Skip to content

Commit

Permalink
PP-13428 add connector pact tests
Browse files Browse the repository at this point in the history
Add PACT tests between selfservice and connector to test for 3D secure and corporate exemption data
  • Loading branch information
SandorArpa committed Feb 14, 2025
1 parent 6aecd01 commit 9911226
Show file tree
Hide file tree
Showing 4 changed files with 170 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .secrets.baseline
Original file line number Diff line number Diff line change
Expand Up @@ -908,5 +908,5 @@
}
]
},
"generated_at": "2025-01-20T13:08:00Z"
"generated_at": "2025-02-14T11:33:55Z"
}
21 changes: 20 additions & 1 deletion test/fixtures/charge.fixtures.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,27 @@ function validGetChargeResponse (opts = {}) {
}
}

function validGetChargeResponseWithExemption (opts = {}) {
return {
state: opts.state || { status: 'started', finished: false },
charge_id: opts.chargeId || 'ch_123abc456def',
exemption: opts.exemption || { requested: true, type: 'corporate', outcome: { result: 'honoured' }},
authorisation_summary: opts.authorisation_summary || { three_d_secure: { required: true, version: '2.1.0' }}
}
}

function validGetChargeResponseWithAuthSummary (opts = {}) {
return {
state: opts.state || { status: 'started', finished: false },
charge_id: opts.chargeId || 'ch_123abc456def',
authorisation_summary: opts.authorisation_summary || { three_d_secure: { required: true, version: '2.1.0' }}
}
}

module.exports = {
validPostChargeRequestRequest,
validPostChargeRequestResponse,
validGetChargeResponse
validGetChargeResponse,
validGetChargeResponseWithExemption,
validGetChargeResponseWithAuthSummary
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
'use strict'

const { Pact } = require('@pact-foundation/pact')
const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
const path = require('path')

const PactInteractionBuilder = require('../../test-helpers/pact/pact-interaction-builder').PactInteractionBuilder
const Connector = require('../../../src/services/clients/connector.client').ConnectorClient
const chargeFixture = require('../../fixtures/charge.fixtures')
const { pactify } = require('../../test-helpers/pact/pactifier').defaultPactifier

// Constants
const ACCOUNTS_RESOURCE = '/v1/api/accounts'
let connectorClient
const expect = chai.expect

// Global setup
chai.use(chaiAsPromised)

const existingGatewayAccountId = 123456
const existingChargeExternalId = 'ch_123abc456def'

describe('connector client - get single charge', () => {
const provider = new Pact({
consumer: 'selfservice',
provider: 'connector',
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
dir: path.resolve(process.cwd(), 'pacts'),
spec: 2,
pactfileWriteMode: 'merge'
})

before(async () => {
const opts = await provider.setup()
connectorClient = new Connector(`http://127.0.0.1:${opts.port}`)
})
after(() => provider.finalize())

describe('get single charge which has authorisation summary request', () => {
const opts = {
chargeId: existingChargeExternalId,
state: {
status: 'success',
finished: true
},
exemption: {
requested: false
}
}
const response = chargeFixture.validGetChargeResponseWithAuthSummary(opts)

before(() => {
return provider.addInteraction(
new PactInteractionBuilder(`${ACCOUNTS_RESOURCE}/${existingGatewayAccountId}/charges/${existingChargeExternalId}`)
.withUponReceiving('a valid get charge which has authorisation summary request')
.withState("a charge exists")
.withMethod('GET')
.withStatusCode(200)
.withResponseBody(pactify(response))
.build())
})

afterEach(() => provider.verify())

it('should get a charge which has authorisation summary successfully', function () {
return connectorClient.getCharge(existingGatewayAccountId, existingChargeExternalId)
.then(charge => {
expect(charge.charge_id).to.equal(existingChargeExternalId)
expect(charge.authorisation_summary.three_d_secure.required).to.equal(true)
expect(charge.authorisation_summary.three_d_secure.version).to.equal('2.1.0')
})
})
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use strict'

const { Pact } = require('@pact-foundation/pact')
const chai = require('chai')
const chaiAsPromised = require('chai-as-promised')
const path = require('path')

const PactInteractionBuilder = require('../../test-helpers/pact/pact-interaction-builder').PactInteractionBuilder
const Connector = require('../../../src/services/clients/connector.client').ConnectorClient
const chargeFixture = require('../../fixtures/charge.fixtures')
const { pactify } = require('../../test-helpers/pact/pactifier').defaultPactifier

// Constants
const ACCOUNTS_RESOURCE = '/v1/api/accounts'
let connectorClient
const expect = chai.expect

// Global setup
chai.use(chaiAsPromised)

const existingGatewayAccountId = 123456
const existingChargeExternalId = 'ch_123abc456def'

describe('connector client - get single charge', () => {
const provider = new Pact({
consumer: 'selfservice',
provider: 'connector',
log: path.resolve(process.cwd(), 'logs', 'mockserver-integration.log'),
dir: path.resolve(process.cwd(), 'pacts'),
spec: 2,
pactfileWriteMode: 'merge'
})

before(async () => {
const opts = await provider.setup()
connectorClient = new Connector(`http://127.0.0.1:${opts.port}`)
})
after(() => provider.finalize())

describe('get single charge which has an honoured corporate exemption request', () => {
const opts = {
chargeId: existingChargeExternalId,
state: {
status: 'success',
finished: true
},
authorisation_summary: {three_d_secure: { required: false}}
}
const response = chargeFixture.validGetChargeResponseWithExemption(opts)

before(() => {
return provider.addInteraction(
new PactInteractionBuilder(`${ACCOUNTS_RESOURCE}/${existingGatewayAccountId}/charges/${existingChargeExternalId}`)
.withUponReceiving('a valid get charge which has an honoured corporate exemption request')
.withState("a charge with honoured corporate exemption exists")
.withMethod('GET')
.withStatusCode(200)
.withResponseBody(pactify(response))
.build())
})

afterEach(() => provider.verify())

it('should get a charge which has an honoured corporate exemption successfully', function () {
return connectorClient.getCharge(existingGatewayAccountId, existingChargeExternalId)
.then(charge => {
expect(charge.charge_id).to.equal(existingChargeExternalId)
expect(charge.exemption.requested).to.equal(true)
expect(charge.exemption.type).to.equal('corporate')
expect(charge.exemption.outcome.result).to.equal('honoured')
})
})
})
})

0 comments on commit 9911226

Please sign in to comment.