diff --git a/app/controllers/simplified-account/settings/card-types/card-types.controller.test.js b/app/controllers/simplified-account/settings/card-types/card-types.controller.test.js index 1656ed6d6..34ce0302e 100644 --- a/app/controllers/simplified-account/settings/card-types/card-types.controller.test.js +++ b/app/controllers/simplified-account/settings/card-types/card-types.controller.test.js @@ -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) }) }) diff --git a/app/utils/simplified-account/format/format-card-types.test.js b/app/utils/simplified-account/format/format-card-types.test.js index 3e3d8ed87..f33140526 100644 --- a/app/utils/simplified-account/format/format-card-types.test.js +++ b/app/utils/simplified-account/format/format-card-types.test.js @@ -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' }) }) })