Skip to content

Commit

Permalink
Merge pull request #3835 from alphagov/pp-11682-add-connector-google-…
Browse files Browse the repository at this point in the history
…pay-worldpay-pact-test-for-axios-connector

PP-11682 Add Worldpay Google pay pact test for new connector Axios client
  • Loading branch information
iqbalgds authored May 13, 2024
2 parents 2a48566 + 0a87119 commit 622add1
Showing 1 changed file with 151 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
'use strict'

// Core dependencies
const path = require('path')

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

// Constants
const TEST_CHARGE_ID = 'testChargeId'
const GOOGLE_AUTH_PATH = `/v1/frontend/charges/${TEST_CHARGE_ID}/wallets/google`
const PORT = Math.floor(Math.random() * 48127) + 1024
const BASEURL = `http://127.0.0.1:${PORT}`

// Custom dependencies
const connectorClient = require('../../../app/services/clients/connector-axios.client')
const fixtures = require('../../fixtures/wallet-payment.fixtures')
const { PactInteractionBuilder } = require('../../test-helpers/pact/pact-interaction-builder')
const { pactify } = require('../../test-helpers/pact/pact-base')()

// Global setup
const expect = chai.expect
chai.use(chaiAsPromised)

const GOOGLE_DDC_RESULT = 'some long opaque string that’s a device data collection result'

describe('Connector Client - Google Pay authorisation API - Worldpay payment', 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('Authorise Worldpay Google Pay payment', function () {
describe('authorisation success', function () {
const successfulGoogleAuthRequest = fixtures.worldpayOrSandboxGoogleAuthRequestDetails({ worldpay3dsFlexDdcResult: GOOGLE_DDC_RESULT })
const authorisationSuccessResponse = fixtures.webPaymentSuccessResponse()
before(() => {
const builder = new PactInteractionBuilder(GOOGLE_AUTH_PATH)
.withRequestBody(successfulGoogleAuthRequest)
.withMethod('POST')
.withState('a Worldpay account exists with a charge with id testChargeId that is in state ENTERING_CARD_DETAILS.')
.withUponReceiving('a valid worldpay google pay auth request which should be authorised')
.withResponseBody(pactify(authorisationSuccessResponse))
.withStatusCode(200)
.build()
return provider.addInteraction(builder)
})

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

it('should return authorisation success', async () => {
const payload = successfulGoogleAuthRequest

try {
const res = await connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({
chargeId: TEST_CHARGE_ID,
wallet: 'google',
payload: payload
})

expect(res.data.status).to.be.equal('AUTHORISATION SUCCESS')
} catch (err) {
throw new Error('should not be hit: ' + JSON.stringify(err))
}
})
})

describe('authorisation success with no last card digits', function () {
const successfulGoogleAuthRequest = fixtures.worldpayOrSandboxGoogleAuthRequestDetails({
lastDigitsCardNumber: '',
worldpay3dsFlexDdcResult: GOOGLE_DDC_RESULT
})
const authorisationSuccessResponse = fixtures.webPaymentSuccessResponse()

before(() => {
const builder = new PactInteractionBuilder(GOOGLE_AUTH_PATH)
.withRequestBody(successfulGoogleAuthRequest)
.withMethod('POST')
.withState('a Worldpay account exists with a charge with id testChargeId that is in state ENTERING_CARD_DETAILS.')
.withUponReceiving('a valid worldpay google pay auth request with no last card digits which should be authorised')
.withResponseBody(pactify(authorisationSuccessResponse))
.withStatusCode(200)
.build()
return provider.addInteraction(builder)
})

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

it('should return authorisation success', async () => {
const payload = successfulGoogleAuthRequest

try {
const res = await connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({
chargeId: TEST_CHARGE_ID,
wallet: 'google',
payload: payload
})

expect(res.data.status).to.be.equal('AUTHORISATION SUCCESS')
} catch (err) {
throw new Error('should not be hit: ' + JSON.stringify(err))
}
})
})

describe('authorisation success with no ddc result', function () {
const successfulGoogleAuthRequest = fixtures.worldpayOrSandboxGoogleAuthRequestDetails()
const authorisationSuccessResponse = fixtures.webPaymentSuccessResponse()

before(() => {
const builder = new PactInteractionBuilder(GOOGLE_AUTH_PATH)
.withRequestBody(successfulGoogleAuthRequest)
.withMethod('POST')
.withState('a Worldpay account exists with a charge with id testChargeId that is in state ENTERING_CARD_DETAILS.')
.withUponReceiving('a valid worldpay google pay auth request with no ddc result which should be authorised')
.withResponseBody(pactify(authorisationSuccessResponse))
.withStatusCode(200)
.build()
return provider.addInteraction(builder)
})

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

it('should return authorisation success', async () => {
const payload = successfulGoogleAuthRequest

try {
const res = await connectorClient({ baseUrl: BASEURL }).chargeAuthWithWallet({
chargeId: TEST_CHARGE_ID,
wallet: 'google',
payload: payload
})

expect(res.data.status).to.be.equal('AUTHORISATION SUCCESS')
} catch (err) {
throw new Error('should not be hit: ' + JSON.stringify(err))
}
})
})
})
})

0 comments on commit 622add1

Please sign in to comment.