@defra-fish/connectors-lib 1.63.0-rc.5 → 1.63.0-rc.6

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.63.0-rc.5",
3
+ "version": "1.63.0-rc.6",
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": "313d1d1a8ab65bd841c27cf615f8abeec527f401"
49
+ "gitHead": "bb4bf03e0fdf3e8c04b00a1bf10b844475796434"
50
50
  }
@@ -746,4 +746,44 @@ describe('sales-api-connector', () => {
746
746
  await expect(salesApi.cancelRecurringPayment('id')).rejects.toThrow('Internal Server Error')
747
747
  })
748
748
  })
749
+
750
+ describe('retrieveStagedTransaction', () => {
751
+ describe.each([['id'], ['abc-123']])("Retrieving staged transaction id '%s'", id => {
752
+ beforeEach(() => {
753
+ fetch.mockReturnValue({
754
+ ok: true,
755
+ status: 200,
756
+ statusText: 'OK',
757
+ text: async () => JSON.stringify({ id })
758
+ })
759
+ })
760
+
761
+ it('calls the endpoint with the correct parameters', async () => {
762
+ await salesApi.retrieveStagedTransaction(id)
763
+
764
+ expect(fetch).toHaveBeenCalledWith(`http://0.0.0.0:4000/retrieveStagedTransaction/${id}`, {
765
+ method: 'get',
766
+ headers: expect.any(Object),
767
+ timeout: 20000
768
+ })
769
+ })
770
+
771
+ it('returns the expected response data', async () => {
772
+ const processedResult = await salesApi.retrieveStagedTransaction(id)
773
+
774
+ expect(processedResult).toEqual({ id })
775
+ })
776
+ })
777
+
778
+ it('throws an error on non-2xx response', async () => {
779
+ fetch.mockReturnValue({
780
+ ok: false,
781
+ status: 500,
782
+ statusText: 'Internal Server Error',
783
+ text: async () => 'Server Error'
784
+ })
785
+
786
+ await expect(salesApi.retrieveStagedTransaction('id')).rejects.toThrow('Internal Server Error')
787
+ })
788
+ })
749
789
  })
@@ -319,3 +319,14 @@ export const processRPResult = async (transactionId, paymentId, createdDate) =>
319
319
  export const cancelRecurringPayment = async id => {
320
320
  return exec2xxOrThrow(call(new URL(`/cancelRecurringPayment/${id}`, urlBase), 'get'))
321
321
  }
322
+
323
+ /**
324
+ * Retrieve a staged transaction
325
+ *
326
+ * @param id
327
+ * @returns {Promise<*>}
328
+ * @throws on a non-2xx response
329
+ */
330
+ export const retrieveStagedTransaction = async id => {
331
+ return exec2xxOrThrow(call(new URL(`/retrieveStagedTransaction/${id}`, urlBase), 'get'))
332
+ }