SubscriptionEmailHandlerTests.js 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. const SandboxedModule = require('sandboxed-module')
  2. const sinon = require('sinon')
  3. const { expect } = require('chai')
  4. const modulePath =
  5. '../../../../app/src/Features/Subscription/SubscriptionEmailHandler'
  6. describe('SubscriptionEmailHandler', function () {
  7. beforeEach(function () {
  8. this.userId = '123456789abcde'
  9. this.email = 'test@test.com'
  10. this.SubscriptionEmailHandler = SandboxedModule.require(modulePath, {
  11. requires: {
  12. '../Email/EmailHandler': (this.EmailHandler = {
  13. promises: {
  14. sendEmail: sinon.stub().resolves({}),
  15. },
  16. }),
  17. '../User/UserGetter': (this.UserGetter = {
  18. promises: {
  19. getUser: sinon
  20. .stub()
  21. .resolves({ _id: this.userId, email: 'test@test.com' }),
  22. },
  23. }),
  24. './PlansLocator': (this.PlansLocator = {
  25. findLocalPlanInSettings: sinon.stub().returns({
  26. name: 'foo',
  27. features: { collaborators: 42 },
  28. }),
  29. }),
  30. },
  31. })
  32. })
  33. it('sends trail onboarding email', async function () {
  34. await this.SubscriptionEmailHandler.sendTrialOnboardingEmail(
  35. this.userId,
  36. 'foo-plan-code'
  37. )
  38. expect(this.PlansLocator.findLocalPlanInSettings).to.have.been.calledWith(
  39. 'foo-plan-code'
  40. )
  41. expect(this.EmailHandler.promises.sendEmail.lastCall.args).to.deep.equal([
  42. 'trialOnboarding',
  43. {
  44. to: this.email,
  45. sendingUser_id: this.userId,
  46. planName: 'foo',
  47. features: { collaborators: 42 },
  48. },
  49. ])
  50. })
  51. })