@defra-fish/sales-api-service 1.60.0 → 1.61.0-rc.1
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.
|
|
3
|
+
"version": "1.61.0-rc.1",
|
|
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.
|
|
39
|
-
"@defra-fish/connectors-lib": "1.
|
|
40
|
-
"@defra-fish/dynamics-lib": "1.
|
|
38
|
+
"@defra-fish/business-rules-lib": "1.61.0-rc.1",
|
|
39
|
+
"@defra-fish/connectors-lib": "1.61.0-rc.1",
|
|
40
|
+
"@defra-fish/dynamics-lib": "1.61.0-rc.1",
|
|
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": "511d7de4ea42bfeca0078f5ff64b5e77c785d44b"
|
|
56
56
|
}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
dueRecurringPaymentsRequestParamsSchema,
|
|
3
|
+
dueRecurringPaymentsResponseSchema,
|
|
4
|
+
processRPResultRequestParamsSchema
|
|
5
|
+
} from '../recurring-payments.schema.js'
|
|
2
6
|
|
|
3
7
|
jest.mock('../validators/validators.js', () => ({
|
|
4
8
|
...jest.requireActual('../validators/validators.js'),
|
|
5
9
|
createEntityIdValidator: () => () => {} // sample data so we don't want it validated for being a real entity id
|
|
6
10
|
}))
|
|
7
11
|
|
|
8
|
-
const
|
|
12
|
+
const getResponseSampleData = () => ({
|
|
9
13
|
id: 'd5549fc6-41c1-ef11-b8e8-7c1e52215dc9',
|
|
10
14
|
name: 'test',
|
|
11
15
|
status: 0,
|
|
@@ -52,9 +56,15 @@ const getSampleData = () => ({
|
|
|
52
56
|
}
|
|
53
57
|
})
|
|
54
58
|
|
|
59
|
+
const getProcessRPResultSampleData = () => ({
|
|
60
|
+
transactionId: 'abc123',
|
|
61
|
+
paymentId: 'def456',
|
|
62
|
+
createdDate: '2025-01-01T00:00:00.000Z'
|
|
63
|
+
})
|
|
64
|
+
|
|
55
65
|
describe('getDueRecurringPaymentsSchema', () => {
|
|
56
66
|
it('validates expected object', async () => {
|
|
57
|
-
|
|
67
|
+
expect(() => dueRecurringPaymentsResponseSchema.validateAsync(getResponseSampleData())).not.toThrow()
|
|
58
68
|
})
|
|
59
69
|
|
|
60
70
|
it.each([
|
|
@@ -70,7 +80,7 @@ describe('getDueRecurringPaymentsSchema', () => {
|
|
|
70
80
|
'contactId',
|
|
71
81
|
'publicId'
|
|
72
82
|
])('throws an error if %s is missing', async property => {
|
|
73
|
-
const sampleData =
|
|
83
|
+
const sampleData = getResponseSampleData()
|
|
74
84
|
delete sampleData[property]
|
|
75
85
|
expect(() => dueRecurringPaymentsResponseSchema.validateAsync(sampleData)).rejects.toThrow()
|
|
76
86
|
})
|
|
@@ -88,7 +98,7 @@ describe('getDueRecurringPaymentsSchema', () => {
|
|
|
88
98
|
['contactId', 'still-not-a-guid'],
|
|
89
99
|
['publicId', 99]
|
|
90
100
|
])('throws an error if %s is not the correct type', async (property, value) => {
|
|
91
|
-
const sampleData =
|
|
101
|
+
const sampleData = getResponseSampleData()
|
|
92
102
|
sampleData[property] = value
|
|
93
103
|
expect(() => dueRecurringPaymentsResponseSchema.validateAsync(sampleData)).rejects.toThrow()
|
|
94
104
|
})
|
|
@@ -97,3 +107,45 @@ describe('getDueRecurringPaymentsSchema', () => {
|
|
|
97
107
|
expect(dueRecurringPaymentsResponseSchema).toMatchSnapshot()
|
|
98
108
|
})
|
|
99
109
|
})
|
|
110
|
+
|
|
111
|
+
describe('dueRecurringPaymentsRequestParamsSchema', () => {
|
|
112
|
+
it('validates expected object', async () => {
|
|
113
|
+
const sampleData = {
|
|
114
|
+
date: '2024-12-23'
|
|
115
|
+
}
|
|
116
|
+
expect(() => dueRecurringPaymentsRequestParamsSchema.validateAsync(sampleData)).not.toThrow()
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
it('throws an error if date missing', async () => {
|
|
120
|
+
expect(() => dueRecurringPaymentsRequestParamsSchema.validateAsync({}).rejects.toThrow())
|
|
121
|
+
})
|
|
122
|
+
|
|
123
|
+
it('throws an error if date is not the correct type', async () => {
|
|
124
|
+
const sampleData = {
|
|
125
|
+
date: 'not-a-date'
|
|
126
|
+
}
|
|
127
|
+
expect(() => dueRecurringPaymentsRequestParamsSchema.validateAsync(sampleData).rejects.toThrow())
|
|
128
|
+
})
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
describe('processRPResultRequestParamsSchema', () => {
|
|
132
|
+
it('validates expected object', async () => {
|
|
133
|
+
expect(() => processRPResultRequestParamsSchema.validateAsync(getProcessRPResultSampleData())).not.toThrow()
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it.each([['transactionId'], ['paymentId'], ['createdDate']])('throws an error if %s is missing', async property => {
|
|
137
|
+
const sampleData = getProcessRPResultSampleData()
|
|
138
|
+
delete sampleData[property]
|
|
139
|
+
expect(() => processRPResultRequestParamsSchema.validateAsync(sampleData).rejects.toThrow())
|
|
140
|
+
})
|
|
141
|
+
|
|
142
|
+
it.each([
|
|
143
|
+
['transactionId', 99],
|
|
144
|
+
['paymentId', 99],
|
|
145
|
+
['createdDate', 'not-a-date']
|
|
146
|
+
])('throws an error if %s is not the correct type', async (property, value) => {
|
|
147
|
+
const sampleData = getProcessRPResultSampleData()
|
|
148
|
+
sampleData[property] = value
|
|
149
|
+
expect(() => processRPResultRequestParamsSchema.validateAsync(sampleData).rejects.toThrow())
|
|
150
|
+
})
|
|
151
|
+
})
|
|
@@ -19,3 +19,13 @@ export const dueRecurringPaymentsResponseSchema = Joi.object({
|
|
|
19
19
|
activePermission: { entity: finalisedPermissionSchemaContent }
|
|
20
20
|
})
|
|
21
21
|
})
|
|
22
|
+
|
|
23
|
+
export const dueRecurringPaymentsRequestParamsSchema = Joi.object({
|
|
24
|
+
date: Joi.string().isoDate().required()
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
export const processRPResultRequestParamsSchema = Joi.object({
|
|
28
|
+
transactionId: Joi.string().required(),
|
|
29
|
+
paymentId: Joi.string().required(),
|
|
30
|
+
createdDate: Joi.string().isoDate().required()
|
|
31
|
+
})
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import recurringPayments from '../recurring-payments.js'
|
|
2
2
|
import { getRecurringPayments, processRPResult } from '../../../services/recurring-payments.service.js'
|
|
3
|
+
import { dueRecurringPaymentsRequestParamsSchema, processRPResultRequestParamsSchema } from '../../../schema/recurring-payments.schema.js'
|
|
3
4
|
|
|
4
5
|
const [
|
|
5
6
|
{
|
|
@@ -15,6 +16,11 @@ jest.mock('../../../services/recurring-payments.service.js', () => ({
|
|
|
15
16
|
processRPResult: jest.fn()
|
|
16
17
|
}))
|
|
17
18
|
|
|
19
|
+
jest.mock('../../../schema/recurring-payments.schema.js', () => ({
|
|
20
|
+
dueRecurringPaymentsRequestParamsSchema: jest.fn(),
|
|
21
|
+
processRPResultRequestParamsSchema: jest.fn()
|
|
22
|
+
}))
|
|
23
|
+
|
|
18
24
|
const getMockRequest = ({
|
|
19
25
|
date = '2023-10-19',
|
|
20
26
|
transactionId = 'transaction-id',
|
|
@@ -44,6 +50,13 @@ describe('recurring payments', () => {
|
|
|
44
50
|
await drpHandler(request, getMockResponseToolkit())
|
|
45
51
|
expect(getRecurringPayments).toHaveBeenCalledWith(date)
|
|
46
52
|
})
|
|
53
|
+
|
|
54
|
+
it('should validate with dueRecurringPaymentsRequestParamsSchema', async () => {
|
|
55
|
+
const date = Symbol('date')
|
|
56
|
+
const request = getMockRequest({ date })
|
|
57
|
+
await drpHandler(request, getMockResponseToolkit())
|
|
58
|
+
expect(recurringPayments[0].options.validate.params).toBe(dueRecurringPaymentsRequestParamsSchema)
|
|
59
|
+
})
|
|
47
60
|
})
|
|
48
61
|
|
|
49
62
|
describe('processRPResult', () => {
|
|
@@ -61,5 +74,12 @@ describe('recurring payments', () => {
|
|
|
61
74
|
await prpHandler(request, getMockResponseToolkit())
|
|
62
75
|
expect(processRPResult).toHaveBeenCalledWith(transactionId, paymentId, createdDate)
|
|
63
76
|
})
|
|
77
|
+
|
|
78
|
+
it('should validate with dueRecurringPaymentsRequestParamsSchema', async () => {
|
|
79
|
+
const date = Symbol('date')
|
|
80
|
+
const request = getMockRequest({ date })
|
|
81
|
+
await drpHandler(request, getMockResponseToolkit())
|
|
82
|
+
expect(recurringPayments[1].options.validate.params).toBe(processRPResultRequestParamsSchema)
|
|
83
|
+
})
|
|
64
84
|
})
|
|
65
85
|
})
|
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
dueRecurringPaymentsRequestParamsSchema,
|
|
3
|
+
dueRecurringPaymentsResponseSchema,
|
|
4
|
+
processRPResultRequestParamsSchema
|
|
5
|
+
} from '../../schema/recurring-payments.schema.js'
|
|
2
6
|
import { getRecurringPayments, processRPResult } from '../../services/recurring-payments.service.js'
|
|
3
7
|
|
|
4
8
|
export default [
|
|
@@ -13,6 +17,9 @@ export default [
|
|
|
13
17
|
},
|
|
14
18
|
description: 'Retrieve recurring payments due for the specified date',
|
|
15
19
|
tags: ['api', 'recurring-payments'],
|
|
20
|
+
validate: {
|
|
21
|
+
params: dueRecurringPaymentsRequestParamsSchema
|
|
22
|
+
},
|
|
16
23
|
plugins: {
|
|
17
24
|
'hapi-swagger': {
|
|
18
25
|
responses: {
|
|
@@ -34,6 +41,9 @@ export default [
|
|
|
34
41
|
},
|
|
35
42
|
description: 'Generate a permission from a recurring payment record',
|
|
36
43
|
tags: ['api', 'recurring-payments'],
|
|
44
|
+
validate: {
|
|
45
|
+
params: processRPResultRequestParamsSchema
|
|
46
|
+
},
|
|
37
47
|
plugins: {
|
|
38
48
|
'hapi-swagger': {
|
|
39
49
|
responses: {
|