From e36beac11a5d73b416952906c09abcd17ecc6e36 Mon Sep 17 00:00:00 2001 From: Iqbal Ahmed Date: Mon, 13 May 2024 13:27:59 +0100 Subject: [PATCH] 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 --- ...xios-client-worldpay-3ds-flex.pact.test.js | 87 +++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 test/unit/clients/connector-axios-client-worldpay-3ds-flex.pact.test.js diff --git a/test/unit/clients/connector-axios-client-worldpay-3ds-flex.pact.test.js b/test/unit/clients/connector-axios-client-worldpay-3ds-flex.pact.test.js new file mode 100644 index 000000000..09c5063d6 --- /dev/null +++ b/test/unit/clients/connector-axios-client-worldpay-3ds-flex.pact.test.js @@ -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('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) + }) + }) +})