@defra-fish/connectors-lib 1.64.0-rc.8 → 1.65.0-rc.0

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.64.0-rc.8",
3
+ "version": "1.65.0-rc.0",
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": "88a60cab95e119b46cec17336d784aec1aeabae8"
49
+ "gitHead": "cdf9253964871c4afe0ff85d085364ffe4e890cf"
50
50
  }
@@ -821,103 +821,38 @@ describe('sales-api-connector', () => {
821
821
  await expect(salesApi.retrieveStagedTransaction('id')).rejects.toThrow('Internal Server Error')
822
822
  })
823
823
  })
824
+ })
824
825
 
825
- describe('retrieveRecurringPaymentAgreement', () => {
826
- describe.each([['id'], ['abc-123']])("Retrieving recurring payment agreement id '%s'", agreementId => {
827
- beforeEach(() => {
828
- fetch.mockReturnValueOnce({
829
- ok: true,
830
- status: 200,
831
- statusText: 'OK',
832
- text: async () => JSON.stringify({ agreementId })
833
- })
834
- })
835
-
836
- it('calls the endpoint with the correct parameters', async () => {
837
- await salesApi.retrieveRecurringPaymentAgreement(agreementId)
838
-
839
- expect(fetch).toHaveBeenCalledWith(`http://0.0.0.0:4000/retrieveRecurringPaymentAgreement/${agreementId}`, {
840
- method: 'get',
841
- headers: expect.any(Object),
842
- timeout: 20000
843
- })
844
- })
845
-
846
- it('returns the expected response data', async () => {
847
- const processedResult = await salesApi.retrieveRecurringPaymentAgreement(agreementId)
848
-
849
- expect(processedResult).toEqual({ agreementId })
850
- })
851
- })
852
-
853
- it('throws an error on non-2xx response', async () => {
854
- fetch.mockReturnValueOnce({
855
- ok: false,
856
- status: 500,
857
- statusText: 'Internal Server Error',
858
- text: async () => 'Server Error'
859
- })
860
-
861
- await expect(salesApi.retrieveRecurringPaymentAgreement('agreementId')).rejects.toThrow('Internal Server Error')
862
- })
826
+ describe('rcp authentication', () => {
827
+ it('returns parsed JSON with successful fetch', async () => {
828
+ const expectedResponse = { woo: 'hoo' }
829
+ fetch.mockReturnValueOnce({ ok: true, status: 200, statusText: 'OK', text: async () => JSON.stringify(expectedResponse) })
830
+ const response = await salesApi.authenticateRecurringPayment('AAAAAA', '1980-03-02', 'BS9 4PT')
831
+ expect(response).toEqual(expectedResponse)
863
832
  })
864
833
 
865
- describe('updateRecurringTransaction', () => {
866
- it.each([['Debit card'], ['Credit card']])('updates the transaction with payment method "%s"', async method => {
867
- const transactionId = 'transaction-id'
868
- const payload = {
869
- payment: {
870
- source: 'Gov Pay',
871
- method
872
- }
873
- }
874
- const expectedResponse = { id: transactionId, ...payload }
875
-
876
- fetch.mockReturnValueOnce({
877
- ok: true,
878
- status: 200,
879
- statusText: 'OK',
880
- text: async () => JSON.stringify(expectedResponse)
881
- })
882
-
883
- await expect(salesApi.updateRecurringTransaction(transactionId, payload)).resolves.toEqual(expectedResponse)
884
-
885
- expect(fetch).toHaveBeenCalledWith(
886
- `http://0.0.0.0:4000/update-recurring-transactions/${transactionId}`,
887
- expect.objectContaining({
888
- method: 'patch',
889
- body: JSON.stringify(payload)
890
- })
891
- )
892
- })
893
-
894
- it('throws on a non-ok response', async () => {
895
- const transactionId = 'transaction-id'
896
- const payload = {
897
- payment: {
898
- source: 'Gov Pay',
899
- method: 'Debit card'
900
- }
834
+ it('calls fetch with the RCP authenticate URL and query params', async () => {
835
+ const expectedResponse = { woo: 'hoo' }
836
+ fetch.mockReturnValueOnce({ ok: true, status: 200, statusText: 'OK', text: async () => JSON.stringify(expectedResponse) })
837
+ await salesApi.authenticateRecurringPayment('AAAAAA', '1980-03-02', 'BS9 4PT')
838
+ expect(fetch).toHaveBeenCalledWith(
839
+ 'http://0.0.0.0:4000/authenticate/rcp/AAAAAA?licenseeBirthDate=1980-03-02&licenseePostcode=BS9%204PT',
840
+ {
841
+ method: 'get',
842
+ headers: expect.any(Object),
843
+ timeout: 20000
901
844
  }
845
+ )
846
+ })
902
847
 
903
- fetch.mockReturnValueOnce({
904
- ok: false,
905
- status: 422,
906
- statusText: 'Unprocessable Entity',
907
- text: async () => JSON.stringify({ error: 'Description' })
908
- })
909
-
910
- await expect(salesApi.updateRecurringTransaction(transactionId, payload)).rejects.toThrow(
911
- /Unexpected response from the Sales API:.*"status": 422.*"statusText": "Unprocessable Entity"/s
912
- )
913
-
914
- expect(fetch).toHaveBeenCalledWith(
915
- `http://0.0.0.0:4000/update-recurring-transactions/${transactionId}`,
916
- expect.objectContaining({
917
- method: 'patch',
918
- body: JSON.stringify(payload)
919
- })
920
- )
848
+ it('returns null when the sales API responds with a non-2xx status', async () => {
849
+ fetch.mockReturnValueOnce({
850
+ ok: false,
851
+ status: 400,
852
+ statusText: 'Bad Request',
853
+ text: async () => 'Bad Request'
921
854
  })
855
+ const response = await salesApi.authenticateRecurringPayment('AAAAAA', '1980-03-02', 'BS9 4PT')
856
+ expect(response).toBeNull()
922
857
  })
923
858
  })
@@ -100,17 +100,6 @@ export const createTransactions = async transactionArr =>
100
100
  */
101
101
  export const finaliseTransaction = async (id, payload) => exec2xxOrThrow(call(new URL(`/transactions/${id}`, urlBase), 'patch', payload))
102
102
 
103
- /**
104
- * Update a transaction in the sales API
105
- *
106
- * @param id the transaction id to finalise
107
- * @param payload the update-transaction payload to supply on the request
108
- * @returns {Promise<*>}
109
- * @throws on a non-2xx response
110
- */
111
- export const updateRecurringTransaction = async (id, payload) =>
112
- exec2xxOrThrow(call(new URL(`/update-recurring-transactions/${id}`, urlBase), 'patch', payload))
113
-
114
103
  /**
115
104
  * Retrieve the details of a transaction file. Returns null if not found.
116
105
  *
@@ -280,6 +269,27 @@ export const authenticate = async (referenceNumber, birthDate, postcode) =>
280
269
  )
281
270
  )
282
271
 
272
+ /**
273
+ * Support for cancelling recurring payment authentication
274
+ * @param referenceNumber
275
+ * @param birthDate
276
+ * @param postcode
277
+ * @returns {Promise<*>}
278
+ */
279
+ export const authenticateRecurringPayment = (referenceNumber, birthDate, postcode) =>
280
+ exec2xxOrNull(
281
+ call(
282
+ new URL(
283
+ `/authenticate/rcp/${referenceNumber}?${querystring.stringify({
284
+ licenseeBirthDate: birthDate,
285
+ licenseePostcode: postcode
286
+ })}`,
287
+ urlBase
288
+ ),
289
+ 'get'
290
+ )
291
+ )
292
+
283
293
  /**
284
294
  * Helper to check if an HTTP status code is classed as a system error
285
295
  *
@@ -341,13 +351,3 @@ export const cancelRecurringPayment = async id => {
341
351
  export const retrieveStagedTransaction = async id => {
342
352
  return exec2xxOrThrow(call(new URL(`/retrieveStagedTransaction/${id}`, urlBase), 'get'))
343
353
  }
344
-
345
- /**
346
- * Retrieve recurring payment agreement details
347
- *
348
- * @param {string} agreementId
349
- * @returns {Promise<*>}
350
- * @throws on a non-2xx response
351
- */
352
- export const retrieveRecurringPaymentAgreement = async agreementId =>
353
- exec2xxOrThrow(call(new URL(`/retrieveRecurringPaymentAgreement/${agreementId}`, urlBase), 'get'))