|
1 | 1 | import App from '../src/app.js'; |
2 | 2 | import {fireEvent, appRender, within, waitFor} from './utils/test-utils'; |
3 | | -import {offer as FixtureOffer, site as FixtureSite} from './utils/test-fixtures'; |
| 3 | +import {offer as FixtureOffer, site as FixtureSite, member as FixtureMember} from './utils/test-fixtures'; |
4 | 4 | import setupGhostApi from '../src/utils/api.js'; |
5 | 5 |
|
6 | 6 | // Simple deep clone function |
@@ -85,7 +85,7 @@ const offerSetup = async ({site, member = null, offer}) => { |
85 | 85 | }; |
86 | 86 | }; |
87 | 87 |
|
88 | | -const setup = async ({site, member = null}) => { |
| 88 | +const setup = async ({site, member = null, checkoutPlanError = null}) => { |
89 | 89 | const ghostApi = setupGhostApi({siteUrl: 'https://example.com'}); |
90 | 90 | ghostApi.init = vi.fn(() => { |
91 | 91 | return Promise.resolve({ |
@@ -113,6 +113,9 @@ const setup = async ({site, member = null}) => { |
113 | 113 | }); |
114 | 114 |
|
115 | 115 | ghostApi.member.checkoutPlan = vi.fn(() => { |
| 116 | + if (checkoutPlanError) { |
| 117 | + return Promise.reject(checkoutPlanError); |
| 118 | + } |
116 | 119 | return Promise.resolve(); |
117 | 120 | }); |
118 | 121 |
|
@@ -579,6 +582,37 @@ describe('Signup', () => { |
579 | 582 | }); |
580 | 583 | }); |
581 | 584 |
|
| 585 | + test('via direct signup link shows an error instead of the magic link page', async () => { |
| 586 | + const siteData = FixtureSite.singleTier.basic; |
| 587 | + const paidTier = siteData.products.find(p => p.type === 'paid'); |
| 588 | + window.location.hash = `#/portal/signup/${paidTier.id}/monthly`; |
| 589 | + |
| 590 | + try { |
| 591 | + const checkoutError = Object.assign( |
| 592 | + new Error('A subscription exists for this Member.'), |
| 593 | + {code: 'CANNOT_CHECKOUT_WITH_EXISTING_SUBSCRIPTION'} |
| 594 | + ); |
| 595 | + |
| 596 | + const {ghostApi, ...utils} = await setup({ |
| 597 | + site: siteData, |
| 598 | + member: FixtureMember.paid, |
| 599 | + checkoutPlanError: checkoutError |
| 600 | + }); |
| 601 | + |
| 602 | + const popupFrame = await utils.findByTitle(/portal-popup/i); |
| 603 | + |
| 604 | + await waitFor(() => { |
| 605 | + expect(ghostApi.member.checkoutPlan).toHaveBeenCalled(); |
| 606 | + }); |
| 607 | + await waitFor(() => { |
| 608 | + expect(within(popupFrame.contentDocument).queryByText(/You already have an active subscription\./i)).toBeInTheDocument(); |
| 609 | + }); |
| 610 | + expect(within(popupFrame.contentDocument).queryByText(/Now check your email!/i)).not.toBeInTheDocument(); |
| 611 | + } finally { |
| 612 | + window.location.hash = ''; |
| 613 | + } |
| 614 | + }); |
| 615 | + |
582 | 616 | test('to an offer via link', async () => { |
583 | 617 | window.location.hash = `#/portal/offers/${FixtureOffer.id}`; |
584 | 618 | const { |
|
0 commit comments