@defra-fish/connectors-lib 1.76.0 → 1.77.0-rc.10

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.76.0",
3
+ "version": "1.77.0-rc.10",
4
4
  "description": "Shared connectors",
5
5
  "type": "module",
6
6
  "engines": {
@@ -47,5 +47,5 @@
47
47
  "node-fetch": "2.7.0",
48
48
  "redlock": "4.2.0"
49
49
  },
50
- "gitHead": "2287ca0defd4b61d66cbea6f0df84568265b036f"
50
+ "gitHead": "b41c703037390290c9403cafc2e0252ef63e149e"
51
51
  }
@@ -869,3 +869,48 @@ describe('rcp authentication', () => {
869
869
  expect(response).toBeNull()
870
870
  })
871
871
  })
872
+
873
+ describe('getLicenceDetails', () => {
874
+ it.each([
875
+ { firstName: 'Gandalf', lastName: 'Grey', birthDate: '2000-10-03', premises: '59', postcode: 'AB123CD' },
876
+ { firstName: 'Bilbo', lastName: 'Baggins', birthDate: '1995-04-15', premises: 'Bag End', postcode: 'BS9 4PT' }
877
+ ])('retrieves the licence details payload returned by the Sales API for %p', async licensee => {
878
+ const expectedResponse = { licences: [{ some: 'data' }] }
879
+ fetch.mockReturnValueOnce({ ok: true, status: 200, statusText: 'OK', text: async () => JSON.stringify(expectedResponse) })
880
+ await expect(salesApi.getLicenceDetails(licensee)).resolves.toEqual(expectedResponse)
881
+ })
882
+
883
+ it.each([
884
+ {
885
+ input: { firstName: 'Gandalf', lastName: 'Grey', birthDate: '2000-10-03', premises: '59', postcode: 'AB123CD' },
886
+ expectedUrl:
887
+ 'http://0.0.0.0:4000/licenceDetails?licenseeFirstName=Gandalf&licenseeLastName=Grey&licenseePremises=59&licenseePostcode=AB123CD&licenseeBirthDate=2000-10-03'
888
+ },
889
+ {
890
+ input: { firstName: 'Bilbo', lastName: 'Baggins', birthDate: '1995-04-15', premises: 'Bag End', postcode: 'BS9 4PT' },
891
+ expectedUrl:
892
+ 'http://0.0.0.0:4000/licenceDetails?licenseeFirstName=Bilbo&licenseeLastName=Baggins&licenseePremises=Bag%20End&licenseePostcode=BS9%204PT&licenseeBirthDate=1995-04-15'
893
+ }
894
+ ])('calls fetch with the name, postcode and date of birth as query parameters for %p', async ({ input, expectedUrl }) => {
895
+ fetch.mockReturnValueOnce({
896
+ ok: true,
897
+ status: 200,
898
+ statusText: 'OK',
899
+ text: async () => JSON.stringify({ licences: [] })
900
+ })
901
+ await salesApi.getLicenceDetails(input)
902
+ expect(fetch).toHaveBeenCalledWith(expectedUrl, expect.objectContaining({ method: 'get' }))
903
+ })
904
+
905
+ it('returns null if none found', async () => {
906
+ fetch.mockReturnValueOnce({
907
+ ok: false,
908
+ status: 404,
909
+ statusText: 'Not Found',
910
+ text: async () => JSON.stringify({ error: 'Description' })
911
+ })
912
+ await expect(
913
+ salesApi.getLicenceDetails({ firstName: 'Gandalf', lastName: 'Grey', birthDate: '2000-10-03', premises: '59', postcode: 'AB123CD' })
914
+ ).resolves.toBeNull()
915
+ })
916
+ })
@@ -351,3 +351,30 @@ export const cancelRecurringPayment = async (id, reason = 'Payment Failure') =>
351
351
  export const retrieveStagedTransaction = async id => {
352
352
  return exec2xxOrThrow(call(new URL(`/retrieveStagedTransaction/${id}`, urlBase), 'get'))
353
353
  }
354
+
355
+ /**
356
+ * Retrieve licence (or licences) details using name, post code and date of birth
357
+ *
358
+ * @param {string} firstName
359
+ * @param {string} lastName
360
+ * @param {string} birthDate
361
+ * @param {string} premises
362
+ * @param {string} postcode
363
+ * @returns {Promise<*>}
364
+ */
365
+ export const getLicenceDetails = async ({ firstName, lastName, birthDate, premises, postcode }) =>
366
+ exec2xxOrNull(
367
+ call(
368
+ new URL(
369
+ `/licenceDetails?${querystring.stringify({
370
+ licenseeFirstName: firstName,
371
+ licenseeLastName: lastName,
372
+ licenseePremises: premises,
373
+ licenseePostcode: postcode,
374
+ licenseeBirthDate: birthDate
375
+ })}`,
376
+ urlBase
377
+ ),
378
+ 'get'
379
+ )
380
+ )