|
| 1 | +import billingPage from 'codecrafters-frontend/tests/pages/settings/billing-page'; |
| 2 | +import testScenario from 'codecrafters-frontend/mirage/scenarios/test'; |
| 3 | +import windowMock from 'ember-window-mock'; |
| 4 | +import { module, test } from 'qunit'; |
| 5 | +import { setupApplicationTest } from 'codecrafters-frontend/tests/helpers'; |
| 6 | +import { setupWindowMock } from 'ember-window-mock/test-support'; |
| 7 | +import { signIn, signInAsSubscriber } from 'codecrafters-frontend/tests/support/authentication-helpers'; |
| 8 | + |
| 9 | +module('Acceptance | settings-page | extend-membership-test', function (hooks) { |
| 10 | + setupApplicationTest(hooks); |
| 11 | + setupWindowMock(hooks); |
| 12 | + |
| 13 | + test('can extend membership', async function (assert) { |
| 14 | + testScenario(this.server); |
| 15 | + signInAsSubscriber(this.owner, this.server); |
| 16 | + |
| 17 | + const subscription = this.server.schema.subscriptions.first(); |
| 18 | + subscription.update('cancelAt', new Date(Date.now() + 30 * 24 * 60 * 60 * 1000)); // 30 days from now |
| 19 | + |
| 20 | + await billingPage.visit(); |
| 21 | + |
| 22 | + assert.strictEqual( |
| 23 | + billingPage.renewalSection.explanationText, |
| 24 | + 'Your membership does not renew automatically. If you extend your membership before expiry, unused time will be added to your new membership.', |
| 25 | + 'explanation text is correct', |
| 26 | + ); |
| 27 | + |
| 28 | + await billingPage.renewalSection.extendMembershipButton.click(); |
| 29 | + assert.true(billingPage.chooseMembershipPlanModal.isVisible, 'choose membership plan modal is visible'); |
| 30 | + await billingPage.chooseMembershipPlanModal.clickOnChoosePlanButton(); |
| 31 | + await billingPage.chooseMembershipPlanModal.clickOnProceedToCheckoutButton(); |
| 32 | + |
| 33 | + assert.strictEqual(windowMock.location.href, 'https://test.com/checkout_session'); |
| 34 | + |
| 35 | + const individualCheckoutSession = this.server.schema.individualCheckoutSessions.first(); |
| 36 | + |
| 37 | + assert.strictEqual(individualCheckoutSession.cancelUrl, `${window.location.origin}/settings/billing`); |
| 38 | + |
| 39 | + // TODO: See if we can add a "membership extended" notice for success? |
| 40 | + assert.strictEqual(individualCheckoutSession.successUrl, `${window.location.origin}/settings/billing`); |
| 41 | + }); |
| 42 | + |
| 43 | + test('renewal section is not displayed when membership has expired', async function (assert) { |
| 44 | + testScenario(this.server); |
| 45 | + signIn(this.owner, this.server); // Sign in without subscription (no active membership) |
| 46 | + |
| 47 | + await billingPage.visit(); |
| 48 | + |
| 49 | + assert.false(billingPage.renewalSection.isVisible, 'renewal section is not visible for expired/no membership'); |
| 50 | + }); |
| 51 | + |
| 52 | + test('renewal section is not displayed when membership is a lifetime membership', async function (assert) { |
| 53 | + testScenario(this.server); |
| 54 | + signInAsSubscriber(this.owner, this.server); |
| 55 | + |
| 56 | + const subscription = this.server.schema.subscriptions.first(); |
| 57 | + // Set cancelAt to more than 50 years from now (lifetime membership) |
| 58 | + subscription.update('cancelAt', new Date(Date.now() + 100 * 365 * 24 * 60 * 60 * 1000)); // 100 years from now |
| 59 | + |
| 60 | + await billingPage.visit(); |
| 61 | + |
| 62 | + assert.false(billingPage.renewalSection.isVisible, 'renewal section is not visible for lifetime membership'); |
| 63 | + }); |
| 64 | +}); |
0 commit comments