@defra-fish/connectors-lib 1.76.0 → 1.77.0-rc.1
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.
|
|
3
|
+
"version": "1.77.0-rc.1",
|
|
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": "
|
|
50
|
+
"gitHead": "2d2758c633c72fb22cd69fd5c9cbf0046568a9a9"
|
|
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', postcode: 'AB123CD' },
|
|
876
|
+
{ firstName: 'Bilbo', lastName: 'Baggins', birthDate: '1995-04-15', 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', postcode: 'AB123CD' },
|
|
886
|
+
expectedUrl:
|
|
887
|
+
'http://0.0.0.0:4000/licenceDetails?licenseeFirstName=Gandalf&licenseeLastName=Grey&licenseePostcode=AB123CD&licenseeBirthDate=2000-10-03'
|
|
888
|
+
},
|
|
889
|
+
{
|
|
890
|
+
input: { firstName: 'Bilbo', lastName: 'Baggins', birthDate: '1995-04-15', postcode: 'BS9 4PT' },
|
|
891
|
+
expectedUrl:
|
|
892
|
+
'http://0.0.0.0:4000/licenceDetails?licenseeFirstName=Bilbo&licenseeLastName=Baggins&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', postcode: 'AB123CD' })
|
|
914
|
+
).resolves.toBeNull()
|
|
915
|
+
})
|
|
916
|
+
})
|
|
@@ -351,3 +351,28 @@ 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} postcode
|
|
362
|
+
* @returns {Promise<*>}
|
|
363
|
+
*/
|
|
364
|
+
export const getLicenceDetails = async ({ firstName, lastName, birthDate, postcode }) =>
|
|
365
|
+
exec2xxOrNull(
|
|
366
|
+
call(
|
|
367
|
+
new URL(
|
|
368
|
+
`/licenceDetails?${querystring.stringify({
|
|
369
|
+
licenseeFirstName: firstName,
|
|
370
|
+
licenseeLastName: lastName,
|
|
371
|
+
licenseePostcode: postcode,
|
|
372
|
+
licenseeBirthDate: birthDate
|
|
373
|
+
})}`,
|
|
374
|
+
urlBase
|
|
375
|
+
),
|
|
376
|
+
'get'
|
|
377
|
+
)
|
|
378
|
+
)
|