@defra-fish/sales-api-service 1.72.0-rc.0 → 1.72.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/sales-api-service",
|
|
3
|
-
"version": "1.72.0-rc.
|
|
3
|
+
"version": "1.72.0-rc.1",
|
|
4
4
|
"description": "Rod Licensing Sales API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -35,9 +35,9 @@
|
|
|
35
35
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@defra-fish/business-rules-lib": "1.72.0-rc.
|
|
39
|
-
"@defra-fish/connectors-lib": "1.72.0-rc.
|
|
40
|
-
"@defra-fish/dynamics-lib": "1.72.0-rc.
|
|
38
|
+
"@defra-fish/business-rules-lib": "1.72.0-rc.1",
|
|
39
|
+
"@defra-fish/connectors-lib": "1.72.0-rc.1",
|
|
40
|
+
"@defra-fish/dynamics-lib": "1.72.0-rc.1",
|
|
41
41
|
"@hapi/boom": "9.1.2",
|
|
42
42
|
"@hapi/hapi": "20.1.3",
|
|
43
43
|
"@hapi/inert": "6.0.3",
|
|
@@ -52,5 +52,5 @@
|
|
|
52
52
|
"moment-timezone": "0.5.34",
|
|
53
53
|
"uuid": "8.3.2"
|
|
54
54
|
},
|
|
55
|
-
"gitHead": "
|
|
55
|
+
"gitHead": "17e9924e8f43184ad41ef0387c4e117511822447"
|
|
56
56
|
}
|
|
@@ -185,7 +185,7 @@ describe('preparePermissionDataForRenewal', () => {
|
|
|
185
185
|
|
|
186
186
|
describe('Senior', () => {
|
|
187
187
|
describe('addSenior', () => {
|
|
188
|
-
it('
|
|
188
|
+
it('adds a senior concession', async () => {
|
|
189
189
|
const permission = getMockPermission()
|
|
190
190
|
await concessionService.addSenior(permission)
|
|
191
191
|
expect(permission.concessions).toContainEqual(getSeniorConcession())
|
|
@@ -199,21 +199,29 @@ describe('preparePermissionDataForRenewal', () => {
|
|
|
199
199
|
expect(permission.concessions).toEqual([expect.objectContaining(seniorConcession)])
|
|
200
200
|
})
|
|
201
201
|
|
|
202
|
-
it('
|
|
202
|
+
it('adds a senior concession and keeps existing Blue Badge concession', async () => {
|
|
203
203
|
const permission = getMockPermission()
|
|
204
|
-
const disabledConcession =
|
|
204
|
+
const disabledConcession = getDisabledBlueBadgeConcession()
|
|
205
205
|
permission.concessions = [disabledConcession]
|
|
206
206
|
await concessionService.addSenior(permission)
|
|
207
207
|
expect(permission.concessions).toEqual([disabledConcession, getSeniorConcession()])
|
|
208
208
|
})
|
|
209
209
|
|
|
210
|
-
it('
|
|
210
|
+
it('adds a senior concession and keeps existing NI concession', async () => {
|
|
211
211
|
const permission = getMockPermission()
|
|
212
|
-
const disabledConcession =
|
|
212
|
+
const disabledConcession = getDisabledNiConcession()
|
|
213
213
|
permission.concessions = [disabledConcession]
|
|
214
214
|
await concessionService.addSenior(permission)
|
|
215
215
|
expect(permission.concessions).toEqual([disabledConcession, getSeniorConcession()])
|
|
216
216
|
})
|
|
217
|
+
|
|
218
|
+
it('removes any existing junior concession', async () => {
|
|
219
|
+
const permission = getMockPermission()
|
|
220
|
+
const juniorConcession = getJuniorConcession()
|
|
221
|
+
permission.concessions = [juniorConcession]
|
|
222
|
+
await concessionService.addSenior(permission)
|
|
223
|
+
expect(permission.concessions).toEqual([getSeniorConcession()])
|
|
224
|
+
})
|
|
217
225
|
})
|
|
218
226
|
|
|
219
227
|
describe('removeSenior', () => {
|
|
@@ -265,6 +273,46 @@ describe('preparePermissionDataForRenewal', () => {
|
|
|
265
273
|
})
|
|
266
274
|
|
|
267
275
|
describe('Junior', () => {
|
|
276
|
+
describe('addJunior', () => {
|
|
277
|
+
it('adds a junior concession', async () => {
|
|
278
|
+
const permission = getMockPermission()
|
|
279
|
+
await concessionService.addJunior(permission)
|
|
280
|
+
expect(permission.concessions).toContainEqual(getJuniorConcession())
|
|
281
|
+
})
|
|
282
|
+
|
|
283
|
+
it("doesn't add second junior concession if one's already present", async () => {
|
|
284
|
+
const juniorConcession = getJuniorConcession()
|
|
285
|
+
const permission = getMockPermission()
|
|
286
|
+
permission.concessions = [juniorConcession]
|
|
287
|
+
await concessionService.addJunior(permission)
|
|
288
|
+
expect(permission.concessions).toEqual([expect.objectContaining(juniorConcession)])
|
|
289
|
+
})
|
|
290
|
+
|
|
291
|
+
it('adds a junior concession and keeps existing Blue Badge concession', async () => {
|
|
292
|
+
const permission = getMockPermission()
|
|
293
|
+
const disabledConcession = getDisabledBlueBadgeConcession()
|
|
294
|
+
permission.concessions = [disabledConcession]
|
|
295
|
+
await concessionService.addJunior(permission)
|
|
296
|
+
expect(permission.concessions).toEqual([disabledConcession, getJuniorConcession()])
|
|
297
|
+
})
|
|
298
|
+
|
|
299
|
+
it('adds a junior concession and keeps existing NI concession', async () => {
|
|
300
|
+
const permission = getMockPermission()
|
|
301
|
+
const disabledConcession = getDisabledNiConcession()
|
|
302
|
+
permission.concessions = [disabledConcession]
|
|
303
|
+
await concessionService.addJunior(permission)
|
|
304
|
+
expect(permission.concessions).toEqual([disabledConcession, getJuniorConcession()])
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
it('removes any existing senior concession', async () => {
|
|
308
|
+
const permission = getMockPermission()
|
|
309
|
+
const seniorConcession = getSeniorConcession()
|
|
310
|
+
permission.concessions = [seniorConcession]
|
|
311
|
+
await concessionService.addJunior(permission)
|
|
312
|
+
expect(permission.concessions).toEqual([getJuniorConcession()])
|
|
313
|
+
})
|
|
314
|
+
})
|
|
315
|
+
|
|
268
316
|
describe('removeJunior', () => {
|
|
269
317
|
it.each([
|
|
270
318
|
['has only a junior concession', [getJuniorConcession()], []],
|
|
@@ -57,5 +57,21 @@ export const addSenior = async permission => {
|
|
|
57
57
|
export const removeSenior = permission => removeConcessionType(permission, CONCESSION.SENIOR)
|
|
58
58
|
export const hasSenior = permission => hasConcessionType(permission, CONCESSION.SENIOR)
|
|
59
59
|
|
|
60
|
+
export const addJunior = async permission => {
|
|
61
|
+
if (!(await hasJunior(permission))) {
|
|
62
|
+
await removeSenior(permission)
|
|
63
|
+
if (!permission.concessions) {
|
|
64
|
+
permission.concessions = []
|
|
65
|
+
}
|
|
66
|
+
permission.concessions.push({
|
|
67
|
+
id: await getTypeConcessionId(CONCESSION.JUNIOR),
|
|
68
|
+
name: CONCESSION.JUNIOR,
|
|
69
|
+
proof: {
|
|
70
|
+
type: CONCESSION_PROOF.none
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
60
76
|
export const removeJunior = permission => removeConcessionType(permission, CONCESSION.JUNIOR)
|
|
61
77
|
export const hasJunior = permission => hasConcessionType(permission, CONCESSION.JUNIOR)
|
|
@@ -204,6 +204,138 @@ describe('preparePermissionDataForRenewal', () => {
|
|
|
204
204
|
const preparedPermission = await preparePermissionDataForRenewal(permission)
|
|
205
205
|
expect(preparedPermission.concessions).toEqual(expect.arrayContaining([expect.objectContaining(disabledConcession)]))
|
|
206
206
|
})
|
|
207
|
+
|
|
208
|
+
it('should remove incorrect senior concession if the licensee is not a senior', async () => {
|
|
209
|
+
const senior = { name: 'Senior', id: 'd0ece997-ef65-e611-80dc-c4346bad4004', proof: { type: 'No Proof' } }
|
|
210
|
+
const notReallyASeniorPermission = existingPermission({
|
|
211
|
+
concessions: [senior]
|
|
212
|
+
})
|
|
213
|
+
const ppd = await preparePermissionDataForRenewal(notReallyASeniorPermission)
|
|
214
|
+
expect(ppd.concessions).toEqual([])
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
it('should remove incorrect senior concession but keep disabled concession if the licensee is disabled but is not a senior', async () => {
|
|
218
|
+
const senior = { name: 'Senior', id: 'd0ece997-ef65-e611-80dc-c4346bad4004', proof: { type: 'No Proof' } }
|
|
219
|
+
const disabled = {
|
|
220
|
+
name: 'Disabled',
|
|
221
|
+
id: 'd1ece997-ef65-e611-80dc-c4346bad4004',
|
|
222
|
+
proof: { type: 'Blue Badge', referenceNumber: '123' }
|
|
223
|
+
}
|
|
224
|
+
const notReallyASeniorPermission = existingPermission({
|
|
225
|
+
concessions: [senior, disabled]
|
|
226
|
+
})
|
|
227
|
+
const ppd = await preparePermissionDataForRenewal(notReallyASeniorPermission)
|
|
228
|
+
expect(ppd.concessions).toEqual([disabled])
|
|
229
|
+
})
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
describe('junior to adult transition', () => {
|
|
233
|
+
describe.each`
|
|
234
|
+
description | birthDate | oldEndDate
|
|
235
|
+
${'the user is renewing at age 14 with a licence that will expire while they are 14'} | ${'2012-01-01'} | ${'2026-04-15'}
|
|
236
|
+
${'the user is renewing at age 14 with a licence that expires today'} | ${'2012-01-01'} | ${'2026-04-01'}
|
|
237
|
+
${'the user is renewing at age 14 with a licence that expired while they were 14'} | ${'2012-01-01'} | ${'2026-03-31'}
|
|
238
|
+
${'the user is renewing at age 16 with a licence that will expire while they are 16'} | ${'2010-01-01'} | ${'2026-04-15'}
|
|
239
|
+
${'the user is renewing at age 16 with a licence that expires today'} | ${'2010-01-01'} | ${'2026-04-01'}
|
|
240
|
+
${'the user is renewing at age 16 with a licence that expired while they were 16'} | ${'2010-01-01'} | ${'2026-03-31'}
|
|
241
|
+
${'the user is renewing the day before their 17th birthday with a licence that expired yesterday'} | ${'2009-04-02'} | ${'2026-03-31'}
|
|
242
|
+
${'the user is renewing the day before their 17th birthday with a licence that expires today'} | ${'2009-04-02'} | ${'2026-04-01'}
|
|
243
|
+
${'the user is renewing at age 16 with a licence that will expire the day before their 17th birthday'} | ${'2009-04-15'} | ${'2026-04-14'}
|
|
244
|
+
`('expected junior licenses', ({ description, birthDate, oldEndDate }) => {
|
|
245
|
+
it(`should keep junior concession if ${description}`, async () => {
|
|
246
|
+
jest.useFakeTimers().setSystemTime(new Date('2026-04-01'))
|
|
247
|
+
const endDate = moment(oldEndDate)
|
|
248
|
+
const junior = { name: 'Junior', id: '3230c68f-ef65-e611-80dc-c4346bad4004', proof: { type: 'No Proof' } }
|
|
249
|
+
const stillJuniorPermission = existingPermission({
|
|
250
|
+
endDate,
|
|
251
|
+
licensee: {
|
|
252
|
+
...existingPermission().licensee,
|
|
253
|
+
birthDate
|
|
254
|
+
},
|
|
255
|
+
concessions: [junior]
|
|
256
|
+
})
|
|
257
|
+
|
|
258
|
+
const ppd = await preparePermissionDataForRenewal(stillJuniorPermission)
|
|
259
|
+
expect(ppd.concessions[0]).toEqual(junior)
|
|
260
|
+
jest.useRealTimers()
|
|
261
|
+
})
|
|
262
|
+
|
|
263
|
+
it(`should keep existing disabled concession and add junior concession if ${description}`, async () => {
|
|
264
|
+
jest.useFakeTimers().setSystemTime(new Date('2026-04-01'))
|
|
265
|
+
const endDate = moment(oldEndDate)
|
|
266
|
+
const junior = { name: 'Junior', id: '3230c68f-ef65-e611-80dc-c4346bad4004', proof: { type: 'No Proof' } }
|
|
267
|
+
const disabled = {
|
|
268
|
+
name: 'Disabled',
|
|
269
|
+
id: 'd1ece997-ef65-e611-80dc-c4346bad4004',
|
|
270
|
+
proof: { type: 'Blue Badge', referenceNumber: '123' }
|
|
271
|
+
}
|
|
272
|
+
const stillJuniorPermission = existingPermission({
|
|
273
|
+
endDate,
|
|
274
|
+
licensee: {
|
|
275
|
+
...existingPermission().licensee,
|
|
276
|
+
birthDate
|
|
277
|
+
},
|
|
278
|
+
concessions: [disabled]
|
|
279
|
+
})
|
|
280
|
+
|
|
281
|
+
const ppd = await preparePermissionDataForRenewal(stillJuniorPermission)
|
|
282
|
+
expect(ppd.concessions).toEqual([disabled, junior])
|
|
283
|
+
jest.useRealTimers()
|
|
284
|
+
})
|
|
285
|
+
})
|
|
286
|
+
|
|
287
|
+
describe.each`
|
|
288
|
+
description | birthDate | oldEndDate
|
|
289
|
+
${'the user is renewing at age 16 with a licence that will expire on their 17th birthday'} | ${'2009-04-10'} | ${'2026-04-10'}
|
|
290
|
+
${'the user is renewing at age 16 with a licence that will expire the day after their 17th birthday'} | ${'2009-04-10'} | ${'2026-04-11'}
|
|
291
|
+
${'the user is renewing on the day of their 17th birthday a licence that expired yesterday'} | ${'2009-04-01'} | ${'2026-03-31'}
|
|
292
|
+
${'the user is renewing on the day of their 17th birthday a licence that expires today'} | ${'2009-04-01'} | ${'2026-04-01'}
|
|
293
|
+
${'the user is renewing on the day of their 17th birthday with a licence that expired a week ago'} | ${'2009-04-01'} | ${'2026-03-25'}
|
|
294
|
+
${'the user is renewing the day after their 17th birthday a licence that expired the day before their birthday'} | ${'2009-03-31'} | ${'2026-03-30'}
|
|
295
|
+
${'the user is renewing the day after their 17th birthday a licence that expired on their birthday'} | ${'2009-03-31'} | ${'2026-03-31'}
|
|
296
|
+
${'the user is renewing the day after their 17th birthday a licence that expires today'} | ${'2009-03-31'} | ${'2026-04-01'}
|
|
297
|
+
${'the user is renewing the day after their 17th birthday with a licence that expired a week ago'} | ${'2009-03-31'} | ${'2026-03-25'}
|
|
298
|
+
`('expected junior licenses', ({ description, birthDate, oldEndDate }) => {
|
|
299
|
+
it(`should remove junior concession if ${description}`, async () => {
|
|
300
|
+
jest.useFakeTimers().setSystemTime(new Date('2026-04-01'))
|
|
301
|
+
const endDate = moment(oldEndDate)
|
|
302
|
+
const junior = { name: 'Junior', id: '3230c68f-ef65-e611-80dc-c4346bad4004', proof: { type: 'No Proof' } }
|
|
303
|
+
const nowAdultPermission = existingPermission({
|
|
304
|
+
endDate,
|
|
305
|
+
licensee: {
|
|
306
|
+
...existingPermission().licensee,
|
|
307
|
+
birthDate
|
|
308
|
+
},
|
|
309
|
+
concessions: [junior]
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
const ppd = await preparePermissionDataForRenewal(nowAdultPermission)
|
|
313
|
+
expect(ppd.concessions).toEqual([])
|
|
314
|
+
jest.useRealTimers()
|
|
315
|
+
})
|
|
316
|
+
|
|
317
|
+
it(`should keep disabled concession and not add junior concession if ${description}`, async () => {
|
|
318
|
+
jest.useFakeTimers().setSystemTime(new Date('2026-04-01'))
|
|
319
|
+
const endDate = moment(oldEndDate)
|
|
320
|
+
const disabled = {
|
|
321
|
+
name: 'Disabled',
|
|
322
|
+
id: 'd1ece997-ef65-e611-80dc-c4346bad4004',
|
|
323
|
+
proof: { type: 'Blue Badge', referenceNumber: '123' }
|
|
324
|
+
}
|
|
325
|
+
const nowAdultPermission = existingPermission({
|
|
326
|
+
endDate,
|
|
327
|
+
licensee: {
|
|
328
|
+
...existingPermission().licensee,
|
|
329
|
+
birthDate
|
|
330
|
+
},
|
|
331
|
+
concessions: [disabled]
|
|
332
|
+
})
|
|
333
|
+
|
|
334
|
+
const ppd = await preparePermissionDataForRenewal(nowAdultPermission)
|
|
335
|
+
expect(ppd.concessions).toEqual([disabled])
|
|
336
|
+
jest.useRealTimers()
|
|
337
|
+
})
|
|
338
|
+
})
|
|
207
339
|
})
|
|
208
340
|
|
|
209
341
|
describe('preparePermit', () => {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { isSenior, SERVICE_LOCAL_TIME } from '@defra-fish/business-rules-lib'
|
|
1
|
+
import { isJunior, isSenior, SERVICE_LOCAL_TIME } from '@defra-fish/business-rules-lib'
|
|
2
2
|
import moment from 'moment-timezone'
|
|
3
|
-
import { addSenior } from '../concession.service.js'
|
|
3
|
+
import { addJunior, addSenior, removeJunior, removeSenior } from '../concession.service.js'
|
|
4
4
|
import { findPermit } from '../permit.service.js'
|
|
5
5
|
|
|
6
6
|
// Replicated from GAFL - need to decide whether to move
|
|
@@ -101,6 +101,11 @@ const prepareConcessionsData = async (existingPermission, dateData) => {
|
|
|
101
101
|
|
|
102
102
|
if (isSenior(ageAtLicenceStartDate)) {
|
|
103
103
|
await addSenior(existingPermission)
|
|
104
|
+
} else if (isJunior(ageAtLicenceStartDate)) {
|
|
105
|
+
await addJunior(existingPermission)
|
|
106
|
+
} else {
|
|
107
|
+
await removeJunior(existingPermission)
|
|
108
|
+
await removeSenior(existingPermission)
|
|
104
109
|
}
|
|
105
110
|
|
|
106
111
|
return existingPermission.concessions
|