From 0360730a92bbc57619fb279706589842cea762c0 Mon Sep 17 00:00:00 2001 From: Ankita Shrivastava Date: Wed, 14 Dec 2022 15:27:13 -0500 Subject: [PATCH] test(subplat): add test for resubscription and update mode of payment --- .../pages/products/subscriptionManagement.ts | 20 ++++ .../coupons-ui-tests/coupon.spec.ts | 37 ------ .../coupons-ui-tests/resubscription.spec.ts | 108 ++++++++++++++++++ 3 files changed, 128 insertions(+), 37 deletions(-) create mode 100644 packages/functional-tests/tests/subscription-tests/coupons-ui-tests/resubscription.spec.ts diff --git a/packages/functional-tests/pages/products/subscriptionManagement.ts b/packages/functional-tests/pages/products/subscriptionManagement.ts index 1e78a7ac44..c8d0763894 100644 --- a/packages/functional-tests/pages/products/subscriptionManagement.ts +++ b/packages/functional-tests/pages/products/subscriptionManagement.ts @@ -18,6 +18,20 @@ export class SubscriptionManagementPage extends BaseLayout { ]); } + async changeStripeCardDetails() { + await this.page + .locator('[data-testid="reveal-payment-update-button"]') + .click(); + await this.page.locator('[data-testid="name"]').fill('Test User'); + const frame = this.page.frame({ url: /elements-inner-card/ }); + await frame.fill('.InputElement[name=cardnumber]', ''); + await frame.fill('.InputElement[name=cardnumber]', '5555555555554444'); + await frame.fill('.InputElement[name=exp-date]', '444'); + await frame.fill('.InputElement[name=cvc]', '777'); + await frame.fill('.InputElement[name=postal]', '88888'); + await this.page.locator('[data-testid="submit"]').click(); + } + async resubscribe() { return Promise.all([ await this.page @@ -32,6 +46,12 @@ export class SubscriptionManagementPage extends BaseLayout { ]); } + getCardInfo() { + return this.page + .locator('[data-testid="card-logo-and-last-four"]') + .textContent(); + } + getResubscriptionPrice() { return this.page .locator( diff --git a/packages/functional-tests/tests/subscription-tests/coupons-ui-tests/coupon.spec.ts b/packages/functional-tests/tests/subscription-tests/coupons-ui-tests/coupon.spec.ts index 481e27fdcb..79673e9c4e 100644 --- a/packages/functional-tests/tests/subscription-tests/coupons-ui-tests/coupon.spec.ts +++ b/packages/functional-tests/tests/subscription-tests/coupons-ui-tests/coupon.spec.ts @@ -180,41 +180,4 @@ test.describe('coupon test', () => { // Verify the discount is removed expect(await subscribe.discountLineItem()).toBe(false); }); - - test('resubscribe successfully with the same coupon after canceling', async ({ - page, - pages: { relier, subscribe, login, settings, subscriptionManagement }, - }) => { - await relier.goto(); - await relier.clickSubscribe6Month(); - - // 'auto10pforever' is a 10% forever discount coupon for a 6mo plan - await subscribe.addCouponCode('auto10pforever'); - - // Verify the coupon is applied successfully - expect(await subscribe.discountAppliedSuccess()).toBe(true); - - const total = await subscribe.getTotalPrice(); - - //Subscribe successfully - await subscribe.setFullName(); - await subscribe.setCreditCardInfo(); - await subscribe.clickPayNow(); - await subscribe.submit(); - - //Login to FxA account - await login.goto(); - await login.clickSignIn(); - const subscriptionPage = await settings.clickPaidSubscriptions(); - subscriptionManagement.page = subscriptionPage; - - //Cancel subscription - await subscriptionManagement.cancelSubscription(); - await subscriptionManagement.resubscribe(); - - //Verify that the resubscription has the same coupon applied - expect(await subscriptionManagement.getResubscriptionPrice()).toEqual( - total - ); - }); }); diff --git a/packages/functional-tests/tests/subscription-tests/coupons-ui-tests/resubscription.spec.ts b/packages/functional-tests/tests/subscription-tests/coupons-ui-tests/resubscription.spec.ts new file mode 100644 index 0000000000..eec95b3ca5 --- /dev/null +++ b/packages/functional-tests/tests/subscription-tests/coupons-ui-tests/resubscription.spec.ts @@ -0,0 +1,108 @@ +import { test, expect } from '../../../lib/fixtures/standard'; + +test.describe('resubscription test', () => { + test.beforeEach(() => { + test.slow(); + }); + + test('resubscribe successfully with the same coupon after canceling for stripe', async ({ + page, + pages: { relier, subscribe, login, settings, subscriptionManagement }, + }) => { + await relier.goto(); + await relier.clickSubscribe6Month(); + + // 'auto10pforever' is a 10% forever discount coupon for a 6mo plan + await subscribe.addCouponCode('auto10pforever'); + + // Verify the coupon is applied successfully + expect(await subscribe.discountAppliedSuccess()).toBe(true); + + const total = await subscribe.getTotalPrice(); + + //Subscribe successfully with Stripe + await subscribe.setFullName(); + await subscribe.setCreditCardInfo(); + await subscribe.clickPayNow(); + await subscribe.submit(); + + //Login to FxA account + await login.goto(); + await login.clickSignIn(); + const subscriptionPage = await settings.clickPaidSubscriptions(); + subscriptionManagement.page = subscriptionPage; + + //Cancel subscription and then resubscribe + await subscriptionManagement.cancelSubscription(); + await subscriptionManagement.resubscribe(); + + //Verify that the resubscription has the same coupon applied + expect(await subscriptionManagement.getResubscriptionPrice()).toEqual( + total + ); + }); + + test('resubscribe successfully with the same coupon after canceling for paypal', async ({ + page, + pages: { relier, subscribe, login, settings, subscriptionManagement }, + }) => { + await relier.goto(); + await relier.clickSubscribe6Month(); + + // 'auto10pforever' is a 10% forever discount coupon for a 6mo plan + await subscribe.addCouponCode('auto10pforever'); + + // Verify the coupon is applied successfully + expect(await subscribe.discountAppliedSuccess()).toBe(true); + + const total = await subscribe.getTotalPrice(); + + //Subscribe successfully using Paypal + await subscribe.setPayPalInfo(); + await subscribe.submit(); + + //Login to FxA account + await login.goto(); + await login.clickSignIn(); + const subscriptionPage = await settings.clickPaidSubscriptions(); + subscriptionManagement.page = subscriptionPage; + + //Cancel subscription and then resubscribe + await subscriptionManagement.cancelSubscription(); + await subscriptionManagement.resubscribe(); + + //Verify that the resubscription has the same coupon applied + expect(await subscriptionManagement.getResubscriptionPrice()).toEqual( + total + ); + }); + + test('update mode of payment for stripe', async ({ + page, + pages: { relier, subscribe, login, settings, subscriptionManagement }, + }) => { + await relier.goto(); + await relier.clickSubscribe6Month(); + + // 'auto10pforever' is a 10% forever discount coupon for a 6mo plan + await subscribe.addCouponCode('auto10pforever'); + + //Subscribe successfully + await subscribe.setFullName(); + await subscribe.setCreditCardInfo(); + await subscribe.clickPayNow(); + await subscribe.submit(); + + //Login to FxA account + await login.goto(); + await login.clickSignIn(); + const subscriptionPage = await settings.clickPaidSubscriptions(); + subscriptionManagement.page = subscriptionPage; + + //Change stripe card information + await subscriptionManagement.changeStripeCardDetails(); + + //Verify that the card info is updated + expect(await subscriptionManagement.getCardInfo()).toContain('4444'); + }); +});