@defra-fish/sales-api-service 1.78.0-rc.0 → 1.78.0-rc.2
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.78.0-rc.
|
|
3
|
+
"version": "1.78.0-rc.2",
|
|
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.78.0-rc.
|
|
39
|
-
"@defra-fish/connectors-lib": "1.78.0-rc.
|
|
40
|
-
"@defra-fish/dynamics-lib": "1.78.0-rc.
|
|
38
|
+
"@defra-fish/business-rules-lib": "1.78.0-rc.2",
|
|
39
|
+
"@defra-fish/connectors-lib": "1.78.0-rc.2",
|
|
40
|
+
"@defra-fish/dynamics-lib": "1.78.0-rc.2",
|
|
41
41
|
"@hapi/boom": "9.1.2",
|
|
42
42
|
"@hapi/hapi": "20.1.3",
|
|
43
43
|
"@hapi/inert": "6.0.3",
|
|
@@ -53,5 +53,5 @@
|
|
|
53
53
|
"moment-timezone": "0.5.34",
|
|
54
54
|
"uuid": "8.3.2"
|
|
55
55
|
},
|
|
56
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "ccf5451df9750e8afcb2a3bd253bb90ec224105b"
|
|
57
57
|
}
|
|
@@ -209,6 +209,20 @@ describe('permissions service', () => {
|
|
|
209
209
|
const endDate = await calculateEndDate({ permitId: 'e11b34a0-0c66-e611-80dc-c4346bad0190', startDate })
|
|
210
210
|
expect(endDate).toBe('2025-02-28T23:59:59.999Z')
|
|
211
211
|
})
|
|
212
|
+
|
|
213
|
+
it.each([
|
|
214
|
+
['2028-02-29T23:59:59.999Z', '2027-03-01'],
|
|
215
|
+
['2029-02-28T23:59:59.999Z', '2028-03-01'],
|
|
216
|
+
['2032-02-29T23:59:59.999Z', '2031-03-01'],
|
|
217
|
+
['2033-02-28T23:59:59.999Z', '2032-03-01'],
|
|
218
|
+
['2028-03-01T23:59:59.999Z', '2027-03-02']
|
|
219
|
+
])('returns %s as the end date for a 12 month licence starting %s', async (expected, start) => {
|
|
220
|
+
const endDate = await calculateEndDate({
|
|
221
|
+
permitId: 'e11b34a0-0c66-e611-80dc-c4346bad0190',
|
|
222
|
+
startDate: moment(`${start}T00:00:00.000Z`)
|
|
223
|
+
})
|
|
224
|
+
expect(endDate).toBe(expected)
|
|
225
|
+
})
|
|
212
226
|
})
|
|
213
227
|
|
|
214
228
|
describe('sequence generator', () => {
|
|
@@ -50,7 +50,8 @@ export const generatePermissionNumber = async ({ permitId, startDate, licensee:
|
|
|
50
50
|
}
|
|
51
51
|
|
|
52
52
|
/**
|
|
53
|
-
* Calculate the end date of a permission for a given permitId and start date
|
|
53
|
+
* Calculate the end date of a permission for a given permitId and start date.
|
|
54
|
+
* 12 month licences starting on 1st March end on the last day of February the following year, whether this is the 28th or 29th.
|
|
54
55
|
* @param {string} permitId the permit ID to use when calculating the end date
|
|
55
56
|
* @param {moment.Moment|string} startDate The start date to use when calculating the end date
|
|
56
57
|
* @returns {Promise<moment.Moment>} The end date as a moment
|
|
@@ -59,7 +60,12 @@ export const calculateEndDateMoment = async ({ permitId, startDate }) => {
|
|
|
59
60
|
const permit = await getReferenceDataForEntityAndId(Permit, permitId)
|
|
60
61
|
const duration = moment.duration(`P${permit.durationMagnitude}${permit.durationDesignator.description}`)
|
|
61
62
|
if (permit.durationMagnitude === 12 && permit.durationDesignator.description === 'M') {
|
|
62
|
-
|
|
63
|
+
const localStart = moment(startDate).tz(SERVICE_LOCAL_TIME)
|
|
64
|
+
const endMoment = localStart.clone().subtract(1, 'day').endOf('day').add(duration)
|
|
65
|
+
if (localStart.month() === 2 && localStart.date() === 1) {
|
|
66
|
+
endMoment.endOf('month')
|
|
67
|
+
}
|
|
68
|
+
return endMoment
|
|
63
69
|
}
|
|
64
70
|
return moment(startDate).add(duration)
|
|
65
71
|
}
|