@defra-fish/connectors-lib 1.62.0-rc.1 → 1.62.0-rc.2

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.1",
3
+ "version": "1.62.0-rc.2",
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": "89028907ee2ee612a0126fb9b7857791c2e9563d"
49
+ "gitHead": "6a3a2c6a81067424144382557214c49c27559cdf"
50
50
  }
@@ -706,4 +706,44 @@ describe('sales-api-connector', () => {
706
706
  })
707
707
  })
708
708
  })
709
+
710
+ describe('cancelRecurringPayment', () => {
711
+ describe.each([['id'], ['abc-123']])("Cancelling recurring payment id '%s'", id => {
712
+ beforeEach(() => {
713
+ fetch.mockReturnValue({
714
+ ok: true,
715
+ status: 200,
716
+ statusText: 'OK',
717
+ text: async () => JSON.stringify({ id })
718
+ })
719
+ })
720
+
721
+ it('calls the endpoint with the correct parameters', async () => {
722
+ await salesApi.cancelRecurringPayment(id)
723
+
724
+ expect(fetch).toHaveBeenCalledWith(`http://0.0.0.0:4000/cancelRecurringPayment/${id}`, {
725
+ method: 'get',
726
+ headers: expect.any(Object),
727
+ timeout: 20000
728
+ })
729
+ })
730
+
731
+ it('returns the expected response data', async () => {
732
+ const processedResult = await salesApi.cancelRecurringPayment(id)
733
+
734
+ expect(processedResult).toEqual({ id })
735
+ })
736
+ })
737
+
738
+ it('throws an error on non-2xx response', async () => {
739
+ fetch.mockReturnValue({
740
+ ok: false,
741
+ status: 500,
742
+ statusText: 'Internal Server Error',
743
+ text: async () => 'Server Error'
744
+ })
745
+
746
+ await expect(salesApi.cancelRecurringPayment('id')).rejects.toThrow('Internal Server Error')
747
+ })
748
+ })
709
749
  })
@@ -308,3 +308,14 @@ export const preparePermissionDataForRenewal = async referenceNumber =>
308
308
  export const processRPResult = async (transactionId, paymentId, createdDate) => {
309
309
  return exec2xxOrThrow(call(new URL(`/processRPResult/${transactionId}/${paymentId}/${createdDate}`, urlBase), 'get'))
310
310
  }
311
+
312
+ /**
313
+ * Cancel a RecurringPayment
314
+ *
315
+ * @param id
316
+ * @returns {Promise<*>}
317
+ * @throws on a non-2xx response
318
+ */
319
+ export const cancelRecurringPayment = async id => {
320
+ return exec2xxOrThrow(call(new URL(`/cancelRecurringPayment/${id}`, urlBase), 'get'))
321
+ }