@@ -20,6 +20,7 @@ const { AccountEventsManager } = require('../lib/account-events');
2020const { gleanMetrics } = require ( '../lib/metrics/glean' ) ;
2121const { PriceManager } = require ( '@fxa/payments/customer' ) ;
2222const { ProductConfigurationManager } = require ( '@fxa/shared/cms' ) ;
23+ const { FxaMailer } = require ( '../lib/senders/fxa-mailer' ) ;
2324
2425const proxyquire = require ( 'proxyquire' ) ;
2526const amplitudeModule = proxyquire ( '../lib/metrics/amplitude' , {
@@ -355,6 +356,7 @@ module.exports = {
355356 unMockAccountEventsManager,
356357 mockPriceManager,
357358 mockProductConfigurationManager,
359+ mockFxaMailer,
358360} ;
359361
360362function mockCustoms ( errors ) {
@@ -1125,3 +1127,38 @@ function mockProductConfigurationManager() {
11251127 Container . set ( ProductConfigurationManager , productConfigurationManager ) ;
11261128 return productConfigurationManager ;
11271129}
1130+
1131+ /**
1132+ * Used to mock the FxaMailer, injecting the mock into the Container. Be sure
1133+ * to call this before the code under test requests an FxaMailer instance from
1134+ * the Container.
1135+ *
1136+ * `canSend` is defaulted to a stub that resolves to `false`, so email
1137+ * sending is disabled by default in tests. Call mock setup with an override to enable
1138+ * sending for specific tests.
1139+ * ```
1140+ * const mockFxaMailer = mocks.mockFxaMailer({ canSend: sinon.stub().resolves(true) });
1141+ * // or, if you don't need to spy on the method:
1142+ * const mockFxaMailer = mocks.mockFxaMailer({ canSend: true });
1143+ * ```
1144+ * @param {* } overrides
1145+ * @returns {object } The mock FxaMailer instance for spy and assertion use.
1146+ * @usage
1147+ *
1148+ * ``` ts
1149+ * const mockFxaMailer = mocks.mockFxaMailer();
1150+ * // arrange, act, assert
1151+ * sinon.assert.calledOnce(mockFxaMailer.sendRecoveryEmail);
1152+ * ```
1153+ */
1154+ function mockFxaMailer ( overrides ) {
1155+ const mockFxaMailer = {
1156+ // add new email methods here!
1157+ canSend : sinon . stub ( ) . resolves ( false ) ,
1158+ sendRecoveryEmail : sinon . stub ( ) . resolves ( ) ,
1159+ sendPasswordForgotOtpEmail : sinon . stub ( ) . resolves ( ) ,
1160+ ...overrides ,
1161+ } ;
1162+ Container . set ( FxaMailer , mockFxaMailer ) ;
1163+ return mockFxaMailer ;
1164+ }
0 commit comments