Skip to content

Commit

Permalink
Merge pull request #1234 from guardian/ahe/national-delivery-address-…
Browse files Browse the repository at this point in the history
…test

Add Cypress Tests for National Delivery Address Blocking
  • Loading branch information
andrewHEguardian authored Oct 30, 2023
2 parents 67f1fe4 + 33d8c2e commit ade7a93
Show file tree
Hide file tree
Showing 6 changed files with 153 additions and 42 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,8 @@ export const DeliveryAddressUpdate = (props: WithProductType<ProductType>) => {
contactIdToArrayOfProductDetailAndProductType,
)
.flatMap(flattenEquivalent)
.some(({ productDetail }) => {
return (
GROUPED_PRODUCT_TYPES.subscriptions.mapGroupedToSpecific(
productDetail,
).productType === 'nationaldelivery'
);
.some(({ productType }) => {
return productType.productType === 'nationaldelivery';
});

if (hasNationalDelivery) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,8 @@ export const DeliveryAddressStep = (props: DeliveryAddressStepProps) => {
contactIdToArrayOfProductDetailAndProductType,
)
.flatMap(flattenEquivalent)
.some(({ productDetail }) => {
return (
GROUPED_PRODUCT_TYPES.subscriptions.mapGroupedToSpecific(
productDetail,
).productType === 'nationaldelivery'
);
.some(({ productType }) => {
return productType.productType === 'nationaldelivery';
});

if (hasNationalDelivery) {
Expand Down
66 changes: 66 additions & 0 deletions client/fixtures/productBuilder/baseProducts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,72 @@ export function baseHomeDelivery(): ProductDetail {
};
}

export function baseNationalDelivery(): ProductDetail {
return {
mmaCategory: 'subscriptions',
tier: 'Newspaper - National Delivery',
isPaidTier: true,
selfServiceCancellation: {
isAllowed: false,
shouldDisplayEmail: false,
phoneRegionsToDisplay: ['UK & ROW'],
},
joinDate: '2021-12-15',
optIn: true,
subscription: {
contactId: '0039E00001KA26BQAT',
deliveryAddress: {
addressLine1: 'Kings Place',
addressLine2: '90 York Way',
town: 'Derby',
postcode: 'DE10FD',
country: 'United Kingdom',
},
safeToUpdatePaymentMethod: true,
start: '2021-12-24',
end: '2022-12-15',
nextPaymentPrice: 3250,
nextPaymentDate: '2021-12-24',
lastPaymentDate: null,
chargedThroughDate: null,
renewalDate: '2022-12-15',
anniversaryDate: '2022-12-24',
cancelledAt: false,
subscriberId: 'A-S00293857',
subscriptionId: 'A-S00293857',
trialLength: -37,
autoRenew: true,
currentPlans: [
{
name: 'Everyday',
start: '2021-12-24',
end: '2022-12-15',
shouldBeVisible: true,
chargedThrough: null,
price: 3250,
currency: '£',
currencyISO: 'GBP',
billingPeriod: 'month',
daysOfWeek: [
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
'Sunday',
],
},
],
futurePlans: [],
readerType: 'Direct',
accountId: '8ad0965d7dbcc507017dbe20afd33ac4',
deliveryAddressChangeEffectiveDate: '2022-02-11',
},
isTestUser: false,
};
}

export function baseSupporterPlus(): ProductDetail {
return {
mmaCategory: 'recurringSupport',
Expand Down
7 changes: 7 additions & 0 deletions client/fixtures/productBuilder/testProducts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import {
baseGuardianWeekly,
baseHomeDelivery,
baseMembership,
baseNationalDelivery,
baseSupporterPlus,
} from './baseProducts';
import { cards, ProductBuilder } from './productBuilder';
Expand Down Expand Up @@ -134,6 +135,12 @@ export function homeDelivery() {
.getProductDetailObject();
}

export function nationalDelivery() {
return new ProductBuilder(baseNationalDelivery())
.payByCard()
.getProductDetailObject();
}

export function membershipSupporter() {
return new ProductBuilder(baseMembership())
.payByCard()
Expand Down
70 changes: 40 additions & 30 deletions cypress/e2e/parallel-4/deliveryAddress.cy.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import {
guardianWeeklyPaidByCard,
nationalDelivery,
supporterPlus,
} from '../../../client/fixtures/productBuilder/testProducts';
import { toMembersDataApiResponse } from '../../../client/fixtures/mdapiResponse';
Expand All @@ -17,21 +18,6 @@ describe('Delivery address', () => {
),
}).as('product_detail');

cy.intercept('GET', '/api/cancelled/', {
statusCode: 200,
body: [],
}).as('cancelled');
});

it('Can update delivery address. Navigating from account overview', () => {
cy.intercept('GET', '/api/me/mma', {
statusCode: 200,
body: toMembersDataApiResponse(
guardianWeeklyPaidByCard(),
supporterPlus(),
),
}).as('mma');

cy.intercept('GET', '/mpapi/user/mobile-subscriptions', {
statusCode: 200,
body: { subscriptions: [] },
Expand All @@ -47,6 +33,21 @@ describe('Delivery address', () => {
body: 'success',
}).as('address_update');

cy.intercept('GET', '/api/cancelled/', {
statusCode: 200,
body: [],
}).as('cancelled');
});

it('Can update delivery address. Navigating from account overview', () => {
cy.intercept('GET', '/api/me/mma', {
statusCode: 200,
body: toMembersDataApiResponse(
guardianWeeklyPaidByCard(),
supporterPlus(),
),
}).as('mma');

cy.visit('/');
cy.wait('@mma');
cy.wait('@cancelled');
Expand Down Expand Up @@ -76,29 +77,38 @@ describe('Delivery address', () => {
cy.get('@address_update.all').should('have.length', 1);
});

it('Shows updated address when returning to manage subscription page', () => {
it('Cannot update National delivery address. Navigating from account overview', () => {
cy.intercept('GET', '/api/me/mma', {
statusCode: 200,
body: toMembersDataApiResponse(
guardianWeeklyPaidByCard(),
supporterPlus(),
),
body: toMembersDataApiResponse(nationalDelivery(), supporterPlus()),
}).as('mma');

cy.intercept('GET', '/mpapi/user/mobile-subscriptions', {
statusCode: 200,
body: { subscriptions: [] },
}).as('mobile_subscriptions');
cy.visit('/');
cy.wait('@mma');
cy.wait('@cancelled');
cy.wait('@mobile_subscriptions');
cy.wait('@single_contributions');

cy.intercept('GET', '/api/me/one-off-contributions', {
cy.findByText('Manage subscription').click();

cy.intercept('GET', '/api/me/mma?productType=ContentSubscription', {
statusCode: 200,
body: [],
}).as('single_contributions');
body: toMembersDataApiResponse(nationalDelivery(), supporterPlus()),
});

cy.intercept('PUT', '/api/delivery/address/update/**', {
cy.findByText('Manage delivery address').click();

cy.findByText(/Changed address?/).should('exist');
});

it('Shows updated address when returning to manage subscription page', () => {
cy.intercept('GET', '/api/me/mma', {
statusCode: 200,
body: 'success',
}).as('address_update');
body: toMembersDataApiResponse(
guardianWeeklyPaidByCard(),
supporterPlus(),
),
}).as('mma');

cy.visit('/');
cy.wait('@mma');
Expand Down
36 changes: 36 additions & 0 deletions cypress/e2e/parallel-4/deliveryRecords.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { singleContributionsAPIResponse } from '../../../client/fixtures/singleC
import {
guardianWeeklyPaidByCard,
homeDelivery,
nationalDelivery,
} from '../../../client/fixtures/productBuilder/testProducts';

describe('Delivery records', () => {
Expand Down Expand Up @@ -351,6 +352,41 @@ describe('Delivery records', () => {
cy.get('@address_update.all').should('have.length', 1);
});

it('does not allow you to update National delivery address before reporting a problem', () => {
cy.intercept('GET', '/api/me/mma?productType=HomeDelivery', {
statusCode: 200,
body: toMembersDataApiResponse(nationalDelivery()),
}).as('national_product_detail');

cy.visit('/delivery/nationaldelivery/records');

cy.wait('@national_product_detail');
cy.wait('@delivery_records');

cy.findByRole('button', { name: 'Report a problem' }).click();

cy.findByText(
'Step 1. What type of problem are you experiencing?',
).should('exist');
cy.findByRole('radio', { name: 'Damaged paper' }).click();
cy.findByRole('textbox', { name: 'Please specify' }).type('Pages torn');
cy.findByRole('button', { name: 'Continue to Step 2 & 3' }).click();

cy.findByText(
'Step 2. Select the date you have experienced the problem',
).should('exist');
cy.findByText(
'Step 3. Check your current delivery address and instructions',
).should('exist');
cy.findByText('Kings Place').should('exist');

cy.findByRole('button', { name: 'Update' }).should('not.exist');

cy.findByText(/Changed address?/).should('exist');

cy.findByRole('button', { name: 'Review your report' }).should('exist');
});

it('displays an error message if a delivery problem is not selected', () => {
cy.visit('/delivery/guardianweekly/records');
cy.wait('@product_detail');
Expand Down

0 comments on commit ade7a93

Please sign in to comment.