show-downgrade-option.test.ts 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. import { expect } from 'chai'
  2. import showDowngradeOption from '../../../../../frontend/js/features/subscription/util/show-downgrade-option'
  3. const dateformat = require('dateformat')
  4. describe('showDowngradeOption', function () {
  5. const today = new Date()
  6. const sevenDaysFromToday = new Date().setDate(today.getDate() + 7)
  7. const sevenDaysFromTodayFormatted = dateformat(
  8. sevenDaysFromToday,
  9. 'dS mmmm yyyy'
  10. )
  11. it('returns false when no trial end date', function () {
  12. expect(showDowngradeOption('collab')).to.be.false
  13. })
  14. it('returns false when a plan code without "collaborator" ', function () {
  15. expect(showDowngradeOption('test', false, sevenDaysFromTodayFormatted)).to
  16. .be.false
  17. })
  18. it('returns false when on a plan with trial date in future but has "collaborator" and "ann" in plan code', function () {
  19. expect(
  20. showDowngradeOption(
  21. 'collaborator-annual',
  22. false,
  23. sevenDaysFromTodayFormatted
  24. )
  25. ).to.be.false
  26. })
  27. it('returns false when on a plan with trial date in future and plan code has "collaborator" and no "ann" but is a group plan', function () {
  28. expect(
  29. showDowngradeOption('collaborator', true, sevenDaysFromTodayFormatted)
  30. ).to.be.false
  31. })
  32. it('returns false when on a plan with "collaborator" and without "ann" and trial date in future', function () {
  33. expect(
  34. showDowngradeOption('collaborator', false, sevenDaysFromTodayFormatted)
  35. ).to.be.false
  36. })
  37. it('returns true when on a plan with "collaborator" and without "ann" and no trial date', function () {
  38. expect(showDowngradeOption('collaborator', false)).to.be.true
  39. })
  40. it('returns true when on a plan with "collaborator" and without "ann" and trial date is in the past', function () {
  41. expect(
  42. showDowngradeOption('collaborator', false, '2000-02-16T17:59:07.000Z')
  43. ).to.be.true
  44. })
  45. })