-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
PP-11682 Add Worldpay flex pact test for new connector Axios client
- Update the existing pact test to work with the new connector Axios client
- Loading branch information
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
87 changes: 87 additions & 0 deletions
87
test/unit/clients/connector-axios-client-worldpay-3ds-flex.pact.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,87 @@ | ||
'use strict' | ||
|
||
// NPM dependencies | ||
const path = require('path') | ||
const { Pact } = require('@pact-foundation/pact') | ||
const { expect } = require('chai') | ||
|
||
// Local dependencies | ||
const connectorClient = require('../../../app/services/clients/connector-axios.client') | ||
const { PactInteractionBuilder } = require('../../test-helpers/pact/pact-interaction-builder') | ||
const worlpay3dsFlexFixtures = require('../../fixtures/worldpay-3ds-flex.fixtures') | ||
const paymentFixtures = require('../../fixtures/payment.fixtures') | ||
const { pactify } = require('../../test-helpers/pact/pact-base')() | ||
|
||
const TEST_CHARGE_ID = 'testChargeId' | ||
const GET_JWT_URL = `/v1/frontend/charges/${TEST_CHARGE_ID}/worldpay/3ds-flex/ddc` | ||
const GET_CHARGE_URL = `/v1/frontend/charges/${TEST_CHARGE_ID}` | ||
|
||
const PORT = Math.floor(Math.random() * 48127) + 1024 | ||
const BASE_URL = `http://127.0.0.1:${PORT}` | ||
|
||
describe.only('connector client - Worldpay 3DS flex tests', function () { | ||
const provider = new Pact({ | ||
consumer: 'frontend', | ||
provider: 'connector', | ||
port: PORT, | ||
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'), | ||
dir: path.resolve(process.cwd(), 'pacts'), | ||
spec: 2, | ||
pactfileWriteMode: 'merge' | ||
}) | ||
|
||
before(() => provider.setup()) | ||
after(() => provider.finalize()) | ||
|
||
describe('get Worldpay 3DS flex JWT', function () { | ||
describe('success', function () { | ||
const response = worlpay3dsFlexFixtures.validDdcJwt() | ||
|
||
before(() => { | ||
const builder = new PactInteractionBuilder(GET_JWT_URL) | ||
.withMethod('GET') | ||
.withState('a Worldpay account exists with 3DS flex credentials and a charge with id testChargeId') | ||
.withUponReceiving('a valid get Worldpay 3DS flex DDC JWT request') | ||
.withResponseBody(pactify(response)) | ||
.withStatusCode(200) | ||
.build() | ||
return provider.addInteraction(builder) | ||
}) | ||
|
||
afterEach(() => provider.verify()) | ||
|
||
it('should return jwt', async function () { | ||
const res = await connectorClient({ baseUrl: BASE_URL }).getWorldpay3dsFlexJwt({ chargeId: TEST_CHARGE_ID }) | ||
expect(res.data.jwt).to.be.equal(response.jwt) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('get charge in 3DS required has a 3DS flex challenge JWT', function () { | ||
before(() => { | ||
const response = paymentFixtures.validChargeDetails({ | ||
chargeId: TEST_CHARGE_ID, | ||
cardTypes: [{ brand: 'visa' }], | ||
auth3dsData: { | ||
worldpayChallengeJwt: 'a-jwt' | ||
} | ||
}) | ||
|
||
const builder = new PactInteractionBuilder(GET_CHARGE_URL) | ||
.withMethod('GET') | ||
.withState('a Worldpay account exists with 3DS flex credentials and a charge with id testChargeId that is in state AUTHORISATION_3DS_REQUIRED') | ||
.withUponReceiving('a valid get charge request') | ||
.withResponseBody(pactify(response)) | ||
.withStatusCode(200) | ||
.build() | ||
return provider.addInteraction(builder) | ||
}) | ||
|
||
afterEach(() => provider.verify()) | ||
|
||
it('should return charge with worldpayChallengeJwt', async function () { | ||
const res = await connectorClient({ baseUrl: BASE_URL }).findCharge({ chargeId: TEST_CHARGE_ID }) | ||
expect(res.data.charge_id).to.be.equal(TEST_CHARGE_ID) | ||
}) | ||
}) | ||
}) |