Skip to content

Commit

Permalink
PP-7583: update payment link cypress tests for URL structure
Browse files Browse the repository at this point in the history
  • Loading branch information
sfount committed Jan 18, 2021
1 parent b9e5b25 commit 17543a4
Show file tree
Hide file tree
Showing 8 changed files with 112 additions and 99 deletions.
12 changes: 6 additions & 6 deletions app/utils/payment-links.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,22 +32,22 @@ describe('payment links helper methods', () => {
})

it('correctly flags context as creating payment link if not in manage list', () => {
const mockRequest = { route: { path: paths.paymentLinks.review } }
const mockRequest = { route: { path: paths.account.paymentLinks.review } }
const result = getPaymentLinksContext(mockRequest)
expect(result.isCreatingPaymentLink).to.be.true // eslint-disable-line
expect(result.listMetadataPageUrl).to.equal(paths.paymentLinks.review)
expect(result.addMetadataPageUrl).to.equal(paths.paymentLinks.addMetadata)
expect(result.listMetadataPageUrl).to.include(paths.account.paymentLinks.review)
expect(result.addMetadataPageUrl).to.include(paths.account.paymentLinks.addMetadata)
})

it('correctly flags context as managing payment link if in manage link and interpolates relevant product id', () => {
const mockRequest = {
route: { path: paths.paymentLinks.manage.edit },
route: { path: paths.account.paymentLinks.manage.edit },
params: { productExternalId: 'an-external-id' }
}
const result = getPaymentLinksContext(mockRequest)
expect(result.isCreatingPaymentLink).to.be.false // eslint-disable-line
expect(result.listMetadataPageUrl).to.equal('/create-payment-link/manage/edit/an-external-id')
expect(result.addMetadataPageUrl).to.equal('/create-payment-link/manage/an-external-id/add-reporting-column')
expect(result.listMetadataPageUrl).to.include('/create-payment-link/manage/edit/an-external-id')
expect(result.addMetadataPageUrl).to.include('/create-payment-link/manage/an-external-id/add-reporting-column')
})
})

Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ const gatewayAccountStubs = require('../../stubs/gateway-account-stubs')
const userStubs = require('../../stubs/user-stubs')
const { getProductsStub, getProductByExternalIdStub, deleteProductStub } = require('../../stubs/products-stubs')
const userExternalId = 'a-user-id'
const gatewayAccountExternalId = 'a-valid-account-id'
const gatewayAccountId = 42
const productExternalId = 'a-product-id'

Expand All @@ -14,15 +15,15 @@ describe('Should delete payment link', () => {
cy.setEncryptedCookies(userExternalId, gatewayAccountId)
cy.task('setupStubs', [
userStubs.getUserSuccess({ userExternalId, gatewayAccountId }),
gatewayAccountStubs.getGatewayAccountSuccess({ gatewayAccountId, type: 'test', paymentProvider: 'worldpay' }),
gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId, type: 'test', paymentProvider: 'worldpay' }),
getProductsStub([product], gatewayAccountId),
getProductByExternalIdStub(product, gatewayAccountId),
deleteProductStub(product, gatewayAccountId, 1)
])
})

it('should list a single English payment links and have no Welsh payment links section', () => {
cy.visit('/create-payment-link/manage')
cy.visit(`/account/${gatewayAccountExternalId}/create-payment-link/manage`)

cy.get('h1').should('contain', 'Manage payment links')
cy.get('.payment-links-list--header').should('contain',
Expand Down
69 changes: 35 additions & 34 deletions test/cypress/integration/payment-links/edit-payment-link.cy.test.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const gatewayAccountStubs = require('../../stubs/gateway-account-stubs')
const productStubs = require('../../stubs/products-stubs')
const userExternalId = 'a-user-id'
const gatewayAccountId = 42
const gatewayAccountExternalId = 'a-valid-account-id'

const buildPaymentLinkOpts = function buildPaymentLinkOpts (name, href, language) {
return {
Expand Down Expand Up @@ -39,7 +40,7 @@ const buildPaymentLinkWithMetadataOpts = function buildPaymentLinkWithMetadataOp
function setupStubs (products) {
cy.task('setupStubs', [
userStubs.getUserSuccess({ userExternalId, gatewayAccountId }),
gatewayAccountStubs.getGatewayAccountSuccess({ gatewayAccountId, type: 'test', paymentProvider: 'worldpay' }),
gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId, type: 'test', paymentProvider: 'worldpay' }),
productStubs.getProductsStub(products, gatewayAccountId)
])
}
Expand All @@ -55,12 +56,12 @@ describe('The manage payment links page', () => {
})

it('should state that there are no payment links', () => {
cy.visit('/create-payment-link/manage')
cy.visit(`/account/${gatewayAccountExternalId}/create-payment-link/manage`)

cy.get('h1').should('contain', 'Manage payment links')
cy.get('.payment-links-list--header').should('contain',
'There are no payment links, you can create one now')
cy.get('.payment-links-list--header > a').should('have.attr', 'href', '/create-payment-link')
cy.get('.payment-links-list--header > a').should('have.attr', 'href', `/account/${gatewayAccountExternalId}/create-payment-link`)
})
})

Expand All @@ -77,7 +78,7 @@ describe('The manage payment links page', () => {
})

it('should list English payment links and have no Welsh payment links section', () => {
cy.visit('/create-payment-link/manage')
cy.visit(`/account/${gatewayAccountExternalId}/create-payment-link/manage`)

cy.get('h1').should('contain', 'Manage payment links')
cy.get('.payment-links-list--header').should('contain',
Expand Down Expand Up @@ -114,7 +115,7 @@ describe('The manage payment links page', () => {
})

it('should list English payment links and Welsh payment links separately', () => {
cy.visit('/create-payment-link/manage')
cy.visit(`/account/${gatewayAccountExternalId}/create-payment-link/manage`)

cy.get('h1').should('contain', 'Manage payment links')
cy.get('.payment-links-list--header').should('contain',
Expand Down Expand Up @@ -159,7 +160,7 @@ describe('The manage payment links page', () => {
})

it('should list Welsh payment links', () => {
cy.visit('/create-payment-link/manage')
cy.visit(`/account/${gatewayAccountExternalId}/create-payment-link/manage`)

cy.get('h1').should('contain', 'Manage payment links')
cy.get('.payment-links-list--header').should('contain',
Expand All @@ -186,13 +187,13 @@ describe('The manage payment links page', () => {
beforeEach(() => {
cy.task('setupStubs', [
userStubs.getUserSuccess({ userExternalId, gatewayAccountId }),
gatewayAccountStubs.getGatewayAccountSuccess({ gatewayAccountId, type: 'test', paymentProvider: 'worldpay' }),
gatewayAccountStubs.getGatewayAccountByExternalIdSuccess({ gatewayAccountId, gatewayAccountExternalId, type: 'test', paymentProvider: 'worldpay' }),
productStubs.getProductsByGatewayAccountIdFailure()
])
})

it('should display an error', () => {
cy.visit('/create-payment-link/manage', { failOnStatusCode: false })
cy.visit(`/account/${gatewayAccountExternalId}/create-payment-link/manage`, { failOnStatusCode: false })
cy.get('h1').should('contain', 'An error occurred:')
})
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ describe('GET edit amount controller', () => {
params: {
productExternalId
},
account: {
external_id: 'some-external-id'
},
flash: sinon.spy()
}
res = {
Expand All @@ -27,15 +30,15 @@ describe('GET edit amount controller', () => {

it('should return to "Manage payment links" with an error if session data not found', () => {
getEditAmountController(req, res, next)
sinon.assert.calledWith(res.redirect, '/create-payment-link/manage')
sinon.assert.calledWith(res.redirect, '/account/some-external-id/create-payment-link/manage')
})

it('should return to "Manage payment links" with an error if ID in URL does not match ID in session', () => {
lodash.set(req, 'session.editPaymentLinkData', {
externalId: 'a-different-id'
})
getEditAmountController(req, res, next)
sinon.assert.calledWith(res.redirect, '/create-payment-link/manage')
sinon.assert.calledWith(res.redirect, '/account/some-external-id/create-payment-link/manage')
})

it('should send field values from session when rendering page for fixed amount', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ describe('GET edit information controller', () => {
params: {
productExternalId
},
account: {
external_id: 'some-external-id'
},
flash: sinon.spy()
}
res = {
Expand All @@ -27,15 +30,15 @@ describe('GET edit information controller', () => {

it('should return to "Manage payment links" with an error if session data not found', () => {
getEditInformationController(req, res, next)
sinon.assert.calledWith(res.redirect, '/create-payment-link/manage')
sinon.assert.calledWith(res.redirect, '/account/some-external-id/create-payment-link/manage')
})

it('should return to "Manage payment links" with an error if ID in URL does not match ID in session', () => {
lodash.set(req, 'session.editPaymentLinkData', {
externalId: 'a-different-id'
})
getEditInformationController(req, res, next)
sinon.assert.calledWith(res.redirect, '/create-payment-link/manage')
sinon.assert.calledWith(res.redirect, '/account/some-external-id/create-payment-link/manage')
})

it('should send field values from session when rendering page', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ describe('GET edit reference controller', () => {
params: {
productExternalId
},
account: {
external_id: 'some-external-id'
},
flash: sinon.spy()
}
res = {
Expand All @@ -27,15 +30,15 @@ describe('GET edit reference controller', () => {

it('should return to "Manage payment links" with an error if session data not found', () => {
getEditReferenceController(req, res, next)
sinon.assert.calledWith(res.redirect, '/create-payment-link/manage')
sinon.assert.calledWith(res.redirect, '/account/some-external-id/create-payment-link/manage')
})

it('should return to "Manage payment links" with an error if ID in URL does not match ID in session', () => {
lodash.set(req, 'session.editPaymentLinkData', {
externalId: 'a-different-id'
})
getEditReferenceController(req, res, next)
sinon.assert.calledWith(res.redirect, '/create-payment-link/manage')
sinon.assert.calledWith(res.redirect, '/account/some-external-id/create-payment-link/manage')
})

it('should send field values from session when rendering page', () => {
Expand Down

0 comments on commit 17543a4

Please sign in to comment.