Skip to content

Commit

Permalink
PP-12413: Pact test for requesting a stripe test account (#4244)
Browse files Browse the repository at this point in the history
* PP-12413: Pact test for requesting a stripe test account

Pact test to verify a call of `POST
/v1/service/{serviceId}/request-stripe-test-account` from selfservice to
connector works.
  • Loading branch information
oswaldquek authored Aug 6, 2024
1 parent ac35a8a commit 4395eb8
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
6 changes: 6 additions & 0 deletions app/services/clients/connector.client.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,12 @@ ConnectorClient.prototype = {
return responseBodyToStripeAccountTransformer(response.data)
},

requestStripeTestAccount: async function (serviceId) {
const url = `${this.connectorUrl}/v1/service/${serviceId}/request-stripe-test-account`
configureClient(client, url)
await client.post(url)
},

postChargeRequest: async function (gatewayAccountId, payload) {
const url = `${this.connectorUrl}${CHARGES_API_PATH.replace('{accountId}', gatewayAccountId)}`
configureClient(client, url)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ describe('connector client', function () {

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

it('should post a refund request successfully', async () => {
it('should create a charge request successfully', async () => {
const connectorResponse = await connectorClient.postChargeRequest(gatewayAccountId, validPostCreateChargeRequest)
expect(connectorResponse.state.status).to.equal('created')
expect(connectorResponse.return_url).to.equal('https://somewhere.gov.uk/rainbow/1')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
'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('../../../app/services/clients/connector.client').ConnectorClient
const { string } = require('@pact-foundation/pact').Matchers

// Constants
let connectorClient

// Global setup
chai.use(chaiAsPromised)

const serviceId = 'a-service-id'

describe('connector client - request stripe test account', function () {
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('when a post to request stripe test account is made', () => {
describe('success', () => {
const validResponse = {
stripe_connect_account_id: 'acct_123',
gateway_account_id: string('1'),
gateway_account_external_id: string('an-external-id')
}

before(() => {
return provider.addInteraction(
new PactInteractionBuilder(`/v1/service/${serviceId}/request-stripe-test-account`)
.withUponReceiving('a request for a stripe test account')
.withState('a sandbox gateway account with service id a-service-id exists and stripe is configured to create a connect account with id acct_123')
.withMethod('POST')
.withStatusCode(200)
.withResponseHeaders({ 'Content-Type': 'application/json' })
.withResponseBody(validResponse)
.build()
)
})

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

it('a stripe test account and new gateway account should be created', async () => {
await connectorClient.requestStripeTestAccount(serviceId)
})
})
})
})

0 comments on commit 4395eb8

Please sign in to comment.