@defra-fish/sales-api-service 1.68.0 → 1.69.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,10 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra-fish/sales-api-service",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.69.0-rc.0",
|
|
4
4
|
"description": "Rod Licensing Sales API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
7
|
-
"node": ">=
|
|
7
|
+
"node": ">=22"
|
|
8
8
|
},
|
|
9
9
|
"keywords": [
|
|
10
10
|
"rod",
|
|
@@ -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.
|
|
39
|
-
"@defra-fish/connectors-lib": "1.
|
|
40
|
-
"@defra-fish/dynamics-lib": "1.
|
|
38
|
+
"@defra-fish/business-rules-lib": "1.69.0-rc.0",
|
|
39
|
+
"@defra-fish/connectors-lib": "1.69.0-rc.0",
|
|
40
|
+
"@defra-fish/dynamics-lib": "1.69.0-rc.0",
|
|
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": "e9eb67926528361d45ad630df84da2ad47723b97"
|
|
56
56
|
}
|
|
@@ -58,40 +58,100 @@ describe('permissions service', () => {
|
|
|
58
58
|
beforeEach(jest.clearAllMocks)
|
|
59
59
|
|
|
60
60
|
describe('generatePermissionNumber', () => {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
61
|
+
describe('adult', () => {
|
|
62
|
+
it('generates a permission number for adults', async () => {
|
|
63
|
+
const number = await generatePermissionNumber(
|
|
64
|
+
getSamplePermission({
|
|
65
|
+
permitId: MOCK_12MONTH_DISABLED_PERMIT.id,
|
|
66
|
+
birthDate: moment()
|
|
67
|
+
.subtract(JUNIOR_MAX_AGE + 1, 'years')
|
|
68
|
+
.format('YYYY-MM-DD')
|
|
69
|
+
}),
|
|
70
|
+
'Telesales'
|
|
71
|
+
)
|
|
72
|
+
const block1 = moment().subtract(1, 'day').add(1, 'year').endOf('day').format('HHDDMMYY')
|
|
73
|
+
const expected = new RegExp(`^${block1}-1TS3FFT-[A-Z0-9]{5}[0-9]$`)
|
|
74
|
+
expect(number).toMatch(expected)
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
it('formats as F if startDate is on 17th birthday but issueDate is 1 week before', async () => {
|
|
78
|
+
const birthDate = moment().subtract(JUNIOR_MAX_AGE, 'years').format('YYYY-MM-DD')
|
|
79
|
+
const issueDate = moment(birthDate).add(JUNIOR_MAX_AGE, 'years').add(1, 'year').subtract(7, 'day').toISOString()
|
|
80
|
+
const startDate = moment(birthDate).add(JUNIOR_MAX_AGE, 'years').add(1, 'year').toISOString()
|
|
81
|
+
const number = await generatePermissionNumber(
|
|
82
|
+
{
|
|
83
|
+
...getSamplePermission({
|
|
84
|
+
permitId: MOCK_12MONTH_SENIOR_PERMIT.id,
|
|
85
|
+
birthDate
|
|
86
|
+
}),
|
|
87
|
+
startDate,
|
|
88
|
+
issueDate
|
|
89
|
+
},
|
|
90
|
+
'Web Sales'
|
|
91
|
+
)
|
|
92
|
+
expect(number).toMatch(/-[A-Z0-9]{4}F/)
|
|
93
|
+
})
|
|
74
94
|
})
|
|
75
95
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
getSamplePermission(
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
)
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
96
|
+
describe('senior', () => {
|
|
97
|
+
it('generates a permission number for seniors', async () => {
|
|
98
|
+
const number = await generatePermissionNumber(getSamplePermission(), 'Web Sales')
|
|
99
|
+
const block1 = moment().add(1, 'hour').startOf('hour').add(1, 'day').format('HHDDMMYY')
|
|
100
|
+
const expected = new RegExp(`^${block1}-2WC1SFT-[A-Z0-9]{5}[0-9]$`)
|
|
101
|
+
expect(number).toMatch(expected)
|
|
102
|
+
})
|
|
103
|
+
|
|
104
|
+
it('formats as S if startDate is on 66th birthday but issueDate is 1 week before', async () => {
|
|
105
|
+
const birthDate = moment().subtract(SENIOR_MIN_AGE, 'years').format('YYYY-MM-DD')
|
|
106
|
+
const issueDate = moment(birthDate).add(SENIOR_MIN_AGE, 'years').subtract(7, 'day').toISOString()
|
|
107
|
+
const startDate = moment(birthDate).add(SENIOR_MIN_AGE, 'years').toISOString()
|
|
108
|
+
const number = await generatePermissionNumber(
|
|
109
|
+
{
|
|
110
|
+
...getSamplePermission({
|
|
111
|
+
permitId: MOCK_12MONTH_SENIOR_PERMIT.id,
|
|
112
|
+
birthDate
|
|
113
|
+
}),
|
|
114
|
+
startDate,
|
|
115
|
+
issueDate
|
|
116
|
+
},
|
|
117
|
+
'Web Sales'
|
|
118
|
+
)
|
|
119
|
+
expect(number).toMatch(/-[A-Z0-9]{4}S/)
|
|
120
|
+
})
|
|
88
121
|
})
|
|
89
122
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
123
|
+
describe('junior', () => {
|
|
124
|
+
it('generates a permission number for juniors', async () => {
|
|
125
|
+
const number = await generatePermissionNumber(
|
|
126
|
+
getSamplePermission({
|
|
127
|
+
birthDate: moment()
|
|
128
|
+
.subtract(JUNIOR_MAX_AGE - 1, 'years')
|
|
129
|
+
.format('YYYY-MM-DD')
|
|
130
|
+
}),
|
|
131
|
+
'Web Sales'
|
|
132
|
+
)
|
|
133
|
+
const block1 = moment().add(1, 'hour').startOf('hour').add(1, 'day').format('HHDDMMYY')
|
|
134
|
+
const expected = new RegExp(`^${block1}-2WC1JFT-[A-Z0-9]{5}[0-9]$`)
|
|
135
|
+
expect(number).toMatch(expected)
|
|
136
|
+
})
|
|
137
|
+
|
|
138
|
+
it('formats as J if startDate is on 16th birthday but issueDate is 1 week before', async () => {
|
|
139
|
+
const birthDate = moment().subtract(JUNIOR_MAX_AGE, 'years').format('YYYY-MM-DD')
|
|
140
|
+
const startDate = moment(birthDate).add(JUNIOR_MAX_AGE, 'years').toISOString()
|
|
141
|
+
const issueDate = moment(startDate).subtract(7, 'day').toISOString()
|
|
142
|
+
const number = await generatePermissionNumber(
|
|
143
|
+
{
|
|
144
|
+
...getSamplePermission({
|
|
145
|
+
permitId: MOCK_12MONTH_SENIOR_PERMIT.id,
|
|
146
|
+
birthDate
|
|
147
|
+
}),
|
|
148
|
+
startDate,
|
|
149
|
+
issueDate
|
|
150
|
+
},
|
|
151
|
+
'Web Sales'
|
|
152
|
+
)
|
|
153
|
+
expect(number).toMatch(/-[A-Z0-9]{4}J/)
|
|
154
|
+
})
|
|
95
155
|
})
|
|
96
156
|
})
|
|
97
157
|
|
|
@@ -16,7 +16,6 @@ const DICTIONARIES = [
|
|
|
16
16
|
* Generate a new permission number
|
|
17
17
|
*
|
|
18
18
|
* @param permitId
|
|
19
|
-
* @param issueDate
|
|
20
19
|
* @param startDate
|
|
21
20
|
* @param dataSource
|
|
22
21
|
* @param firstName
|
|
@@ -24,10 +23,7 @@ const DICTIONARIES = [
|
|
|
24
23
|
* @param birthDate
|
|
25
24
|
* @returns {Promise<string>}
|
|
26
25
|
*/
|
|
27
|
-
export const generatePermissionNumber = async (
|
|
28
|
-
{ permitId, issueDate, startDate, licensee: { firstName, lastName, birthDate } },
|
|
29
|
-
dataSource
|
|
30
|
-
) => {
|
|
26
|
+
export const generatePermissionNumber = async ({ permitId, startDate, licensee: { firstName, lastName, birthDate } }, dataSource) => {
|
|
31
27
|
const permit = await getReferenceDataForEntityAndId(Permit, permitId)
|
|
32
28
|
|
|
33
29
|
const endDate = await calculateEndDateMoment({ permitId, startDate })
|
|
@@ -43,7 +39,7 @@ export const generatePermissionNumber = async (
|
|
|
43
39
|
|
|
44
40
|
const durationInDays = moment.duration(`P${permit.durationMagnitude}${permit.durationDesignator.description}`).asDays()
|
|
45
41
|
const duration = String(durationInDays).charAt(0)
|
|
46
|
-
const age = getAgeCategory(birthDate,
|
|
42
|
+
const age = getAgeCategory(birthDate, startDate)
|
|
47
43
|
const initials = (firstName.charAt(0) + lastName.charAt(0)).toUpperCase()
|
|
48
44
|
const block2 = permit.numberOfRods + channel + type + duration + age + initials
|
|
49
45
|
|
|
@@ -82,18 +78,18 @@ const SENIOR_AGE = 66
|
|
|
82
78
|
/**
|
|
83
79
|
* Determine the appropriate age category code for use in a permission number
|
|
84
80
|
* @param birthDate The birth date of the licensee
|
|
85
|
-
* @param
|
|
81
|
+
* @param startDate The start date of the permission
|
|
86
82
|
* @returns {string} The appropriate category code (single digit string)
|
|
87
83
|
*/
|
|
88
|
-
const getAgeCategory = (birthDate,
|
|
84
|
+
const getAgeCategory = (birthDate, startDate) => {
|
|
89
85
|
const dob = moment(birthDate)
|
|
90
|
-
const
|
|
86
|
+
const start = moment(startDate)
|
|
91
87
|
const seventeenthBirthday = dob.clone().add(ADULT_AGE, 'years')
|
|
92
88
|
const sixtysixthBirthday = dob.clone().add(SENIOR_AGE, 'years')
|
|
93
89
|
|
|
94
|
-
if (
|
|
90
|
+
if (start.isBefore(seventeenthBirthday)) {
|
|
95
91
|
return 'J'
|
|
96
|
-
} else if (
|
|
92
|
+
} else if (start.isSameOrAfter(sixtysixthBirthday)) {
|
|
97
93
|
return 'S'
|
|
98
94
|
} else {
|
|
99
95
|
return 'F'
|