From a03b51307f906c19d1aecc9526c8e1fca904a503 Mon Sep 17 00:00:00 2001 From: Iris Faraway Date: Fri, 6 Dec 2024 15:11:11 +0000 Subject: [PATCH] Rename createRecurringPayment to clarify it creates agreements (#2082) https://eaflood.atlassian.net/browse/IWTF-4373 Since the actual payments are created using the usual createPayment function, just with recurring as true. --- .../src/__tests__/govuk-pay-api.spec.js | 6 +++--- packages/connectors-lib/src/govuk-pay-api.js | 2 +- .../payment/__test__/govuk-pay-service.spec.js | 16 ++++++++-------- .../src/services/payment/govuk-pay-service.js | 6 +++--- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/packages/connectors-lib/src/__tests__/govuk-pay-api.spec.js b/packages/connectors-lib/src/__tests__/govuk-pay-api.spec.js index 43f4b3e08..4c1832c70 100644 --- a/packages/connectors-lib/src/__tests__/govuk-pay-api.spec.js +++ b/packages/connectors-lib/src/__tests__/govuk-pay-api.spec.js @@ -120,10 +120,10 @@ describe('govuk-pay-api-connector', () => { }) }) - describe('createRecurringPayment', () => { + describe('createRecurringPaymentAgreement', () => { it('creates new payments', async () => { fetch.mockReturnValue({ ok: true, status: 200 }) - await expect(govUkPayApi.createRecurringPayment({ cost: 0 })).resolves.toEqual({ ok: true, status: 200 }) + await expect(govUkPayApi.createRecurringPaymentAgreement({ cost: 0 })).resolves.toEqual({ ok: true, status: 200 }) expect(fetch).toHaveBeenCalledWith('http://0.0.0.0/agreement', { body: JSON.stringify({ cost: 0 }), headers: recurringHeaders, @@ -137,7 +137,7 @@ describe('govuk-pay-api-connector', () => { fetch.mockImplementation(() => { throw new Error('') }) - expect(govUkPayApi.createRecurringPayment({ reference: '123' })).rejects.toEqual(Error('')) + expect(govUkPayApi.createRecurringPaymentAgreement({ reference: '123' })).rejects.toEqual(Error('')) expect(fetch).toHaveBeenCalledWith('http://0.0.0.0/agreement', { body: JSON.stringify({ reference: '123' }), headers: recurringHeaders, diff --git a/packages/connectors-lib/src/govuk-pay-api.js b/packages/connectors-lib/src/govuk-pay-api.js index 16657c213..b3295dec3 100644 --- a/packages/connectors-lib/src/govuk-pay-api.js +++ b/packages/connectors-lib/src/govuk-pay-api.js @@ -15,7 +15,7 @@ const headers = recurring => ({ * @param preparedPayment - see the GOV.UK pay API reference for details * @returns {Promise<*>} */ -export const createRecurringPayment = async preparedPayment => { +export const createRecurringPaymentAgreement = async preparedPayment => { try { return fetch(process.env.GOV_PAY_RCP_API_URL, { headers: headers(true), diff --git a/packages/gafl-webapp-service/src/services/payment/__test__/govuk-pay-service.spec.js b/packages/gafl-webapp-service/src/services/payment/__test__/govuk-pay-service.spec.js index ac995d1b2..c027790bc 100644 --- a/packages/gafl-webapp-service/src/services/payment/__test__/govuk-pay-service.spec.js +++ b/packages/gafl-webapp-service/src/services/payment/__test__/govuk-pay-service.spec.js @@ -309,7 +309,7 @@ describe('The govuk-pay-service', () => { ok: true, json: jest.fn().mockResolvedValue({ success: true, paymentId: 'abc123' }) } - govUkPayApi.createRecurringPayment.mockResolvedValue(mockResponse) + govUkPayApi.createRecurringPaymentAgreement.mockResolvedValue(mockResponse) const unique = Symbol('payload') const payload = { reference: 'd81f1a2b-6508-468f-8342-b6770f60f7cd', @@ -318,7 +318,7 @@ describe('The govuk-pay-service', () => { unique } await sendRecurringPayment(payload) - expect(govUkPayApi.createRecurringPayment).toHaveBeenCalledWith(payload) + expect(govUkPayApi.createRecurringPaymentAgreement).toHaveBeenCalledWith(payload) }) it('should return response body when payment creation is successful', async () => { @@ -326,7 +326,7 @@ describe('The govuk-pay-service', () => { ok: true, json: jest.fn().mockResolvedValue({ success: true, paymentId: 'abc123' }) } - govUkPayApi.createRecurringPayment.mockResolvedValue(mockResponse) + govUkPayApi.createRecurringPaymentAgreement.mockResolvedValue(mockResponse) const result = await sendRecurringPayment(preparedPayment) @@ -338,7 +338,7 @@ describe('The govuk-pay-service', () => { ok: true, json: jest.fn().mockResolvedValue({ success: true, paymentId: 'abc123' }) } - govUkPayApi.createRecurringPayment.mockResolvedValue(mockResponse) + govUkPayApi.createRecurringPaymentAgreement.mockResolvedValue(mockResponse) await sendRecurringPayment(preparedPayment) @@ -352,7 +352,7 @@ describe('The govuk-pay-service', () => { json: jest.fn().mockResolvedValue({ message: 'Server error' }) } const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(() => {}) - govUkPayApi.createRecurringPayment.mockResolvedValue(mockResponse) + govUkPayApi.createRecurringPaymentAgreement.mockResolvedValue(mockResponse) try { await sendRecurringPayment(preparedPayment) @@ -370,7 +370,7 @@ describe('The govuk-pay-service', () => { it('should throw error when API call fails with network issue', async () => { const mockError = new Error('Network error') const consoleErrorSpy = jest.spyOn(console, 'error').mockImplementation(jest.fn()) - govUkPayApi.createRecurringPayment.mockRejectedValue(mockError) + govUkPayApi.createRecurringPaymentAgreement.mockRejectedValue(mockError) try { await sendRecurringPayment(preparedPayment) @@ -389,7 +389,7 @@ describe('The govuk-pay-service', () => { json: jest.fn().mockResolvedValue({ message: 'Rate limit exceeded' }) } const consoleErrorSpy = jest.spyOn(console, 'info').mockImplementation(jest.fn()) - govUkPayApi.createRecurringPayment.mockResolvedValue(mockResponse) + govUkPayApi.createRecurringPaymentAgreement.mockResolvedValue(mockResponse) try { await sendRecurringPayment(preparedPayment) @@ -404,7 +404,7 @@ describe('The govuk-pay-service', () => { status: 500, json: jest.fn().mockResolvedValue({ message: 'Server error' }) } - govUkPayApi.createRecurringPayment.mockResolvedValue(mockResponse) + govUkPayApi.createRecurringPaymentAgreement.mockResolvedValue(mockResponse) try { await sendRecurringPayment(preparedPayment) diff --git a/packages/gafl-webapp-service/src/services/payment/govuk-pay-service.js b/packages/gafl-webapp-service/src/services/payment/govuk-pay-service.js index 80bedb845..ee150457d 100644 --- a/packages/gafl-webapp-service/src/services/payment/govuk-pay-service.js +++ b/packages/gafl-webapp-service/src/services/payment/govuk-pay-service.js @@ -109,9 +109,9 @@ export const getPaymentStatus = async (paymentId, recurring = false) => { } } -const createRecurringPayment = async preparedPayment => { +const createRecurringPaymentAgreement = async preparedPayment => { try { - return await govUkPayApi.createRecurringPayment(preparedPayment) + return await govUkPayApi.createRecurringPaymentAgreement(preparedPayment) } catch (err) { /* * Potentially errors caught here (unreachable, timeouts) may be retried - set origin on the error to indicate @@ -122,7 +122,7 @@ const createRecurringPayment = async preparedPayment => { } export const sendRecurringPayment = async preparedPayment => { - const response = await createRecurringPayment(preparedPayment) + const response = await createRecurringPaymentAgreement(preparedPayment) if (response.ok) { const resBody = await response.json()