@defra-fish/business-rules-lib 1.33.0-rc.8 → 1.33.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,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra-fish/business-rules-lib",
3
- "version": "1.33.0-rc.8",
3
+ "version": "1.33.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": "432443fdf2c5f267038d4547cf8659b28bf7e9bf"
40
+ "gitHead": "4d9f66bbf6842bcfa09be77e591460bedf2ba7ec"
41
41
  }
@@ -1,14 +1,4 @@
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'
1
+ import { isMinor, isJunior, isSenior, MINOR_MAX_AGE, JUNIOR_MAX_AGE, SENIOR_MIN_AGE } from '../ages.js'
12
2
 
13
3
  describe('age determination', () => {
14
4
  describe('isMinor', () => {
@@ -39,35 +29,5 @@ describe('age determination', () => {
39
29
  it(`age of ${SENIOR_MIN_AGE - 1} is not a senior`, () => {
40
30
  expect(isSenior(SENIOR_MIN_AGE - 1)).toBeFalsy()
41
31
  })
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
- })
72
32
  })
73
33
  })
@@ -12,4 +12,20 @@ describe('permissions helper', () => {
12
12
  const cost = getPermissionCost(permission)
13
13
  expect(cost).toBe(expectedCost)
14
14
  })
15
+
16
+ it('returns new cost if no start date provided and current date / time is after new cost start date', () => {
17
+ jest.useFakeTimers()
18
+ jest.setSystemTime(new Date('2023-04-02T00:00:00.000Z'))
19
+ const permission = { permit: { cost: 10, newCost: 20, newCostStartDate: '2023-04-01T00:00:00.000' } }
20
+ const cost = getPermissionCost(permission)
21
+ expect(cost).toBe(permission.permit.newCost)
22
+ })
23
+
24
+ it('returns old cost if no start date provided and current date / time is before new cost start date', () => {
25
+ jest.useFakeTimers()
26
+ jest.setSystemTime(new Date('2023-03-31T00:00:00.000Z'))
27
+ const permission = { permit: { cost: 10, newCost: 20, newCostStartDate: '2023-04-01T00:00:00.000' } }
28
+ const cost = getPermissionCost(permission)
29
+ expect(cost).toBe(permission.permit.cost)
30
+ })
15
31
  })
package/src/util/ages.js CHANGED
@@ -1,14 +1,9 @@
1
- import moment from 'moment'
2
-
3
1
  /** The maximum age at which an angler is considered to be a minor (free licence) */
4
2
  export const MINOR_MAX_AGE = 12
5
3
  /** The maximum age at which an angler is entitled to a junior concession */
6
4
  export const JUNIOR_MAX_AGE = 16
7
5
  /** The minimum age at which an angler becomes entitled to a senior concession */
8
- export const SENIOR_MIN_AGE = 65
9
- export const NEW_SENIOR_MIN_AGE = 66
10
- export const SENIOR_AGE_CHANGE_DATE = '2023-04-01T00:00:00.000+01:00'
11
- const changeoverMoment = moment(SENIOR_AGE_CHANGE_DATE)
6
+ export const SENIOR_MIN_AGE = 66
12
7
 
13
8
  /**
14
9
  * Determine if the provided age is classified as a minor
@@ -27,10 +22,6 @@ export const isJunior = age => age > MINOR_MAX_AGE && age <= JUNIOR_MAX_AGE
27
22
  /**
28
23
  * Determine if the provided age is classified as a senior
29
24
  * @param {number} age The age to be tested
30
- * @param {string} permissionStartDate in format YYYY-MM-DD
31
25
  * @returns {boolean} true if the given age should be classified as a senior
32
26
  */
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
- }
27
+ export const isSenior = age => age >= SENIOR_MIN_AGE
@@ -1,5 +1,6 @@
1
1
  export const getPermissionCost = permission => {
2
- if (Date.parse(permission.startDate) >= Date.parse(permission.permit.newCostStartDate)) {
2
+ const permissionStartDate = permission.startDate || new Date().toISOString()
3
+ if (Date.parse(permissionStartDate) >= Date.parse(permission.permit.newCostStartDate)) {
3
4
  return permission.permit.newCost
4
5
  }
5
6
  return permission.permit.cost