From 978b1f3db095e98bca4562e645ad80b6a478bfa4 Mon Sep 17 00:00:00 2001 From: Ankita Shrivastava Date: Tue, 29 Mar 2022 13:20:36 -0400 Subject: [PATCH] (test): add test for subscription retry after failed subscription --- packages/functional-tests/package.json | 2 +- .../functional-tests/pages/products/index.ts | 26 ++++++++++--------- .../tests/subscription.spec.ts | 21 +++++++++++++++ 3 files changed, 36 insertions(+), 13 deletions(-) diff --git a/packages/functional-tests/package.json b/packages/functional-tests/package.json index cd94fbf780..0a92bb4d35 100644 --- a/packages/functional-tests/package.json +++ b/packages/functional-tests/package.json @@ -17,7 +17,7 @@ "fxa-payments-server": "workspace:*", "fxa-settings": "workspace:*", "jsqr": "^1.4.0", - "playwright": "^1.18.0", + "playwright": "^1.20.0", "upng-js": "^2.1.0" } } diff --git a/packages/functional-tests/pages/products/index.ts b/packages/functional-tests/pages/products/index.ts index 43198a45ed..66f4f51303 100644 --- a/packages/functional-tests/pages/products/index.ts +++ b/packages/functional-tests/pages/products/index.ts @@ -9,6 +9,7 @@ export class SubscribePage extends BaseLayout { async setCreditCardInfo() { const frame = this.page.frame({ url: /elements-inner-card/ }); + await frame.fill('.InputElement[name=cardnumber]', ''); await frame.fill('.InputElement[name=cardnumber]', '4242424242424242'); await frame.fill('.InputElement[name=exp-date]', '555'); await frame.fill('.InputElement[name=cvc]', '333'); @@ -17,6 +18,16 @@ export class SubscribePage extends BaseLayout { await this.page.click('button[type=submit]'); } + async setFailedCreditCardInfo() { + const frame = this.page.frame({ url: /elements-inner-card/ }); + await frame.fill('.InputElement[name=cardnumber]', '4000000000000341'); + await frame.fill('.InputElement[name=exp-date]', '666'); + await frame.fill('.InputElement[name=cvc]', '444'); + await frame.fill('.InputElement[name=postal]', '77777'); + await this.page.check('input[type=checkbox]'); + await this.page.click('button[type=submit]'); + } + async setPayPalInfo() { await this.page.check('[data-testid="confirm"]'); const [paypalWindow] = await Promise.all([ @@ -35,18 +46,9 @@ export class SubscribePage extends BaseLayout { await paypalWindow.click('button[id=consentButton]'); } - /*submit() { - return Promise.all([ - this.page.click('button[type=submit]'), - this.page.waitForResponse( - (r) => - r.request().method() === 'GET' && - /\/mozilla-subscriptions\/customer\/billing-and-subscriptions$/.test( - r.request().url() - ) - ), - ]); - }*/ + async clickTryAgain() { + return Promise.all([this.page.click('[data-testid="retry-link"]')]); + } submit() { return Promise.all([ diff --git a/packages/functional-tests/tests/subscription.spec.ts b/packages/functional-tests/tests/subscription.spec.ts index bd94b8c4db..261762dafe 100644 --- a/packages/functional-tests/tests/subscription.spec.ts +++ b/packages/functional-tests/tests/subscription.spec.ts @@ -36,3 +36,24 @@ test.describe('severity-1', () => { expect(await relier.isPro()).toBe(true); }); }); + +test.describe('severity-1', () => { + test('subscribe with credit card after initial failed subscription', async ({ + pages: { relier, login, subscribe }, + }, { project }) => { + test.skip(project.name === 'production', 'prod needs a valid credit card'); + test.skip(project.name === 'local', 'No need to be run on local'); + test.slow(); + await relier.goto(); + await relier.clickSubscribe(); + await subscribe.setFullName(); + await subscribe.setFailedCreditCardInfo(); + await subscribe.clickTryAgain(); + await subscribe.setCreditCardInfo(); + await subscribe.submit(); + await relier.goto(); + await relier.clickEmailFirst(); + await login.submit(); + expect(await relier.isPro()).toBe(true); + }); +});