@defra-fish/sales-api-service 1.73.0-rc.8 → 1.73.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 +6 -5
- package/src/__mocks__/dynamics-web-api.js +4 -2
- package/src/server/plugins/__tests__/health.spec.js +1 -1
- package/src/server/plugins/health.js +1 -1
- package/src/services/__tests__/recurring-payments.service.spec.js +11 -11
- package/src/services/__tests__/reference-data.service.spec.js +14 -14
- package/src/services/recurring-payments.service.js +2 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@defra-fish/sales-api-service",
|
|
3
|
-
"version": "1.73.0
|
|
3
|
+
"version": "1.73.0",
|
|
4
4
|
"description": "Rod Licensing Sales API",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -35,15 +35,16 @@
|
|
|
35
35
|
"test": "echo \"Error: run tests from root\" && exit 1"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@defra-fish/business-rules-lib": "1.73.0
|
|
39
|
-
"@defra-fish/connectors-lib": "1.73.0
|
|
40
|
-
"@defra-fish/dynamics-lib": "1.73.0
|
|
38
|
+
"@defra-fish/business-rules-lib": "1.73.0",
|
|
39
|
+
"@defra-fish/connectors-lib": "1.73.0",
|
|
40
|
+
"@defra-fish/dynamics-lib": "1.73.0",
|
|
41
41
|
"@hapi/boom": "9.1.2",
|
|
42
42
|
"@hapi/hapi": "20.1.3",
|
|
43
43
|
"@hapi/inert": "6.0.3",
|
|
44
44
|
"@hapi/vision": "6.1.0",
|
|
45
45
|
"debug": "4.3.3",
|
|
46
46
|
"dot-prop": "6.0.1",
|
|
47
|
+
"dynamics-web-api": "2.4.0",
|
|
47
48
|
"hapi-and-healthy": "7.0.7",
|
|
48
49
|
"hapi-swagger": "14.2.5",
|
|
49
50
|
"ioredis": "4.28.5",
|
|
@@ -52,5 +53,5 @@
|
|
|
52
53
|
"moment-timezone": "0.5.34",
|
|
53
54
|
"uuid": "8.3.2"
|
|
54
55
|
},
|
|
55
|
-
"gitHead": "
|
|
56
|
+
"gitHead": "128d150e6bd30468bca4e39fb44dd11c5598eb43"
|
|
56
57
|
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
1
|
import { configureDynamicsWebApiMock } from '../../../dynamics-lib/src/__mocks__/dynamics-web-api-mock-helper.js'
|
|
2
|
-
const DynamicsWebApi = jest.
|
|
3
|
-
|
|
2
|
+
const DynamicsWebApi = jest.fn()
|
|
3
|
+
DynamicsWebApi.prototype = {}
|
|
4
|
+
configureDynamicsWebApiMock(DynamicsWebApi)
|
|
5
|
+
export { DynamicsWebApi }
|
|
@@ -84,7 +84,7 @@ describe('hapi healthcheck', () => {
|
|
|
84
84
|
})
|
|
85
85
|
|
|
86
86
|
it('exposes a service status page returning a 500 error when unhealthy', async () => {
|
|
87
|
-
jest.spyOn(dynamicsClient, '
|
|
87
|
+
jest.spyOn(dynamicsClient, 'callFunction').mockImplementation(async () => {
|
|
88
88
|
throw new Error('Simulated')
|
|
89
89
|
})
|
|
90
90
|
const result = await server.inject({ method: 'GET', url: '/service-status' })
|
|
@@ -19,7 +19,7 @@ export default {
|
|
|
19
19
|
test: {
|
|
20
20
|
node: [
|
|
21
21
|
async () => {
|
|
22
|
-
return { connection: 'dynamics', status: 'ok', ...(await dynamicsClient.
|
|
22
|
+
return { connection: 'dynamics', status: 'ok', ...(await dynamicsClient.callFunction('RetrieveVersion')) }
|
|
23
23
|
},
|
|
24
24
|
async () => {
|
|
25
25
|
return { connection: 'dynamodb', status: 'ok', ...(await ddb.listTables()) }
|
|
@@ -52,7 +52,7 @@ jest.mock('@defra-fish/dynamics-lib', () => ({
|
|
|
52
52
|
findDueRecurringPayments: jest.fn(),
|
|
53
53
|
findRecurringPaymentsByAgreementId: jest.fn(() => ({ toRetrieveRequest: () => {} })),
|
|
54
54
|
dynamicsClient: {
|
|
55
|
-
|
|
55
|
+
retrieveMultiple: jest.fn(() => ({ value: [] }))
|
|
56
56
|
},
|
|
57
57
|
persist: jest.fn(),
|
|
58
58
|
findRecurringPaymentByPermissionId: jest.fn(() => ({ toRetrieveRequest: () => {} })),
|
|
@@ -780,16 +780,16 @@ describe('recurring payments service', () => {
|
|
|
780
780
|
expect(findRecurringPaymentsByAgreementId).toHaveBeenCalledWith(agreementId)
|
|
781
781
|
})
|
|
782
782
|
|
|
783
|
-
it('passes query created by findRecurringPaymentsByAgreementId to
|
|
783
|
+
it('passes query created by findRecurringPaymentsByAgreementId to retrieveMultiple', async () => {
|
|
784
784
|
const retrieveRequest = Symbol('retrieve request')
|
|
785
785
|
findRecurringPaymentsByAgreementId.mockReturnValueOnce({ toRetrieveRequest: () => retrieveRequest })
|
|
786
786
|
await findNewestExistingRecurringPaymentInCrm()
|
|
787
|
-
expect(dynamicsClient.
|
|
787
|
+
expect(dynamicsClient.retrieveMultiple).toHaveBeenCalledWith(retrieveRequest)
|
|
788
788
|
})
|
|
789
789
|
|
|
790
790
|
it('returns a Recurring Payment (not a plain object)', async () => {
|
|
791
791
|
jest.spyOn(RecurringPayment, 'fromResponse')
|
|
792
|
-
dynamicsClient.
|
|
792
|
+
dynamicsClient.retrieveMultiple.mockReturnValueOnce(getMockResponse())
|
|
793
793
|
const recurringPayment = await findNewestExistingRecurringPaymentInCrm()
|
|
794
794
|
expect(RecurringPayment.fromResponse.mock.results[0].value).toBe(recurringPayment)
|
|
795
795
|
})
|
|
@@ -824,13 +824,13 @@ describe('recurring payments service', () => {
|
|
|
824
824
|
'908-oid'
|
|
825
825
|
]
|
|
826
826
|
])('returns most recent existing recurring payment from %s', async (_desc, mockResponseData, expectedId) => {
|
|
827
|
-
dynamicsClient.
|
|
827
|
+
dynamicsClient.retrieveMultiple.mockReturnValueOnce({ value: mockResponseData })
|
|
828
828
|
const recurringPayment = await findNewestExistingRecurringPaymentInCrm()
|
|
829
829
|
expect(recurringPayment.id).toBe(expectedId)
|
|
830
830
|
})
|
|
831
831
|
|
|
832
832
|
it('returns boolean false if no recurring payments found', async () => {
|
|
833
|
-
dynamicsClient.
|
|
833
|
+
dynamicsClient.retrieveMultiple.mockReturnValueOnce({ value: [] })
|
|
834
834
|
const recurringPayment = await findNewestExistingRecurringPaymentInCrm()
|
|
835
835
|
expect(recurringPayment).toBeFalsy()
|
|
836
836
|
})
|
|
@@ -987,7 +987,7 @@ describe('recurring payments service', () => {
|
|
|
987
987
|
describe('findLinkedRecurringPayment', () => {
|
|
988
988
|
const arrangeLinkedRcpSuccess = mockResponse => {
|
|
989
989
|
jest.spyOn(RecurringPayment, 'fromResponse')
|
|
990
|
-
dynamicsClient.
|
|
990
|
+
dynamicsClient.retrieveMultiple.mockReturnValueOnce(mockResponse)
|
|
991
991
|
retrieveGlobalOptionSets.mockReturnValueOnce({
|
|
992
992
|
cached: jest.fn().mockResolvedValue({ definition: 'mock-def' })
|
|
993
993
|
})
|
|
@@ -999,11 +999,11 @@ describe('recurring payments service', () => {
|
|
|
999
999
|
expect(findRecurringPaymentByPermissionId).toHaveBeenCalledWith(permissionId)
|
|
1000
1000
|
})
|
|
1001
1001
|
|
|
1002
|
-
it('passes query created by findRecurringPaymentByPermissionId to
|
|
1002
|
+
it('passes query created by findRecurringPaymentByPermissionId to retrieveMultiple', async () => {
|
|
1003
1003
|
const retrieveRequest = Symbol('retrieve request')
|
|
1004
1004
|
findRecurringPaymentByPermissionId.mockReturnValueOnce({ toRetrieveRequest: () => retrieveRequest })
|
|
1005
1005
|
await findLinkedRecurringPayment()
|
|
1006
|
-
expect(dynamicsClient.
|
|
1006
|
+
expect(dynamicsClient.retrieveMultiple).toHaveBeenCalledWith(retrieveRequest)
|
|
1007
1007
|
})
|
|
1008
1008
|
|
|
1009
1009
|
it('calls RecurringPayment.fromResponse with response and definitions', async () => {
|
|
@@ -1037,7 +1037,7 @@ describe('recurring payments service', () => {
|
|
|
1037
1037
|
'rcp-456'
|
|
1038
1038
|
]
|
|
1039
1039
|
])('returns the most recent linked recurring payment (%s)', async (_desc, mockData, expectedId) => {
|
|
1040
|
-
dynamicsClient.
|
|
1040
|
+
dynamicsClient.retrieveMultiple.mockReturnValueOnce({ value: mockData })
|
|
1041
1041
|
retrieveGlobalOptionSets.mockReturnValueOnce({ cached: jest.fn().mockResolvedValue({ def: 'mock' }) })
|
|
1042
1042
|
|
|
1043
1043
|
const recurringPayment = await findLinkedRecurringPayment('abc123')
|
|
@@ -1045,7 +1045,7 @@ describe('recurring payments service', () => {
|
|
|
1045
1045
|
})
|
|
1046
1046
|
|
|
1047
1047
|
it('returns false if no linked recurring payments found', async () => {
|
|
1048
|
-
dynamicsClient.
|
|
1048
|
+
dynamicsClient.retrieveMultiple.mockReturnValueOnce({ value: [] })
|
|
1049
1049
|
const recurringPayment = await findLinkedRecurringPayment('abc123')
|
|
1050
1050
|
expect(recurringPayment).toBeFalsy()
|
|
1051
1051
|
})
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
MOCK_1DAY_SENIOR_PERMIT_DYNAMICS_RESPONSE,
|
|
13
13
|
MOCK_CONCESSION_DYNAMICS_RESPONSE
|
|
14
14
|
} from '../../__mocks__/test-data.js'
|
|
15
|
-
import
|
|
15
|
+
import { DynamicsWebApi } from 'dynamics-web-api'
|
|
16
16
|
|
|
17
17
|
const getOptionSetMappingExpectation = (name, ...keys) => {
|
|
18
18
|
const options = keys.reduce((acc, k) => {
|
|
@@ -32,8 +32,8 @@ const getOptionSetMappingExpectation = (name, ...keys) => {
|
|
|
32
32
|
|
|
33
33
|
describe('reference-data service', () => {
|
|
34
34
|
beforeAll(async () => {
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
DynamicsWebApi.__reset()
|
|
36
|
+
DynamicsWebApi.__setResponse('executeBatch', [
|
|
37
37
|
{
|
|
38
38
|
value: [MOCK_12MONTH_SENIOR_PERMIT_DYNAMICS_RESPONSE, MOCK_1DAY_SENIOR_PERMIT_DYNAMICS_RESPONSE]
|
|
39
39
|
},
|
|
@@ -50,12 +50,12 @@ describe('reference-data service', () => {
|
|
|
50
50
|
permits: expect.arrayContaining([expect.any(Permit)]),
|
|
51
51
|
concessions: expect.arrayContaining([expect.any(Concession)])
|
|
52
52
|
})
|
|
53
|
-
expect(
|
|
53
|
+
expect(DynamicsWebApi.prototype.executeBatch).toHaveBeenCalledTimes(1)
|
|
54
54
|
})
|
|
55
55
|
it('uses a cache', async () => {
|
|
56
56
|
await getReferenceData()
|
|
57
57
|
await getReferenceData()
|
|
58
|
-
expect(
|
|
58
|
+
expect(DynamicsWebApi.prototype.executeBatch).toHaveBeenCalledTimes(1)
|
|
59
59
|
})
|
|
60
60
|
})
|
|
61
61
|
|
|
@@ -63,7 +63,7 @@ describe('reference-data service', () => {
|
|
|
63
63
|
it('retrieves an entries for the given type', async () => {
|
|
64
64
|
const result = await getReferenceDataForEntity(Permit)
|
|
65
65
|
expect(result).toEqual(expect.arrayContaining([expect.any(Permit)]))
|
|
66
|
-
expect(
|
|
66
|
+
expect(DynamicsWebApi.prototype.executeBatch).toHaveBeenCalledTimes(1)
|
|
67
67
|
})
|
|
68
68
|
})
|
|
69
69
|
|
|
@@ -71,12 +71,12 @@ describe('reference-data service', () => {
|
|
|
71
71
|
it('retrieves an entry for a given id', async () => {
|
|
72
72
|
const result = await getReferenceDataForEntityAndId(Permit, MOCK_12MONTH_SENIOR_PERMIT_DYNAMICS_RESPONSE.defra_permitid)
|
|
73
73
|
expect(result).toBeInstanceOf(Permit)
|
|
74
|
-
expect(
|
|
74
|
+
expect(DynamicsWebApi.prototype.executeBatch).toHaveBeenCalledTimes(1)
|
|
75
75
|
})
|
|
76
76
|
it('returns undefined if not found', async () => {
|
|
77
77
|
const result = await getReferenceDataForEntityAndId(Permit, 'not-found')
|
|
78
78
|
expect(result).toBe(undefined)
|
|
79
|
-
expect(
|
|
79
|
+
expect(DynamicsWebApi.prototype.executeBatch).toHaveBeenCalledTimes(1)
|
|
80
80
|
})
|
|
81
81
|
})
|
|
82
82
|
|
|
@@ -89,7 +89,7 @@ describe('reference-data service', () => {
|
|
|
89
89
|
defra_concessionproof: getOptionSetMappingExpectation('defra_concessionproof', 910400000, 910400001, 910400002, 910400003)
|
|
90
90
|
})
|
|
91
91
|
)
|
|
92
|
-
expect(
|
|
92
|
+
expect(DynamicsWebApi.prototype.retrieveGlobalOptionSets).toHaveBeenCalledTimes(1)
|
|
93
93
|
})
|
|
94
94
|
})
|
|
95
95
|
|
|
@@ -97,12 +97,12 @@ describe('reference-data service', () => {
|
|
|
97
97
|
it('retrieves all option-sets for a single name', async () => {
|
|
98
98
|
const result = await getGlobalOptionSet('defra_duration')
|
|
99
99
|
expect(result).toMatchObject(getOptionSetMappingExpectation('defra_duration', 910400000, 910400001, 910400002, 910400003))
|
|
100
|
-
expect(
|
|
100
|
+
expect(DynamicsWebApi.prototype.retrieveGlobalOptionSets).toHaveBeenCalledTimes(1)
|
|
101
101
|
})
|
|
102
102
|
it('returns undefined if not found', async () => {
|
|
103
103
|
const result = await getGlobalOptionSet('not-found')
|
|
104
104
|
expect(result).toBe(undefined)
|
|
105
|
-
expect(
|
|
105
|
+
expect(DynamicsWebApi.prototype.retrieveGlobalOptionSets).toHaveBeenCalledTimes(1)
|
|
106
106
|
})
|
|
107
107
|
})
|
|
108
108
|
|
|
@@ -110,17 +110,17 @@ describe('reference-data service', () => {
|
|
|
110
110
|
it('retrieves a single option-set for a single name and label', async () => {
|
|
111
111
|
const result = await getGlobalOptionSetValue('defra_duration', '1 day')
|
|
112
112
|
expect(result).toMatchObject({ id: 910400000, label: '1 day', description: '1 day' })
|
|
113
|
-
expect(
|
|
113
|
+
expect(DynamicsWebApi.prototype.retrieveGlobalOptionSets).toHaveBeenCalledTimes(1)
|
|
114
114
|
})
|
|
115
115
|
it('returns undefined if the option-set label is not found', async () => {
|
|
116
116
|
const result = await getGlobalOptionSetValue('defra_duration', 'not-found')
|
|
117
117
|
expect(result).toBe(undefined)
|
|
118
|
-
expect(
|
|
118
|
+
expect(DynamicsWebApi.prototype.retrieveGlobalOptionSets).toHaveBeenCalledTimes(1)
|
|
119
119
|
})
|
|
120
120
|
it('returns undefined if the option-set name is not found', async () => {
|
|
121
121
|
const result = await getGlobalOptionSetValue('not-found', 'not-found')
|
|
122
122
|
expect(result).toBe(undefined)
|
|
123
|
-
expect(
|
|
123
|
+
expect(DynamicsWebApi.prototype.retrieveGlobalOptionSets).toHaveBeenCalledTimes(1)
|
|
124
124
|
})
|
|
125
125
|
})
|
|
126
126
|
})
|
|
@@ -158,7 +158,7 @@ export const processRPResult = async (transactionId, paymentId, createdDate) =>
|
|
|
158
158
|
|
|
159
159
|
export const findNewestExistingRecurringPaymentInCrm = async agreementId => {
|
|
160
160
|
const query = findRecurringPaymentsByAgreementId(agreementId)
|
|
161
|
-
const response = await dynamicsClient.
|
|
161
|
+
const response = await dynamicsClient.retrieveMultiple(query.toRetrieveRequest())
|
|
162
162
|
if (response.value.length) {
|
|
163
163
|
const [rcpResponseData] = response.value.sort((a, b) => Date.parse(b.defra_enddate) - Date.parse(a.defra_enddate))
|
|
164
164
|
return RecurringPayment.fromResponse(rcpResponseData)
|
|
@@ -192,7 +192,7 @@ const determineRecurringPaymentName = (transactionRecord, contact) => {
|
|
|
192
192
|
|
|
193
193
|
export const findLinkedRecurringPayment = async permissionId => {
|
|
194
194
|
const query = findRecurringPaymentByPermissionId(permissionId)
|
|
195
|
-
const response = await dynamicsClient.
|
|
195
|
+
const response = await dynamicsClient.retrieveMultiple(query.toRetrieveRequest())
|
|
196
196
|
if (response.value.length) {
|
|
197
197
|
const [rcpResponseData] = response.value.sort((a, b) => Date.parse(b.defra_enddate) - Date.parse(a.defra_enddate))
|
|
198
198
|
const definition = await retrieveGlobalOptionSets().cached()
|