-
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 connector charge pact for the new Axios connector client
- Updated the test to work with the connector Axios client.
- Loading branch information
Showing
1 changed file
with
118 additions
and
0 deletions.
There are no files selected for viewing
118 changes: 118 additions & 0 deletions
118
test/unit/clients/connector-axios-client-charge.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,118 @@ | ||
'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 fixtures = require('../../fixtures/payment.fixtures') | ||
const { PactInteractionBuilder } = require('../../test-helpers/pact/pact-interaction-builder') | ||
const { pactify } = require('../../test-helpers/pact/pact-base')() | ||
|
||
const TEST_CHARGE_ID = 'testChargeId' | ||
const GET_CHARGE_URL = `/v1/frontend/charges/${TEST_CHARGE_ID}` | ||
const AUTHORISE_CHARGE_URL = `/v1/frontend/charges/${TEST_CHARGE_ID}/cards` | ||
|
||
const PORT = Math.floor(Math.random() * 48127) + 1024 | ||
const BASE_URL = `http://127.0.0.1:${PORT}` | ||
|
||
describe('Connector client - charge 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('Authorisation request success', function () { | ||
const authRequest = fixtures.validAuthorisationRequest() | ||
|
||
before(() => { | ||
const response = fixtures.validChargeCardDetailsAuthorised() | ||
const builder = new PactInteractionBuilder(AUTHORISE_CHARGE_URL) | ||
.withRequestBody(authRequest) | ||
.withMethod('POST') | ||
.withState('a sandbox account exists with a charge with id testChargeId that is in state ENTERING_CARD_DETAILS.') | ||
.withUponReceiving('an authorisation request') | ||
.withResponseBody(pactify(response)) | ||
.withStatusCode(200) | ||
.build() | ||
return provider.addInteraction(builder) | ||
}) | ||
|
||
afterEach(() => provider.verify()) | ||
|
||
it('should return authorisation success', async () => { | ||
try { | ||
const res = await connectorClient({ baseUrl: BASE_URL }).chargeAuth({ | ||
chargeId: TEST_CHARGE_ID, | ||
payload: authRequest | ||
}) | ||
|
||
expect(res.data.status).to.be.equal('AUTHORISATION SUCCESS') | ||
} catch (err) { | ||
throw new Error('should not be hit: ' + JSON.stringify(err)) | ||
} | ||
}) | ||
}) | ||
|
||
describe('Authorisation request without a billing address success', function () { | ||
const authRequest = fixtures.validAuthorisationRequest({ noBillingAddress: true }) | ||
|
||
before(() => { | ||
const response = fixtures.validChargeCardDetailsAuthorised() | ||
const builder = new PactInteractionBuilder(AUTHORISE_CHARGE_URL) | ||
.withRequestBody(authRequest) | ||
.withMethod('POST') | ||
.withState('a sandbox account exists with a charge with id testChargeId that is in state ENTERING_CARD_DETAILS.') | ||
.withUponReceiving('an authorisation request without a billing address') | ||
.withResponseBody(pactify(response)) | ||
.withStatusCode(200) | ||
.build() | ||
return provider.addInteraction(builder) | ||
}) | ||
|
||
afterEach(() => provider.verify()) | ||
|
||
it('should return authorisation success', async () => { | ||
const res = await connectorClient({ baseUrl: BASE_URL }).chargeAuth({ | ||
chargeId: TEST_CHARGE_ID, | ||
payload: authRequest | ||
}) | ||
expect(res.data.status).to.be.equal('AUTHORISATION SUCCESS') | ||
}) | ||
}) | ||
|
||
describe('Find charge success', function () { | ||
before(() => { | ||
const response = fixtures.validChargeDetails({ | ||
chargeId: TEST_CHARGE_ID, | ||
cardTypes: [{ brand: 'visa' }] | ||
}) | ||
|
||
const builder = new PactInteractionBuilder(GET_CHARGE_URL) | ||
.withMethod('GET') | ||
.withState('a sandbox account exists with a charge with id testChargeId that is in state ENTERING_CARD_DETAILS.') | ||
.withUponReceiving('a valid get charge request') | ||
.withResponseBody(pactify(response)) | ||
.withStatusCode(200) | ||
.build() | ||
return provider.addInteraction(builder) | ||
}) | ||
|
||
afterEach(() => provider.verify()) | ||
|
||
it('should return charge', async () => { | ||
const res = await connectorClient({ baseUrl: BASE_URL }).findCharge({ chargeId: TEST_CHARGE_ID }) | ||
expect(res.data.charge_id).to.be.equal(TEST_CHARGE_ID) | ||
}) | ||
}) | ||
}) |