@defra-fish/sales-api-service 1.63.0-rc.13 → 1.63.0-rc.15

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.63.0-rc.13",
3
+ "version": "1.63.0-rc.15",
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.63.0-rc.13",
39
- "@defra-fish/connectors-lib": "1.63.0-rc.13",
40
- "@defra-fish/dynamics-lib": "1.63.0-rc.13",
38
+ "@defra-fish/business-rules-lib": "1.63.0-rc.15",
39
+ "@defra-fish/connectors-lib": "1.63.0-rc.15",
40
+ "@defra-fish/dynamics-lib": "1.63.0-rc.15",
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": "d3579f75016512c92605e0f8824200d33a83f589"
55
+ "gitHead": "af32a7debc5f14203373c2a9e87ac2c63958a7f4"
56
56
  }
@@ -62,7 +62,9 @@ describe('permissions service', () => {
62
62
  const number = await generatePermissionNumber(
63
63
  getSamplePermission({
64
64
  permitId: MOCK_12MONTH_DISABLED_PERMIT.id,
65
- birthDate: moment().subtract(JUNIOR_MAX_AGE, 'years').format('YYYY-MM-DD')
65
+ birthDate: moment()
66
+ .subtract(JUNIOR_MAX_AGE + 1, 'years')
67
+ .format('YYYY-MM-DD')
66
68
  }),
67
69
  'Telesales'
68
70
  )
@@ -95,7 +95,6 @@ jest.mock('../../services/paymentjournals/payment-journals.service.js', () => ({
95
95
  }))
96
96
 
97
97
  jest.mock('@defra-fish/business-rules-lib', () => ({
98
- ADVANCED_PURCHASE_MAX_DAYS: 30,
99
98
  PAYMENT_JOURNAL_STATUS_CODES: {
100
99
  InProgress: 'InProgressCode',
101
100
  Cancelled: 'CancelledCode',
@@ -455,6 +454,17 @@ describe('recurring payments service', () => {
455
454
  '2025-11-12T00:00:00.000Z',
456
455
  '3456'
457
456
  ],
457
+ [
458
+ 'starts thirty-one days after issue date - next due on issue date plus one year',
459
+ '9o8u7yhui89u8i9oiu8i8u7yhu',
460
+ {
461
+ startDate: '2024-12-14T00:00:00.000Z',
462
+ issueDate: '2024-11-12T15:00:45.922Z',
463
+ endDate: '2025-12-13T23:59:59.999Z'
464
+ },
465
+ '2025-11-12T00:00:00.000Z',
466
+ '4321'
467
+ ],
458
468
  [
459
469
  "issued on 29th Feb '24, starts on 30th March '24 - next due on 28th Feb '25",
460
470
  'hy7u8ijhyu78jhyu8iu8hjiujn',
@@ -511,11 +521,11 @@ describe('recurring payments service', () => {
511
521
 
512
522
  it.each([
513
523
  [
514
- 'start date is thirty one days after issue date',
524
+ 'start date equals issue date',
515
525
  {
516
- startDate: '2024-12-14T00:00:00.000Z',
517
- issueDate: '2024-11-12T15:00:45.922Z',
518
- endDate: '2025-12-13T23:59:59.999Z'
526
+ startDate: '2024-11-11T00:00:00.000Z',
527
+ issueDate: '2024-11-11T00:00:00.000Z',
528
+ endDate: '2025-11-10T23:59:59.999Z'
519
529
  }
520
530
  ],
521
531
  [
@@ -1,5 +1,5 @@
1
1
  import { Permission, Permit } from '@defra-fish/dynamics-lib'
2
- import { isJunior, isSenior, SERVICE_LOCAL_TIME } from '@defra-fish/business-rules-lib'
2
+ import { SERVICE_LOCAL_TIME } from '@defra-fish/business-rules-lib'
3
3
  import { getGlobalOptionSetValue, getReferenceDataForEntityAndId } from './reference-data.service.js'
4
4
  import { redis } from './ioredis.service.js'
5
5
  import moment from 'moment-timezone'
@@ -76,6 +76,9 @@ export const calculateEndDateMoment = async ({ permitId, startDate }) => {
76
76
  */
77
77
  export const calculateEndDate = async ({ permitId, startDate }) => (await calculateEndDateMoment({ permitId, startDate })).toISOString()
78
78
 
79
+ const ADULT_AGE = 17
80
+ const SENIOR_AGE = 66
81
+
79
82
  /**
80
83
  * Determine the appropriate age category code for use in a permission number
81
84
  * @param birthDate The birth date of the licensee
@@ -85,14 +88,16 @@ export const calculateEndDate = async ({ permitId, startDate }) => (await calcul
85
88
  const getAgeCategory = (birthDate, issueDate) => {
86
89
  const dob = moment(birthDate)
87
90
  const issue = moment(issueDate)
88
- const diff = issue.diff(dob, 'years', true)
91
+ const seventeenthBirthday = dob.clone().add(ADULT_AGE, 'years')
92
+ const sixtysixthBirthday = dob.clone().add(SENIOR_AGE, 'years')
89
93
 
90
- if (isJunior(diff)) {
94
+ if (issue.isBefore(seventeenthBirthday)) {
91
95
  return 'J'
92
- } else if (isSenior(diff)) {
96
+ } else if (issue.isSameOrAfter(sixtysixthBirthday)) {
93
97
  return 'S'
98
+ } else {
99
+ return 'F'
94
100
  }
95
- return 'F'
96
101
  }
97
102
 
98
103
  /**
@@ -10,7 +10,7 @@ import {
10
10
  import { calculateEndDate, generatePermissionNumber } from './permissions.service.js'
11
11
  import { getObfuscatedDob } from './contacts.service.js'
12
12
  import { createHash } from 'node:crypto'
13
- import { ADVANCED_PURCHASE_MAX_DAYS, PAYMENT_JOURNAL_STATUS_CODES, PAYMENT_TYPE, TRANSACTION_SOURCE } from '@defra-fish/business-rules-lib'
13
+ import { PAYMENT_JOURNAL_STATUS_CODES, PAYMENT_TYPE, TRANSACTION_SOURCE } from '@defra-fish/business-rules-lib'
14
14
  import { TRANSACTION_STAGING_TABLE, TRANSACTION_QUEUE } from '../config.js'
15
15
  import { TRANSACTION_STATUS } from '../services/transactions/constants.js'
16
16
  import { retrieveStagedTransaction } from '../services/transactions/retrieve-transaction.js'
@@ -26,7 +26,7 @@ export const getRecurringPayments = date => executeQuery(findDueRecurringPayment
26
26
 
27
27
  const getNextDueDate = (startDate, issueDate, endDate) => {
28
28
  const mStart = moment(startDate)
29
- if (mStart.isAfter(moment(issueDate)) && mStart.isSameOrBefore(moment(issueDate).add(ADVANCED_PURCHASE_MAX_DAYS, 'days'), 'day')) {
29
+ if (mStart.isAfter(moment(issueDate))) {
30
30
  if (mStart.isSame(moment(issueDate), 'day')) {
31
31
  return moment(startDate).add(1, 'year').subtract(10, 'days').startOf('day').toISOString()
32
32
  }