Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PP-13428 add connector pact tests #4463

Merged
merged 1 commit into from
Feb 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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')
})
})
})
})
Loading