From 2570a4cff3aa666adbd6ca8216bc2bd7b138352e Mon Sep 17 00:00:00 2001 From: Stephen Daly Date: Mon, 27 Nov 2023 10:17:22 +0000 Subject: [PATCH] PP-11701 Remove wallets feature flag Remove feature flag for showing the setting to enable digital wallets for sandbox accounts, and always show the setting. Fix some Cypress test that started breaking because the wallet setting is now showing for sandbox accounts, and the tests were accessing the settings by element index. Use the `data-cy` attribute to select the relevant section in the settings before using element indices. --- app/utils/display-converter.js | 10 ++- app/utils/display-converter.test.js | 25 ++----- app/views/settings/index.njk | 3 + .../default-billing-address-country.cy.js | 12 ++-- .../settings/email-notifications.cy.js | 68 +++++++++++-------- ...k-moto-card-number-and-security-code.cy.js | 40 ++++++----- test/cypress/test.env | 1 - 7 files changed, 86 insertions(+), 73 deletions(-) diff --git a/app/utils/display-converter.js b/app/utils/display-converter.js index 246c92dbb3..a279ac19dd 100644 --- a/app/utils/display-converter.js +++ b/app/utils/display-converter.js @@ -42,6 +42,12 @@ const hideServiceNavTemplates = [ 'two-factor-auth/resend-sms-code' ] +const digitalWalletsSupportedProviders = [ + 'sandbox', + 'stripe', + 'worldpay' +] + /** * converts users permission array of form * @@ -121,9 +127,7 @@ module.exports = function (req, data, template) { convertedData.currentGatewayAccount = getAccount(account) convertedData.isTestGateway = _.get(convertedData, 'currentGatewayAccount.type') === 'test' convertedData.isSandbox = paymentProvider === 'sandbox' - convertedData.isDigitalWalletSupported = paymentProvider === 'worldpay' || - (paymentProvider === 'sandbox' && process.env.ALLOW_ENABLING_DIGITAL_WALLETS_FOR_SANDBOX_ACCOUNT === 'true') || - paymentProvider === 'stripe' + convertedData.isDigitalWalletSupported = digitalWalletsSupportedProviders.includes(paymentProvider) convertedData.currentService = service convertedData.isLive = req.isLive convertedData.humanReadableEnvironment = convertedData.isLive ? 'Live' : 'Test' diff --git a/app/utils/display-converter.test.js b/app/utils/display-converter.test.js index 2da9f02d5b..2320c4b17e 100644 --- a/app/utils/display-converter.test.js +++ b/app/utils/display-converter.test.js @@ -4,11 +4,6 @@ var displayConverter = require('./display-converter') const expect = chai.expect describe('Display converter', function () { - afterEach(() => { - process.env.ALLOW_ENABLING_DIGITAL_WALLETS_FOR_STRIPE_ACCOUNT = undefined - process.env.ALLOW_ENABLING_DIGITAL_WALLETS_FOR_SANDBOX_ACCOUNT = undefined - }) - it('should add full_type to account if type is test', function () { let data = displayConverter({ account: { @@ -89,35 +84,23 @@ describe('Display converter', function () { expect(data.isDigitalWalletSupported).to.equal(true) }) - it('should return isDigitalWalletSupported=false for sandbox account when ALLOW_ENABLING_DIGITAL_WALLETS_FOR_SANDBOX_ACCOUNT is not set', () => { + it('should return isDigitalWalletSupported=true for sandbox accounts', () => { const data = displayConverter({ account: { type: 'test', payment_provider: 'sandbox' } }, {}, {}) - expect(data.isDigitalWalletSupported).to.equal(false) + expect(data.isDigitalWalletSupported).to.equal(true) }) - it('should return isDigitalWalletSupported=false for sandbox account when ALLOW_ENABLING_DIGITAL_WALLETS_FOR_SANDBOX_ACCOUNT is false', () => { - process.env.ALLOW_ENABLING_DIGITAL_WALLETS_FOR_SANDBOX_ACCOUNT = 'false' + it('should return isDigitalWalletSupported=false for unsupported provider', () => { const data = displayConverter({ account: { type: 'test', - payment_provider: 'sandbox' + payment_provider: 'epdq' } }, {}, {}) expect(data.isDigitalWalletSupported).to.equal(false) }) - - it('should return isDigitalWalletSupported=true for sandbox account when ALLOW_ENABLING_DIGITAL_WALLETS_FOR_SANDBOX_ACCOUNT is true', () => { - process.env.ALLOW_ENABLING_DIGITAL_WALLETS_FOR_SANDBOX_ACCOUNT = 'true' - const data = displayConverter({ - account: { - type: 'test', - payment_provider: 'sandbox' - } - }, {}, {}) - expect(data.isDigitalWalletSupported).to.equal(true) - }) }) diff --git a/app/views/settings/index.njk b/app/views/settings/index.njk index c2508474f6..27a4fcc51a 100644 --- a/app/views/settings/index.njk +++ b/app/views/settings/index.njk @@ -96,6 +96,7 @@ {{ govukSummaryList({ classes: 'pay-!-border-top pay-!-padding-top-2-small', + attributes: {'data-cy': 'billing-address-settings'}, rows: [ { key: { @@ -149,6 +150,7 @@ {{ govukSummaryList({ classes: 'pay-!-border-top pay-!-padding-top-2-small', + attributes: {'data-cy': 'email-notification-settings'}, rows: [ { key: { @@ -225,6 +227,7 @@ {{ govukSummaryList({ classes: 'pay-!-border-top pay-!-padding-top-2-small', + attributes: {'data-cy': 'moto-security-settings'}, rows: [ { key: { diff --git a/test/cypress/integration/settings/default-billing-address-country.cy.js b/test/cypress/integration/settings/default-billing-address-country.cy.js index 192909ae43..7c8ecdfa46 100644 --- a/test/cypress/integration/settings/default-billing-address-country.cy.js +++ b/test/cypress/integration/settings/default-billing-address-country.cy.js @@ -37,10 +37,11 @@ describe('Default billing address country', () => { cy.visit(`/account/${gatewayAccountExternalId}/settings`) - cy.get('.govuk-summary-list__key').eq(1).should('contain', 'Default billing address country') - cy.get('.govuk-summary-list__value').eq(1).should('contain', 'None') - - cy.get('.govuk-summary-list__actions').eq(1).contains('Change').click() + cy.get('[data-cy=billing-address-settings]').within(() => { + cy.get('.govuk-summary-list__key').eq(1).should('contain', 'Default billing address country') + cy.get('.govuk-summary-list__value').eq(1).should('contain', 'None') + cy.get('.govuk-summary-list__actions').eq(1).contains('Change').click() + }) cy.get('input[type="radio"]').should('have.length', 2) cy.get('input[value="on"]').should('not.be.checked') @@ -84,7 +85,8 @@ describe('Default billing address country', () => { ]) cy.visit(`/account/${gatewayAccountExternalId}/settings`) - cy.get('.govuk-summary-list__actions').eq(1).contains('View').click() + + cy.get('[data-cy=billing-address-settings]').contains('View').click() cy.get('.pay-info-warning-box').contains('You don’t have permission') cy.get('input[value="on"]').should('be.disabled') cy.get('input[value="off"]').should('be.disabled') diff --git a/test/cypress/integration/settings/email-notifications.cy.js b/test/cypress/integration/settings/email-notifications.cy.js index bb8497e787..850c764651 100644 --- a/test/cypress/integration/settings/email-notifications.cy.js +++ b/test/cypress/integration/settings/email-notifications.cy.js @@ -29,15 +29,17 @@ describe('Settings', () => { describe('Settings default page', () => { it(`should have the page title 'Settings - ${serviceName} - GOV.UK Pay'`, () => { - cy.get('.govuk-summary-list__key').eq(2).should('contain', 'Enter an email address') - cy.get('.govuk-summary-list__value').eq(2).should('contain', 'On (mandatory)') - cy.get('.govuk-summary-list__actions a').eq(2).contains('Change enter an email address settings') - cy.get('.govuk-summary-list__key').eq(3).should('contain', 'Payment confirmation emails') - cy.get('.govuk-summary-list__value').eq(3).should('contain', 'On') - cy.get('.govuk-summary-list__actions a').eq(3).contains('Change payment confirmation emails settings') - cy.get('.govuk-summary-list__key').eq(4).should('contain', 'Refund emails') - cy.get('.govuk-summary-list__value').eq(4).should('contain', 'On') - cy.get('.govuk-summary-list__actions a').eq(4).contains('Change refund emails settings') + cy.get('[data-cy=email-notification-settings]').within(() => { + cy.get('.govuk-summary-list__key').eq(0).should('contain', 'Enter an email address') + cy.get('.govuk-summary-list__value').eq(0).should('contain', 'On (mandatory)') + cy.get('.govuk-summary-list__actions a').eq(0).contains('Change enter an email address settings') + cy.get('.govuk-summary-list__key').eq(1).should('contain', 'Payment confirmation emails') + cy.get('.govuk-summary-list__value').eq(1).should('contain', 'On') + cy.get('.govuk-summary-list__actions a').eq(1).contains('Change payment confirmation emails settings') + cy.get('.govuk-summary-list__key').eq(2).should('contain', 'Refund emails') + cy.get('.govuk-summary-list__value').eq(2).should('contain', 'On') + cy.get('.govuk-summary-list__actions a').eq(2).contains('Change refund emails settings') + }) }) }) @@ -57,9 +59,11 @@ describe('Settings', () => { describe('Email collection mode page', () => { it(`should have the page title 'Email notifications - ${serviceName} Sandbox test - GOV.UK Pay'`, () => { // Access the collection mode page - cy.get('.govuk-summary-list__key').eq(2).should('contain', 'Enter an email address') - cy.get('.govuk-summary-list__value').eq(2).should('contain', 'On (mandatory)') - cy.get('.email-notifications-toggle-collection').contains('Change enter an email address settings').click() + cy.get('[data-cy=email-notification-settings]').within(() => { + cy.get('.govuk-summary-list__key').eq(0).should('contain', 'Enter an email address') + cy.get('.govuk-summary-list__value').eq(0).should('contain', 'On (mandatory)') + cy.get('.email-notifications-toggle-collection').contains('Change enter an email address settings').click() + }) cy.title().should('eq', `Email notifications - ${serviceName} Sandbox test - GOV.UK Pay`) cy.url().should('include', '/email-settings-collection') @@ -81,9 +85,11 @@ describe('Settings', () => { describe('Confirmation email toggle page', () => { it(`should have the page title 'Email notifications - ${serviceName} Sandbox test - GOV.UK Pay'`, () => { // Access the confirmation toggle page - cy.get('.govuk-summary-list__key').eq(3).should('contain', 'Payment confirmation emails') - cy.get('.govuk-summary-list__value').eq(3).should('contain', 'On') - cy.get('.email-notifications-toggle-confirmation').contains('Change payment confirmation emails settings').click() + cy.get('[data-cy=email-notification-settings]').within(() => { + cy.get('.govuk-summary-list__key').eq(1).should('contain', 'Payment confirmation emails') + cy.get('.govuk-summary-list__value').eq(1).should('contain', 'On') + cy.get('.email-notifications-toggle-confirmation').contains('Change payment confirmation emails settings').click() + }) cy.title().should('eq', `Email notifications - ${serviceName} Sandbox test - GOV.UK Pay`) cy.get('.govuk-fieldset__heading').first().should('contain', 'Do you want to send payment confirmation emails?') @@ -103,9 +109,11 @@ describe('Settings', () => { describe('Refund email toggle page', () => { it(`should have the page title 'Email notifications - ${serviceName} Sandbox test - GOV.UK Pay'`, () => { // Access the refund toggle page - cy.get('.govuk-summary-list__key').eq(4).should('contain', 'Refund emails') - cy.get('.govuk-summary-list__value').eq(4).should('contain', 'On') - cy.get('.email-notifications-toggle-refund').contains('Change refund emails settings').click() + cy.get('[data-cy=email-notification-settings]').within(() => { + cy.get('.govuk-summary-list__key').eq(2).should('contain', 'Refund emails') + cy.get('.govuk-summary-list__value').eq(2).should('contain', 'On') + cy.get('.email-notifications-toggle-refund').contains('Change refund emails settings').click() + }) cy.title().should('eq', `Email notifications - ${serviceName} Sandbox test - GOV.UK Pay`) cy.get('.govuk-fieldset__heading').first().should('contain', 'Do you want to send refund emails?') @@ -160,9 +168,11 @@ describe('Settings', () => { describe('Email collection mode page', () => { it(`should have the page title 'Email notifications - ${serviceName} Sandbox test - GOV.UK Pay'`, () => { // Access the collection mode page - cy.get('.govuk-summary-list__key').eq(2).should('contain', 'Enter an email address') - cy.get('.govuk-summary-list__value').eq(2).should('contain', 'On (mandatory)') - cy.get('.email-notifications-toggle-collection').contains('View enter an email address settings').click() + cy.get('[data-cy=email-notification-settings]').within(() => { + cy.get('.govuk-summary-list__key').eq(0).should('contain', 'Enter an email address') + cy.get('.govuk-summary-list__value').eq(0).should('contain', 'On (mandatory)') + cy.get('.email-notifications-toggle-collection').contains('View enter an email address settings').click() + }) cy.title().should('eq', `Email notifications - ${serviceName} Sandbox test - GOV.UK Pay`) cy.url().should('include', '/email-settings-collection') @@ -179,9 +189,11 @@ describe('Settings', () => { describe('Confirmation email toggle page', () => { it(`should have the page title 'Email notifications - ${serviceName} Sandbox test - GOV.UK Pay'`, () => { // Access the confirmation toggle page - cy.get('.govuk-summary-list__key').eq(3).should('contain', 'Payment confirmation emails') - cy.get('.govuk-summary-list__value').eq(3).should('contain', 'On') - cy.get('.email-notifications-toggle-confirmation').contains('View payment confirmation emails settings').click() + cy.get('[data-cy=email-notification-settings]').within(() => { + cy.get('.govuk-summary-list__key').eq(1).should('contain', 'Payment confirmation emails') + cy.get('.govuk-summary-list__value').eq(1).should('contain', 'On') + cy.get('.email-notifications-toggle-confirmation').contains('View payment confirmation emails settings').click() + }) cy.title().should('eq', `Email notifications - ${serviceName} Sandbox test - GOV.UK Pay`) cy.get('.govuk-fieldset__heading').first().should('contain', 'Do you want to send payment confirmation emails?') @@ -197,9 +209,11 @@ describe('Settings', () => { describe('Refund email toggle page', () => { it(`should have the page title 'Email notifications - ${serviceName} Sandbox test - GOV.UK Pay'`, () => { // Access the refund toggle page - cy.get('.govuk-summary-list__key').eq(4).should('contain', 'Refund emails') - cy.get('.govuk-summary-list__value').eq(4).should('contain', 'On') - cy.get('.email-notifications-toggle-refund').contains('View refund emails settings').click() + cy.get('[data-cy=email-notification-settings]').within(() => { + cy.get('.govuk-summary-list__key').eq(2).should('contain', 'Refund emails') + cy.get('.govuk-summary-list__value').eq(2).should('contain', 'On') + cy.get('.email-notifications-toggle-refund').contains('View refund emails settings').click() + }) cy.title().should('eq', `Email notifications - ${serviceName} Sandbox test - GOV.UK Pay`) cy.get('.govuk-fieldset__heading').first().should('contain', 'Do you want to send refund emails?') diff --git a/test/cypress/integration/settings/mask-moto-card-number-and-security-code.cy.js b/test/cypress/integration/settings/mask-moto-card-number-and-security-code.cy.js index a7af7f752c..97bf59d29a 100644 --- a/test/cypress/integration/settings/mask-moto-card-number-and-security-code.cy.js +++ b/test/cypress/integration/settings/mask-moto-card-number-and-security-code.cy.js @@ -73,10 +73,12 @@ describe('MOTO mask security section', () => { setupMotoStubs({ readonly: true, allowMoto: true, motoMaskCardNumber: false }) cy.visit(`/account/${gatewayAccountExternalId}/settings`) - cy.get('.govuk-summary-list__key').eq(5).should('contain', 'Hide card numbers') - cy.get('.govuk-summary-list__value').eq(5).should('contain', 'Off') - cy.get('.govuk-summary-list__actions a').eq(5).contains('View') - cy.get('.govuk-summary-list__actions a').eq(5).click() + cy.get('[data-cy=moto-security-settings]').within(() => { + cy.get('.govuk-summary-list__key').eq(0).should('contain', 'Hide card numbers') + cy.get('.govuk-summary-list__value').eq(0).should('contain', 'Off') + cy.get('.govuk-summary-list__actions a').eq(0).contains('View') + cy.get('.govuk-summary-list__actions a').eq(0).click() + }) cy.title().should('eq', `MOTO - hide card numbers for ${serviceName} - GOV.UK Pay`) cy.get('.pay-info-warning-box').should('exist') cy.get('input[value="on"]').should('be.disabled') @@ -91,10 +93,12 @@ describe('MOTO mask security section', () => { setupMotoStubs({ readonly: false, allowMoto: true, motoMaskCardNumber: false }) cy.visit(`/account/${gatewayAccountExternalId}/settings`) - cy.get('.govuk-summary-list__key').eq(5).should('contain', 'Hide card numbers') - cy.get('.govuk-summary-list__value').eq(5).should('contain', 'Off') - cy.get('.govuk-summary-list__actions a').eq(5).contains('Change') - cy.get('.govuk-summary-list__actions a').eq(5).click() + cy.get('[data-cy=moto-security-settings]').within(() => { + cy.get('.govuk-summary-list__key').eq(0).should('contain', 'Hide card numbers') + cy.get('.govuk-summary-list__value').eq(0).should('contain', 'Off') + cy.get('.govuk-summary-list__actions a').eq(0).contains('Change') + cy.get('.govuk-summary-list__actions a').eq(0).click() + }) cy.title().should('eq', `MOTO - hide card numbers for ${serviceName} - GOV.UK Pay`) cy.get('input[value="on"]').should('not.be.disabled') cy.get('input[value="off"]').should('not.be.disabled') @@ -115,10 +119,12 @@ describe('MOTO mask security section', () => { setupMotoStubs({ readonly: true, allowMoto: true, motoMaskSecurityCode: false }) cy.visit(`/account/${gatewayAccountExternalId}/settings`) - cy.get('.govuk-summary-list__key').eq(6).should('contain', 'Hide card security codes') - cy.get('.govuk-summary-list__value').eq(6).should('contain', 'Off') - cy.get('.govuk-summary-list__actions a').eq(6).contains('View') - cy.get('.govuk-summary-list__actions a').eq(6).click() + cy.get('[data-cy=moto-security-settings]').within(() => { + cy.get('.govuk-summary-list__key').eq(1).should('contain', 'Hide card security codes') + cy.get('.govuk-summary-list__value').eq(1).should('contain', 'Off') + cy.get('.govuk-summary-list__actions a').eq(1).contains('View') + cy.get('.govuk-summary-list__actions a').eq(1).click() + }) cy.title().should('eq', `MOTO - hide security codes for ${serviceName} - GOV.UK Pay`) cy.get('.pay-info-warning-box').should('exist') cy.get('input[value="on"]').should('be.disabled') @@ -133,10 +139,12 @@ describe('MOTO mask security section', () => { setupMotoStubs({ readonly: false, allowMoto: true, motoMaskSecurityCode: false }) cy.visit(`/account/${gatewayAccountExternalId}/settings`) - cy.get('.govuk-summary-list__key').eq(6).should('contain', 'Hide card security codes') - cy.get('.govuk-summary-list__value').eq(6).should('contain', 'Off') - cy.get('.govuk-summary-list__actions a').eq(6).contains('Change') - cy.get('.govuk-summary-list__actions a').eq(6).click() + cy.get('[data-cy=moto-security-settings]').within(() => { + cy.get('.govuk-summary-list__key').eq(1).should('contain', 'Hide card security codes') + cy.get('.govuk-summary-list__value').eq(1).should('contain', 'Off') + cy.get('.govuk-summary-list__actions a').eq(1).contains('Change') + cy.get('.govuk-summary-list__actions a').eq(1).click() + }) cy.title().should('eq', `MOTO - hide security codes for ${serviceName} - GOV.UK Pay`) cy.get('input[value="on"]').should('not.be.disabled') cy.get('input[value="off"]').should('not.be.disabled') diff --git a/test/cypress/test.env b/test/cypress/test.env index 3884f22750..904d521f06 100644 --- a/test/cypress/test.env +++ b/test/cypress/test.env @@ -22,4 +22,3 @@ GOCARDLESS_TEST_OAUTH_BASE_URL=http://127.0.0.1:8000 GOCARDLESS_TEST_CLIENT_ID=testClientId PAYOUTS_RELEASE_DATE=1590148800 ENABLE_STRIPE_ONBOARDING_TASK_LIST=true -ALLOW_ENABLING_DIGITAL_WALLETS_FOR_STRIPE_ACCOUNT=true