@defra-fish/business-rules-lib 1.30.0 → 1.31.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 +2 -2
- package/src/util/__tests__/ages.spec.js +59 -9
- package/src/util/ages.js +10 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra-fish/business-rules-lib",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.31.0-rc.0",
|
|
4
4
|
"description": "Shared business rules for the rod licensing digital services",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -37,5 +37,5 @@
|
|
|
37
37
|
"moment": "^2.29.1",
|
|
38
38
|
"uuid": "^8.3.2"
|
|
39
39
|
},
|
|
40
|
-
"gitHead": "
|
|
40
|
+
"gitHead": "2400d2924cc92d60a00883fcdf4a6c9d398a81de"
|
|
41
41
|
}
|
|
@@ -1,23 +1,73 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
isMinor,
|
|
3
|
+
isJunior,
|
|
4
|
+
isSenior,
|
|
5
|
+
MINOR_MAX_AGE,
|
|
6
|
+
JUNIOR_MAX_AGE,
|
|
7
|
+
SENIOR_MIN_AGE,
|
|
8
|
+
NEW_SENIOR_MIN_AGE,
|
|
9
|
+
SENIOR_AGE_CHANGE_DATE
|
|
10
|
+
} from '../ages.js'
|
|
11
|
+
import moment from 'moment'
|
|
2
12
|
|
|
3
13
|
describe('age determination', () => {
|
|
4
14
|
describe('isMinor', () => {
|
|
5
|
-
it(
|
|
6
|
-
expect(isMinor(
|
|
15
|
+
it.each(Array.from({ length: MINOR_MAX_AGE }, (_v, index) => index + 1))('age of %d is a minor', age => {
|
|
16
|
+
expect(isMinor(age)).toBeTruthy()
|
|
17
|
+
})
|
|
18
|
+
it(`${MINOR_MAX_AGE + 1} is not a minor`, () => {
|
|
19
|
+
expect(isMinor(MINOR_MAX_AGE + 1)).toBeFalsy()
|
|
7
20
|
})
|
|
8
21
|
})
|
|
9
22
|
describe('isJunior', () => {
|
|
10
|
-
it(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
23
|
+
it.each(Array.from({ length: JUNIOR_MAX_AGE - MINOR_MAX_AGE }, (_v, index) => MINOR_MAX_AGE + index + 1))(
|
|
24
|
+
'Age of %d is a Junior',
|
|
25
|
+
age => {
|
|
26
|
+
expect(isJunior(age)).toBeTruthy()
|
|
27
|
+
}
|
|
28
|
+
)
|
|
29
|
+
it.each([MINOR_MAX_AGE, JUNIOR_MAX_AGE + 1])('Age of %d is not a junior', age => {
|
|
30
|
+
expect(isJunior(age)).toBeFalsy()
|
|
14
31
|
})
|
|
15
32
|
})
|
|
16
33
|
|
|
17
34
|
describe('isSenior', () => {
|
|
18
|
-
it(
|
|
19
|
-
expect(isSenior(
|
|
35
|
+
it.each(Array.from({ length: 10 }, (_v, index) => SENIOR_MIN_AGE + index))('age of %d is a senior', age => {
|
|
36
|
+
expect(isSenior(age)).toBeTruthy()
|
|
37
|
+
})
|
|
38
|
+
|
|
39
|
+
it(`age of ${SENIOR_MIN_AGE - 1} is not a senior`, () => {
|
|
20
40
|
expect(isSenior(SENIOR_MIN_AGE - 1)).toBeFalsy()
|
|
21
41
|
})
|
|
42
|
+
|
|
43
|
+
it.each([moment(SENIOR_AGE_CHANGE_DATE).format('YYYY-MM-DD'), moment(SENIOR_AGE_CHANGE_DATE).add(1, 'day').format('YYYY-MM-DD')])(
|
|
44
|
+
`age of ${SENIOR_MIN_AGE} isn't a senior for permissions starting on %s`,
|
|
45
|
+
() => {
|
|
46
|
+
expect(isSenior(SENIOR_MIN_AGE, SENIOR_AGE_CHANGE_DATE)).toBeFalsy()
|
|
47
|
+
}
|
|
48
|
+
)
|
|
49
|
+
|
|
50
|
+
it.each([
|
|
51
|
+
moment(SENIOR_AGE_CHANGE_DATE).subtract(1, 'day').format('YYYY-MM-DD'),
|
|
52
|
+
moment(SENIOR_AGE_CHANGE_DATE).subtract(2, 'day').format('YYYY-MM-DD'),
|
|
53
|
+
moment(SENIOR_AGE_CHANGE_DATE).subtract(1, 'week').format('YYYY-MM-DD'),
|
|
54
|
+
moment(SENIOR_AGE_CHANGE_DATE).subtract(1, 'month').format('YYYY-MM-DD')
|
|
55
|
+
])(`age of ${SENIOR_MIN_AGE} is senior for permissions starting on %s (before SENIOR_AGE_CHANGE_DATE)`, startDate => {
|
|
56
|
+
expect(isSenior(SENIOR_MIN_AGE, startDate)).toBeTruthy()
|
|
57
|
+
})
|
|
58
|
+
|
|
59
|
+
it.each`
|
|
60
|
+
age | startDate
|
|
61
|
+
${NEW_SENIOR_MIN_AGE} | ${moment(SENIOR_AGE_CHANGE_DATE).format('YYYY-MM-DD')}
|
|
62
|
+
${NEW_SENIOR_MIN_AGE} | ${moment(SENIOR_AGE_CHANGE_DATE).add(1, 'day').format('YYYY-MM-DD')}
|
|
63
|
+
${NEW_SENIOR_MIN_AGE} | ${moment(SENIOR_AGE_CHANGE_DATE).add(1, 'week').format('YYYY-MM-DD')}
|
|
64
|
+
${NEW_SENIOR_MIN_AGE} | ${moment(SENIOR_AGE_CHANGE_DATE).add(1, 'month').format('YYYY-MM-DD')}
|
|
65
|
+
${NEW_SENIOR_MIN_AGE + 1} | ${moment(SENIOR_AGE_CHANGE_DATE).format('YYYY-MM-DD')}
|
|
66
|
+
${NEW_SENIOR_MIN_AGE + 5} | ${moment(SENIOR_AGE_CHANGE_DATE).add(1, 'day').format('YYYY-MM-DD')}
|
|
67
|
+
${NEW_SENIOR_MIN_AGE + 10} | ${moment(SENIOR_AGE_CHANGE_DATE).add(1, 'week').format('YYYY-MM-DD')}
|
|
68
|
+
${NEW_SENIOR_MIN_AGE + 15} | ${moment(SENIOR_AGE_CHANGE_DATE).add(1, 'month').format('YYYY-MM-DD')}
|
|
69
|
+
`('age of $age is senior for permissions starting on $startDate (on or after SENIOR_AGE_CHANGE_DATE)', ({ age, startDate }) => {
|
|
70
|
+
expect(isSenior(age, startDate)).toBeTruthy()
|
|
71
|
+
})
|
|
22
72
|
})
|
|
23
73
|
})
|
package/src/util/ages.js
CHANGED
|
@@ -1,9 +1,14 @@
|
|
|
1
|
+
import moment from 'moment'
|
|
2
|
+
|
|
1
3
|
/** The maximum age at which an angler is considered to be a minor (free licence) */
|
|
2
4
|
export const MINOR_MAX_AGE = 12
|
|
3
5
|
/** The maximum age at which an angler is entitled to a junior concession */
|
|
4
6
|
export const JUNIOR_MAX_AGE = 16
|
|
5
7
|
/** The minimum age at which an angler becomes entitled to a senior concession */
|
|
6
8
|
export const SENIOR_MIN_AGE = 65
|
|
9
|
+
export const NEW_SENIOR_MIN_AGE = 66
|
|
10
|
+
export const SENIOR_AGE_CHANGE_DATE = '2023-04-01'
|
|
11
|
+
const changeoverMoment = moment(SENIOR_AGE_CHANGE_DATE)
|
|
7
12
|
|
|
8
13
|
/**
|
|
9
14
|
* Determine if the provided age is classified as a minor
|
|
@@ -22,6 +27,10 @@ export const isJunior = age => age > MINOR_MAX_AGE && age <= JUNIOR_MAX_AGE
|
|
|
22
27
|
/**
|
|
23
28
|
* Determine if the provided age is classified as a senior
|
|
24
29
|
* @param {number} age The age to be tested
|
|
30
|
+
* @param {string} permissionStartDate in format YYYY-MM-DD
|
|
25
31
|
* @returns {boolean} true if the given age should be classified as a senior
|
|
26
32
|
*/
|
|
27
|
-
export const isSenior = age =>
|
|
33
|
+
export const isSenior = (age, permissionStartDate) => {
|
|
34
|
+
const permissionStartsAfterChangeover = changeoverMoment.isSameOrBefore(permissionStartDate)
|
|
35
|
+
return permissionStartsAfterChangeover ? age >= NEW_SENIOR_MIN_AGE : age >= SENIOR_MIN_AGE
|
|
36
|
+
}
|