Skip to content

Commit

Permalink
PP-11288-Improve Validation on Prefilled Payment Links
Browse files Browse the repository at this point in the history
- Added Cypress Tests
  • Loading branch information
olatomgds committed Nov 15, 2023
1 parent 552bdef commit 06afda2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
12 changes: 12 additions & 0 deletions test/cypress/integration/payment-links/amount.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ describe('Amount page', () => {
cy.get('[data-cy=error-message]').should('contain', 'Enter an amount in pounds and pence using digits and a decimal point, like 123.45 or 156.00')
})

it('when the amount is £0.00, should display an error', () => {
cy.visit('/pay/a-product-id/amount')
cy.get('[data-cy=input]').type('0.00', { delay: 0 })
cy.get('[data-cy=button]').click()

cy.get('[data-cy=error-summary] a')
.should('contain', 'Amount must be £0.01 or more')
.should('have.attr', 'href', '#payment-amount')

cy.get('[data-cy=error-message]').should('contain', 'Amount must be £0.01 or more')
})

it('when a valid amount is entered, should then go to the `confirm` page', () => {
cy.visit('/pay/a-product-id/amount')
cy.get('[data-cy=input]')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,29 @@ describe('Payment link visited with amount and reference provided as query param
})
})
})

it('should show error page when confirmation page has a £0 amount and the "Continue to payment" button is clicked', () => {
cy.visit(`/redirect/${serviceNamePath}/${productNamePath}?amount=0&reference=REF123`)
cy.get('h1').should('have.text', productName)

cy.get('[data-cy=button]').click()

cy.location().should((location) => {
expect(location.pathname).to.eq(`/pay/${productExternalId}/confirm`)
})

cy.get('.govuk-summary-list__row').eq(1).within(() => {
cy.get('dt').should('contain', 'Total to pay')
cy.get('dd').eq(0).should('contain', '£0')
// should have no change link
cy.get('dd').eq(1).should('not.exist')
})

cy.get('[data-cy=continue-to-payment-button]').click()
cy.get('h1').should('have.text', 'An error occurred:')
cy.get('[data-cy=error-message]').should('have.text', 'There is a problem with the link you have been sent to use to pay. ' +
'The payment amount cannot be £0.00. Contact the service you’re trying to make a payment to.')
})
})

describe('Payment link visited with invalid amount in query params', () => {
Expand Down Expand Up @@ -91,4 +114,4 @@ describe('Payment link visited with invalid reference in query params', () => {
cy.get('h1').should('have.text', 'An error occurred:')
cy.get('[data-cy=error-message]').should('have.text', 'Please contact the service you are trying to make a payment to.')
})
})
})

0 comments on commit 06afda2

Please sign in to comment.