@defra-fish/connectors-lib 1.64.0-rc.16 → 1.64.0-rc.18

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.16",
3
+ "version": "1.64.0-rc.18",
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": "b21258c7055fc45e86b641abdf6c9569cc5ffd8f"
49
+ "gitHead": "48839d8d5db2d4539974549a953a15e3305d46d8"
50
50
  }
@@ -822,3 +822,37 @@ describe('sales-api-connector', () => {
822
822
  })
823
823
  })
824
824
  })
825
+
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)
832
+ })
833
+
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
844
+ }
845
+ )
846
+ })
847
+
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'
854
+ })
855
+ const response = await salesApi.authenticateRecurringPayment('AAAAAA', '1980-03-02', 'BS9 4PT')
856
+ expect(response).toBeNull()
857
+ })
858
+ })
@@ -269,6 +269,27 @@ export const authenticate = async (referenceNumber, birthDate, postcode) =>
269
269
  )
270
270
  )
271
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
+
272
293
  /**
273
294
  * Helper to check if an HTTP status code is classed as a system error
274
295
  *