-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4387 from alphagov/pp-13335-show-3ds-exemption-info
PP-13335 PP-13335 Transactions details page - display corporate exemptions data.
- Loading branch information
Showing
8 changed files
with
390 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/controllers/transactions/transaction-detail.controller.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
const sinon = require('sinon') | ||
const proxyquire = require('proxyquire') | ||
const ledgerTransactionFixture = require('../../../test/fixtures/ledger-transaction.fixtures') | ||
const { validGatewayAccountResponse } = require('../../../test/fixtures/gateway-account.fixtures') | ||
|
||
describe('Transaction details - GET', () => { | ||
let res, next, transaction, transactionServiceSpy | ||
|
||
const gatewayAccountId = '15486734' | ||
|
||
const EXTERNAL_GATEWAY_ACCOUNT_ID = 'an-external-id' | ||
|
||
const transactionId = 'a-transaction-id' | ||
|
||
const account = validGatewayAccountResponse( | ||
{ | ||
external_id: EXTERNAL_GATEWAY_ACCOUNT_ID, | ||
gateway_account_id: gatewayAccountId, | ||
payment_provider: 'sandbox', | ||
credentials: { username: 'a-username' } | ||
} | ||
) | ||
|
||
const req = { | ||
account, | ||
session: {}, | ||
params: { chargeId: transactionId } | ||
} | ||
|
||
const responseSpy = { | ||
response: sinon.spy() | ||
} | ||
|
||
beforeEach(() => { | ||
res = { | ||
render: sinon.spy() | ||
} | ||
|
||
next = sinon.spy() | ||
|
||
transaction = ledgerTransactionFixture.validTransactionDetailsResponse() | ||
responseSpy.response.resetHistory() | ||
}) | ||
|
||
describe('passing the isCorporateExemptionsEnabled flag correctly when calling ledgerFindWithEvents', () => { | ||
it('should not set flag when worldpay_3ds_flag is UNDEFINED on the gateway account', async () => { | ||
req.account.worldpay_3ds_flex = undefined | ||
|
||
const controller = getControllerWithMocks(transaction, responseSpy) | ||
|
||
await controller(req, res, next) | ||
|
||
sinon.assert.called(responseSpy.response) | ||
sinon.assert.called(transactionServiceSpy.ledgerFindWithEvents) | ||
|
||
sinon.assert.match(transactionServiceSpy.ledgerFindWithEvents.firstCall.args[2], undefined) | ||
}) | ||
|
||
it('should set flag=false when corporate exemptions = false on the gateway account', async () => { | ||
req.account.worldpay_3ds_flex = { | ||
corporate_exemptions_enabled: false | ||
} | ||
|
||
const controller = getControllerWithMocks(transaction, responseSpy) | ||
|
||
await controller(req, res, next) | ||
|
||
sinon.assert.called(responseSpy.response) | ||
sinon.assert.called(transactionServiceSpy.ledgerFindWithEvents) | ||
|
||
sinon.assert.match(transactionServiceSpy.ledgerFindWithEvents.firstCall.args[2], false) | ||
}) | ||
|
||
it('should set flag=true when corporate exemptions = true on the gateway account', async () => { | ||
req.account.worldpay_3ds_flex = { | ||
corporate_exemptions_enabled: true | ||
} | ||
|
||
const controller = getControllerWithMocks(transaction, responseSpy) | ||
|
||
await controller(req, res, next) | ||
|
||
sinon.assert.called(responseSpy.response) | ||
sinon.assert.called(transactionServiceSpy.ledgerFindWithEvents) | ||
|
||
sinon.assert.match(transactionServiceSpy.ledgerFindWithEvents.firstCall.args[2], true) | ||
}) | ||
}) | ||
|
||
function getControllerWithMocks (transaction, responseSpy) { | ||
transactionServiceSpy = { | ||
ledgerFindWithEvents: sinon.spy(() => { | ||
return transaction | ||
}) | ||
} | ||
|
||
return proxyquire('./transaction-detail.controller', { | ||
'../../services/transaction.service': transactionServiceSpy, | ||
'../../utils/response.js': responseSpy | ||
}) | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -81,4 +81,186 @@ describe('Transaction view utilities', () => { | |
expect(paymentView.email).to.equal('[email protected]') | ||
expect(paymentView.card_details.cardholder_name).to.equal('Jane D') | ||
}) | ||
|
||
describe('3D secure data', () => { | ||
it('should not set `three_d_Secure` field if no 3D secure object', () => { | ||
const transaction = transactionFixtures.validTransactionDetailsResponse({}) | ||
|
||
const events = transactionFixtures.validTransactionEventsResponse() | ||
const paymentView = buildPaymentView(transaction, events) | ||
|
||
expect(paymentView.three_d_secure).equal(undefined) | ||
}) | ||
|
||
it('should correctly set `three_d_Secure` field to required', () => { | ||
const transaction = transactionFixtures.validTransactionDetailsResponse({ | ||
authorisation_summary: { | ||
three_d_security: { | ||
required: true | ||
} | ||
} | ||
}) | ||
|
||
const events = transactionFixtures.validTransactionEventsResponse() | ||
const paymentView = buildPaymentView(transaction, events) | ||
|
||
expect(paymentView.three_d_secure).equal('Required') | ||
}) | ||
|
||
it('should correctly set `three_d_Secure` field to not required', () => { | ||
const transaction = transactionFixtures.validTransactionDetailsResponse({ | ||
authorisation_summary: { | ||
three_d_security: { | ||
required: false | ||
} | ||
} | ||
}) | ||
|
||
const events = transactionFixtures.validTransactionEventsResponse() | ||
const paymentView = buildPaymentView(transaction, events) | ||
|
||
expect(paymentView.three_d_secure).equal('Not required') | ||
}) | ||
}) | ||
|
||
describe('Corporate exemption data', () => { | ||
describe('when requested=true', () => { | ||
describe('when type=corporate', () => { | ||
it('should set to `honoured`', () => { | ||
const transaction = transactionFixtures.validTransactionDetailsResponse({ | ||
exemption: { | ||
requested: true, | ||
type: 'corporate', | ||
outcome: { | ||
result: 'honoured' | ||
} | ||
} | ||
}) | ||
|
||
const events = transactionFixtures.validTransactionEventsResponse() | ||
const paymentView = buildPaymentView(transaction, events) | ||
|
||
expect(paymentView.corporate_exemption_requested).to.equal('Honoured') | ||
}) | ||
|
||
it('should set to `rejected`', () => { | ||
const transaction = transactionFixtures.validTransactionDetailsResponse({ | ||
exemption: { | ||
requested: true, | ||
type: 'corporate', | ||
outcome: { | ||
result: 'rejected' | ||
} | ||
} | ||
}) | ||
|
||
const events = transactionFixtures.validTransactionEventsResponse() | ||
const paymentView = buildPaymentView(transaction, events) | ||
|
||
expect(paymentView.corporate_exemption_requested).to.equal('Rejected') | ||
}) | ||
|
||
it('should set to `out of scope`', async () => { | ||
const transaction = transactionFixtures.validTransactionDetailsResponse({ | ||
exemption: { | ||
requested: true, | ||
type: 'corporate', | ||
outcome: { | ||
result: 'out of scope' | ||
} | ||
} | ||
}) | ||
|
||
const events = transactionFixtures.validTransactionEventsResponse() | ||
const paymentView = buildPaymentView(transaction, events) | ||
|
||
expect(paymentView.corporate_exemption_requested).to.equal('Out of scope') | ||
}) | ||
|
||
it('should not set a value when there is no `outcome` row', async () => { | ||
const transaction = transactionFixtures.validTransactionDetailsResponse({ | ||
exemption: { | ||
requested: true, | ||
type: 'corporate' | ||
} | ||
}) | ||
|
||
const events = transactionFixtures.validTransactionEventsResponse() | ||
const paymentView = buildPaymentView(transaction, events) | ||
|
||
expect(paymentView.corporate_exemption_requested).to.equal(undefined) | ||
}) | ||
}) | ||
|
||
describe('when type NOT equal to corporate', () => { | ||
describe('when corporate exemptions are disabled on the account', () => { | ||
it('should not set the field', () => { | ||
const transaction = transactionFixtures.validTransactionDetailsResponse({ | ||
exemption: { | ||
requested: true, | ||
outcome: { | ||
result: 'honoured' | ||
} | ||
} | ||
}) | ||
|
||
const events = transactionFixtures.validTransactionEventsResponse() | ||
const paymentView = buildPaymentView(transaction, events, null, false) | ||
|
||
expect(paymentView.corporate_exemption_requested).to.equal(undefined) | ||
}) | ||
}) | ||
|
||
describe('when corporate exemptions are enabled on the account', () => { | ||
it('should set field to `not requested`', () => { | ||
const transaction = transactionFixtures.validTransactionDetailsResponse({ | ||
exemption: { | ||
requested: true, | ||
outcome: { | ||
result: 'honoured' | ||
} | ||
} | ||
}) | ||
|
||
const events = transactionFixtures.validTransactionEventsResponse() | ||
const paymentView = buildPaymentView(transaction, events, null, true) | ||
|
||
expect(paymentView.corporate_exemption_requested).to.equal('Not requested') | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('when requested=false', () => { | ||
describe('when corporate exemptions are disabled on the account', () => { | ||
it('should not set the field', () => { | ||
const transaction = transactionFixtures.validTransactionDetailsResponse({ | ||
exemption: { | ||
requested: false | ||
} | ||
}) | ||
|
||
const events = transactionFixtures.validTransactionEventsResponse() | ||
const paymentView = buildPaymentView(transaction, events, null, false) | ||
|
||
expect(paymentView.corporate_exemption_requested).to.equal(undefined) | ||
}) | ||
}) | ||
|
||
describe('when corporate exemptions are enabled on the account', () => { | ||
it('should set the field to `not requested`', () => { | ||
const transaction = transactionFixtures.validTransactionDetailsResponse({ | ||
exemption: { | ||
requested: false | ||
} | ||
}) | ||
|
||
const events = transactionFixtures.validTransactionEventsResponse() | ||
const paymentView = buildPaymentView(transaction, events, null, true) | ||
|
||
expect(paymentView.corporate_exemption_requested).to.equal('Not requested') | ||
}) | ||
}) | ||
}) | ||
}) | ||
}) |
Oops, something went wrong.