|
| 1 | +/// <reference types='cypress' /> |
| 2 | + |
| 3 | +describe('Billing', () => { |
| 4 | + function stubBillingCalls() { |
| 5 | + cy.intercept('GET', 'http://talo.api/billing/organisation-plan', { |
| 6 | + statusCode: 200, |
| 7 | + fixture: 'responses/billing/free-plan' |
| 8 | + }) |
| 9 | + |
| 10 | + cy.intercept('GET', 'http://talo.api/billing/plans', { |
| 11 | + statusCode: 200, |
| 12 | + fixture: 'responses/billing/plans' |
| 13 | + }) |
| 14 | + |
| 15 | + cy.intercept('GET', 'http://talo.api/billing/usage', { |
| 16 | + statusCode: 200, |
| 17 | + fixture: 'responses/billing/usage' |
| 18 | + }) |
| 19 | + } |
| 20 | + |
| 21 | + it('should show the correct usages', () => { |
| 22 | + stubBillingCalls() |
| 23 | + |
| 24 | + cy.login('owner', '/billing') |
| 25 | + cy.findByTestId('User seats-usage').should('contain.text', '0/2') |
| 26 | + cy.findByTestId('Data exports-usage').should('contain.text', '1/3') |
| 27 | + }) |
| 28 | + |
| 29 | + it('should open the billing portal', () => { |
| 30 | + stubBillingCalls() |
| 31 | + |
| 32 | + cy.intercept('POST', 'http://talo.api/billing/portal-session', { |
| 33 | + statusCode: 200, |
| 34 | + body: { |
| 35 | + redirect: 'https://trytalo.com' |
| 36 | + } |
| 37 | + }).as('portalSession') |
| 38 | + |
| 39 | + cy.login('owner', '/billing') |
| 40 | + cy.findByText('Billing Portal').click() |
| 41 | + |
| 42 | + cy.wait('@portalSession').then(() => { |
| 43 | + cy.on('url:changed', (newUrl) => { |
| 44 | + expect(newUrl).to.eq('https://trytalo.com') |
| 45 | + }) |
| 46 | + }) |
| 47 | + }) |
| 48 | + |
| 49 | + it('should open the checkout portal', () => { |
| 50 | + stubBillingCalls() |
| 51 | + |
| 52 | + cy.intercept('POST', 'http://talo.api/billing/checkout-session', { |
| 53 | + statusCode: 200, |
| 54 | + body: { |
| 55 | + redirect: 'https://trytalo.com' |
| 56 | + } |
| 57 | + }).as('checkoutSession') |
| 58 | + |
| 59 | + cy.login('owner', '/billing') |
| 60 | + cy.findAllByText('Upgrade').spread((button) => button.click()) |
| 61 | + |
| 62 | + cy.wait('@checkoutSession').then(() => { |
| 63 | + cy.on('url:changed', (newUrl) => { |
| 64 | + expect(newUrl).to.eq('https://trytalo.com') |
| 65 | + }) |
| 66 | + }) |
| 67 | + }) |
| 68 | + |
| 69 | + it('should show the confirm plan change modal', () => { |
| 70 | + stubBillingCalls() |
| 71 | + |
| 72 | + cy.intercept('POST', 'http://talo.api/billing/checkout-session', { |
| 73 | + statusCode: 200, |
| 74 | + fixture: 'responses/billing/invoice' |
| 75 | + }) |
| 76 | + |
| 77 | + cy.intercept('POST', 'http://talo.api/billing/confirm-plan', { |
| 78 | + statusCode: 204 |
| 79 | + }) |
| 80 | + |
| 81 | + cy.login('owner', '/billing') |
| 82 | + cy.findAllByText('Upgrade').spread((button) => button.click()) |
| 83 | + |
| 84 | + cy.findByText('This is a preview of the invoice that will be billed on 12 Aug 2022:').should('exist') |
| 85 | + cy.findByText('12 Jun 2022 - 12 Jul 2022').should('exist') |
| 86 | + cy.findByText('Team plan usage').should('exist') |
| 87 | + cy.findByText('Team plan proration').should('exist') |
| 88 | + cy.findByText('13 Jul 2022 - 12 Aug 2022').should('exist') |
| 89 | + cy.findByText('Business plan usage').should('exist') |
| 90 | + |
| 91 | + cy.findByTestId('confirm-plan-change').click() |
| 92 | + cy.findByText('Confirm plan change').should('not.exist') |
| 93 | + cy.findByText('Current plan').should('exist') |
| 94 | + }) |
| 95 | +}) |
0 commit comments