@defra-fish/connectors-lib 1.62.0-rc.6 → 1.62.0-rc.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra-fish/connectors-lib",
|
|
3
|
-
"version": "1.62.0-rc.
|
|
3
|
+
"version": "1.62.0-rc.8",
|
|
4
4
|
"description": "Shared connectors",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -46,5 +46,5 @@
|
|
|
46
46
|
"node-fetch": "^2.7.0",
|
|
47
47
|
"redlock": "^4.2.0"
|
|
48
48
|
},
|
|
49
|
-
"gitHead": "
|
|
49
|
+
"gitHead": "5d9e947d9ce87f6f43aa6ca7ac8d78f797ecebdf"
|
|
50
50
|
}
|
|
@@ -147,4 +147,23 @@ describe('govuk-pay-api-connector', () => {
|
|
|
147
147
|
expect(consoleErrorSpy).toHaveBeenCalled()
|
|
148
148
|
})
|
|
149
149
|
})
|
|
150
|
+
|
|
151
|
+
describe('getRecurringPaymentAgreementInformation', () => {
|
|
152
|
+
it('retrieves recurring payment agreement information', async () => {
|
|
153
|
+
fetch.mockReturnValue({ ok: true, status: 200, json: () => {} })
|
|
154
|
+
await expect(govUkPayApi.getRecurringPaymentAgreementInformation(123)).resolves.toEqual(
|
|
155
|
+
expect.objectContaining({ ok: true, status: 200 })
|
|
156
|
+
)
|
|
157
|
+
expect(fetch).toHaveBeenCalledWith('http://0.0.0.0/agreement/123', { headers: recurringHeaders, method: 'get', timeout: 10000 })
|
|
158
|
+
})
|
|
159
|
+
|
|
160
|
+
it('logs and throws errors', async () => {
|
|
161
|
+
const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(jest.fn())
|
|
162
|
+
fetch.mockImplementation(() => {
|
|
163
|
+
throw new Error('test event error')
|
|
164
|
+
})
|
|
165
|
+
await expect(govUkPayApi.getRecurringPaymentAgreementInformation(123)).rejects.toEqual(Error('test event error'))
|
|
166
|
+
expect(consoleErrorSpy).toHaveBeenCalled()
|
|
167
|
+
})
|
|
168
|
+
})
|
|
150
169
|
})
|
package/src/govuk-pay-api.js
CHANGED
|
@@ -86,3 +86,21 @@ export const fetchPaymentEvents = async (paymentId, recurring = false) => {
|
|
|
86
86
|
throw err
|
|
87
87
|
}
|
|
88
88
|
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Gets payment information linked too a payment
|
|
92
|
+
* @param agreementId - agreementId set up when creating recurring payment
|
|
93
|
+
* @returns {Promise<*>}
|
|
94
|
+
*/
|
|
95
|
+
export const getRecurringPaymentAgreementInformation = async agreementId => {
|
|
96
|
+
try {
|
|
97
|
+
return fetch(`${process.env.GOV_PAY_RCP_API_URL}/${agreementId}`, {
|
|
98
|
+
headers: headers(true),
|
|
99
|
+
method: 'get',
|
|
100
|
+
timeout: process.env.GOV_PAY_REQUEST_TIMEOUT_MS || GOV_PAY_REQUEST_TIMEOUT_MS_DEFAULT
|
|
101
|
+
})
|
|
102
|
+
} catch (err) {
|
|
103
|
+
console.error(`Error fetching recurring payment agreement information in the GOV.UK API service - agreementId: ${agreementId}`, err)
|
|
104
|
+
throw err
|
|
105
|
+
}
|
|
106
|
+
}
|