common.spec.tsx 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import {
  2. createFakeRecurly,
  3. defaultSubscription,
  4. } from '../../fixtures/recurly-mock'
  5. import { PaymentProvider } from '../../../../../../frontend/js/features/subscription/context/payment-context'
  6. import { plans } from '../../fixtures/plans'
  7. import PaymentPreviewPanel from '../../../../../../frontend/js/features/subscription/components/new/payment-preview/payment-preview-panel'
  8. import CheckoutPanel from '../../../../../../frontend/js/features/subscription/components/new/checkout/checkout-panel'
  9. import { fillForm } from '../../helpers/payment'
  10. describe('common recurly validations', function () {
  11. beforeEach(function () {
  12. const plan = plans.find(({ planCode }) => planCode === 'collaborator')
  13. if (!plan) {
  14. throw new Error('No plan was found while running the test!')
  15. }
  16. cy.window().then(win => {
  17. win.metaAttributesCache = new Map()
  18. win.metaAttributesCache.set('ol-countryCode', '')
  19. win.metaAttributesCache.set('ol-recurlyApiKey', '1234')
  20. win.metaAttributesCache.set('ol-recommendedCurrency', 'USD')
  21. win.metaAttributesCache.set('ol-plan', plan)
  22. win.metaAttributesCache.set('ol-planCode', plan.planCode)
  23. win.metaAttributesCache.set('ol-showCouponField', true)
  24. win.recurly = createFakeRecurly(defaultSubscription)
  25. cy.interceptEvents()
  26. })
  27. })
  28. it('initializes recurly', function () {
  29. cy.window().then(win => {
  30. cy.spy(win.recurly, 'configure')
  31. cy.spy(win.recurly.Pricing, 'Subscription')
  32. })
  33. cy.mount(<PaymentProvider publicKey="0000" />)
  34. cy.window().then(win => {
  35. expect(win.recurly.configure).to.be.calledOnce
  36. expect(win.recurly.Pricing.Subscription).to.be.calledOnce
  37. })
  38. })
  39. it('shows three d secure challenge content only once when changing currency', function () {
  40. cy.intercept('POST', 'user/subscription/create', {
  41. statusCode: 404,
  42. body: {
  43. threeDSecureActionTokenId: '123',
  44. },
  45. })
  46. cy.mount(
  47. <PaymentProvider publicKey="0000">
  48. <PaymentPreviewPanel />
  49. <CheckoutPanel />
  50. </PaymentProvider>
  51. )
  52. cy.findByTestId('checkout-form').within(() => fillForm())
  53. cy.findByRole('button', { name: /upgrade now/i }).click()
  54. cy.findByRole('button', { name: /change currency/i }).click()
  55. cy.findByRole('menu').within(() => {
  56. cy.findByRole('menuitem', { name: /gbp/i }).click()
  57. })
  58. cy.findAllByText('3D challenge content').should('have.length', 1)
  59. })
  60. })