SubscriptionEmailHandlerTests.js 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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. '@overleaf/settings': (this.Settings = {
  31. enableOnboardingEmails: true,
  32. }),
  33. },
  34. })
  35. })
  36. describe('when onboarding emails are disabled', function () {
  37. beforeEach(function () {
  38. this.Settings.enableOnboardingEmails = false
  39. })
  40. it('does not send a trial onboarding email', async function () {
  41. await this.SubscriptionEmailHandler.sendTrialOnboardingEmail(
  42. this.userId,
  43. 'foo-plan-code'
  44. )
  45. expect(this.EmailHandler.promises.sendEmail).to.not.have.been.called
  46. })
  47. })
  48. describe('when onboarding emails are enabled', function () {
  49. it('sends trial onboarding email', async function () {
  50. await this.SubscriptionEmailHandler.sendTrialOnboardingEmail(
  51. this.userId,
  52. 'foo-plan-code'
  53. )
  54. expect(this.PlansLocator.findLocalPlanInSettings).to.have.been.calledWith(
  55. 'foo-plan-code'
  56. )
  57. expect(this.EmailHandler.promises.sendEmail.lastCall.args).to.deep.equal([
  58. 'trialOnboarding',
  59. {
  60. to: this.email,
  61. sendingUser_id: this.userId,
  62. planName: 'foo',
  63. features: { collaborators: 42 },
  64. },
  65. ])
  66. })
  67. })
  68. })