Skip to content

Commit

Permalink
PP-13312 Add to tests
Browse files Browse the repository at this point in the history
  • Loading branch information
james-peacock-gds committed Dec 5, 2024
1 parent 3b978eb commit 367dfd2
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ describe('Controller: settings/card-types', () => {
})

it('should pass context data to the response method', () => {
expect(responseStub.args[0][3]).to.have.property('cardTypes').to.have.property('Enabled debit cards').to.have.length(1)
expect(responseStub.args[0][3]).to.have.property('cardTypes').to.have.property('Enabled debit cards').to.have.length(1).to.include('Visa debit')
expect(responseStub.args[0][3].cardTypes).to.have.property('Not enabled debit cards').to.have.length(0)
expect(responseStub.args[0][3].cardTypes).to.have.property('Enabled credit cards').to.have.length(0)
expect(responseStub.args[0][3].cardTypes).to.have.property('Not enabled credit cards').to.have.length(1)
expect(responseStub.args[0][3].cardTypes).to.have.property('Not enabled credit cards').to.have.length(1).to.include('Visa credit')
expect(responseStub.args[0][3]).to.have.property('isAdminUser').to.equal(false)
})
})
Expand Down
43 changes: 38 additions & 5 deletions app/utils/simplified-account/format/format-card-types.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,53 @@ const allCards = [
]
describe('format-card-types for template', () => {
describe('present checkboxes for admin user', () => {
it('should return all card types if they are all enabled', () => {
it('should return all card types with checked boxes if they are all accepted', () => {
const acceptedCards = [...allCards]
const account = { requires3ds: true }
const cards = formatCardTypesForTemplate(allCards, acceptedCards, account, true)
expect(cards.debitCards).to.have.length(3)
expect(cards.creditCards).to.have.length(3)
expect(cards).to.have.property('debitCards').to.have.length(3)
expect(cards.debitCards[0].text).to.equal('Visa debit')
expect(cards.debitCards[0].checked).to.be.true // eslint-disable-line no-unused-expressions
expect(cards.debitCards[1].text).to.equal('Mastercard debit')
expect(cards.debitCards[1].checked).to.be.true // eslint-disable-line no-unused-expressions
expect(cards.debitCards[2].text).to.equal('Maestro')
expect(cards.debitCards[2].checked).to.be.true // eslint-disable-line no-unused-expressions
expect(cards).to.have.property('creditCards').to.have.length(3)
expect(cards.creditCards[0].text).to.equal('Visa credit')
expect(cards.creditCards[0].checked).to.be.true // eslint-disable-line no-unused-expressions
expect(cards.creditCards[1].text).to.equal('American Express')
expect(cards.creditCards[1].checked).to.be.true // eslint-disable-line no-unused-expressions
expect(cards.creditCards[2].text).to.equal('JCB')
expect(cards.creditCards[2].checked).to.be.true // eslint-disable-line no-unused-expressions
})

it('should return unchecked boxes for not accepted card types', () => {
const acceptedCards = [...allCards].filter(card => card.id !== 'id-001' && card.id !== 'id-002')
const account = { requires3ds: true }
const cards = formatCardTypesForTemplate(allCards, acceptedCards, account, true)
expect(cards).to.have.property('debitCards').to.have.length(3)
expect(cards.debitCards.filter(card => card.text === 'Visa debit')[0].checked).to.be.false // eslint-disable-line no-unused-expressions
expect(cards.debitCards.filter(card => card.text === 'Mastercard debit')[0].checked).to.be.true // eslint-disable-line no-unused-expressions
expect(cards.debitCards.filter(card => card.text === 'Maestro')[0].checked).to.be.true // eslint-disable-line no-unused-expressions
expect(cards).to.have.property('creditCards').to.have.length(3)
expect(cards.debitCards.filter(card => card.text === 'Visa credit')[0].checked).to.be.false // eslint-disable-line no-unused-expressions
expect(cards.debitCards.filter(card => card.text === 'American Express')[0].checked).to.be.true // eslint-disable-line no-unused-expressions
expect(cards.debitCards.filter(card => card.text === 'JCB')[0].checked).to.be.true // eslint-disable-line no-unused-expressions
})

it('should set checkbox to disabled for requires3ds card types if 3ds not enabled on account', () => {
const acceptedCards = [...allCards]
const account = { requires3ds: false }
const cards = formatCardTypesForTemplate(allCards, acceptedCards, account, true)
expect(cards.debitCards.filter(card => card.disabled === true)).to.have.length(1)
expect(cards.debitCards.filter(card => card.disabled === true)[0]).to.have.property('text').to.equal('Maestro')
expect(cards.debitCards.filter(card => card.text === 'Maestro')[0]).to.have.property('disabled').to.be.true // eslint-disable-line no-unused-expressions
})

it('should add hint to American Express if payment provider is Worldpay and account is live', () => {
const acceptedCards = [...allCards]
const account = { requires3ds: true, paymentProvider: 'worldpay', type: 'live' }
const cards = formatCardTypesForTemplate(allCards, acceptedCards, account, true)
expect(cards.creditCards.filter(card => card.text === 'American Express')[0])
.to.have.property('hint').to.deep.equal({ html: 'You must have already enabled this with Worldpay' })
})
})

Expand Down

0 comments on commit 367dfd2

Please sign in to comment.