2021-09-28 05:30:01 -04:00
|
|
|
const SandboxedModule = require('sandboxed-module')
|
|
|
|
const sinon = require('sinon')
|
|
|
|
const { expect } = require('chai')
|
|
|
|
const modulePath =
|
|
|
|
'../../../../app/src/Features/Subscription/SubscriptionEmailHandler'
|
|
|
|
|
|
|
|
describe('SubscriptionEmailHandler', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
this.userId = '123456789abcde'
|
|
|
|
this.email = 'test@test.com'
|
|
|
|
|
|
|
|
this.SubscriptionEmailHandler = SandboxedModule.require(modulePath, {
|
|
|
|
requires: {
|
|
|
|
'../Email/EmailHandler': (this.EmailHandler = {
|
|
|
|
promises: {
|
|
|
|
sendEmail: sinon.stub().resolves({}),
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
'../User/UserGetter': (this.UserGetter = {
|
|
|
|
promises: {
|
|
|
|
getUser: sinon
|
|
|
|
.stub()
|
|
|
|
.resolves({ _id: this.userId, email: 'test@test.com' }),
|
|
|
|
},
|
|
|
|
}),
|
2022-04-25 07:05:44 -04:00
|
|
|
'./PlansLocator': (this.PlansLocator = {
|
|
|
|
findLocalPlanInSettings: sinon.stub().returns({
|
|
|
|
name: 'foo',
|
|
|
|
features: { collaborators: 42 },
|
|
|
|
}),
|
|
|
|
}),
|
2021-09-28 05:30:01 -04:00
|
|
|
},
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('sends trail onboarding email', async function () {
|
2022-04-25 07:05:44 -04:00
|
|
|
await this.SubscriptionEmailHandler.sendTrialOnboardingEmail(
|
|
|
|
this.userId,
|
|
|
|
'foo-plan-code'
|
|
|
|
)
|
|
|
|
|
|
|
|
expect(this.PlansLocator.findLocalPlanInSettings).to.have.been.calledWith(
|
|
|
|
'foo-plan-code'
|
|
|
|
)
|
2021-09-28 05:30:01 -04:00
|
|
|
expect(this.EmailHandler.promises.sendEmail.lastCall.args).to.deep.equal([
|
|
|
|
'trialOnboarding',
|
|
|
|
{
|
|
|
|
to: this.email,
|
|
|
|
sendingUser_id: this.userId,
|
2022-04-25 07:05:44 -04:00
|
|
|
planName: 'foo',
|
|
|
|
features: { collaborators: 42 },
|
2021-09-28 05:30:01 -04:00
|
|
|
},
|
|
|
|
])
|
|
|
|
})
|
|
|
|
})
|