@defra-fish/dynamics-lib 1.73.0-rc.7-test-iwtf-4598 → 1.73.0-sales-api-refactor
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/dynamics-lib",
|
|
3
|
-
"version": "1.73.0-
|
|
3
|
+
"version": "1.73.0-sales-api-refactor",
|
|
4
4
|
"description": "Framework to support integration with dynamics",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -42,6 +42,5 @@
|
|
|
42
42
|
"pluralize": "8.0.0",
|
|
43
43
|
"simple-oauth2": "4.3.0",
|
|
44
44
|
"uuid": "8.3.2"
|
|
45
|
-
}
|
|
46
|
-
"gitHead": "df95217ac9db8ee2c4c079ce39ba1483bcb2b4ae"
|
|
45
|
+
}
|
|
47
46
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
findDueRecurringPayments,
|
|
3
3
|
findRecurringPaymentsByAgreementId,
|
|
4
|
-
findRecurringPaymentByPermissionId
|
|
4
|
+
findRecurringPaymentByPermissionId,
|
|
5
|
+
findPermissionByRecurringPaymentId
|
|
5
6
|
} from '../recurring-payments.queries.js'
|
|
7
|
+
import { RecurringPayment } from '../../entities/recurring-payment.entity.js'
|
|
6
8
|
|
|
7
9
|
describe('Recurring Payment Queries', () => {
|
|
8
10
|
const baseSelection = () => [
|
|
@@ -19,7 +21,7 @@ describe('Recurring Payment Queries', () => {
|
|
|
19
21
|
]
|
|
20
22
|
|
|
21
23
|
describe('findDueRecurringPayments', () => {
|
|
22
|
-
it('builds
|
|
24
|
+
it('builds retrieve request with due date filter, active-state checks and contact/permission expands', () => {
|
|
23
25
|
const date = new Date('2023-11-08')
|
|
24
26
|
|
|
25
27
|
const query = findDueRecurringPayments(date)
|
|
@@ -35,7 +37,7 @@ describe('Recurring Payment Queries', () => {
|
|
|
35
37
|
})
|
|
36
38
|
|
|
37
39
|
describe('findRecurringPaymentsByAgreementId', () => {
|
|
38
|
-
it('builds
|
|
40
|
+
it('builds retrieve request filtered by agreement id and active state', () => {
|
|
39
41
|
const agreementId = 'abc123'
|
|
40
42
|
|
|
41
43
|
const query = findRecurringPaymentsByAgreementId(agreementId)
|
|
@@ -49,7 +51,7 @@ describe('Recurring Payment Queries', () => {
|
|
|
49
51
|
})
|
|
50
52
|
|
|
51
53
|
describe('findRecurringPaymentByPermissionId', () => {
|
|
52
|
-
it('builds
|
|
54
|
+
it('builds retrieve request filtered by active permission id and active state', () => {
|
|
53
55
|
const permissionId = 'perm-123'
|
|
54
56
|
|
|
55
57
|
const query = findRecurringPaymentByPermissionId(permissionId)
|
|
@@ -62,4 +64,43 @@ describe('Recurring Payment Queries', () => {
|
|
|
62
64
|
})
|
|
63
65
|
})
|
|
64
66
|
})
|
|
67
|
+
|
|
68
|
+
describe('findPermissionByRecurringPaymentId', () => {
|
|
69
|
+
const createMockDefinition = defaultFilter => ({
|
|
70
|
+
defaultFilter,
|
|
71
|
+
relationships: {
|
|
72
|
+
activePermission: { property: 'defra_ActivePermission' }
|
|
73
|
+
},
|
|
74
|
+
toRetrieveRequest: filter => ({
|
|
75
|
+
collection: 'defra_recurringpayments',
|
|
76
|
+
select: baseSelection(),
|
|
77
|
+
filter
|
|
78
|
+
})
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
it.each(['rcp-456', 'rcp-789'])('builds full filter with conjunctions when recurring payment id is %s', recurringPaymentId => {
|
|
82
|
+
const mockDefaultFilter = 'mock_default_filter'
|
|
83
|
+
const definitionSpy = jest.spyOn(RecurringPayment, 'definition', 'get').mockReturnValue(createMockDefinition(mockDefaultFilter))
|
|
84
|
+
|
|
85
|
+
try {
|
|
86
|
+
const request = findPermissionByRecurringPaymentId(recurringPaymentId).toRetrieveRequest()
|
|
87
|
+
expect(request.filter).toBe(
|
|
88
|
+
`_defra_activepermission_value ne null and defra_recurringpaymentid eq ${recurringPaymentId} and ${mockDefaultFilter}`
|
|
89
|
+
)
|
|
90
|
+
} finally {
|
|
91
|
+
definitionSpy.mockRestore()
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('expands active permission relationship', () => {
|
|
96
|
+
const definitionSpy = jest.spyOn(RecurringPayment, 'definition', 'get').mockReturnValue(createMockDefinition('mock_default_filter'))
|
|
97
|
+
|
|
98
|
+
try {
|
|
99
|
+
const request = findPermissionByRecurringPaymentId('rcp-456').toRetrieveRequest()
|
|
100
|
+
expect(request.expand).toContainEqual({ property: 'defra_ActivePermission' })
|
|
101
|
+
} finally {
|
|
102
|
+
definitionSpy.mockRestore()
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
})
|
|
65
106
|
})
|
|
@@ -59,3 +59,20 @@ export const findRecurringPaymentByPermissionId = permissionId => {
|
|
|
59
59
|
expand: [activePermission]
|
|
60
60
|
})
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Builds a query to retrieve the active permission linked to a recurring payment
|
|
65
|
+
*
|
|
66
|
+
* @param recurringPaymentId the id of the recurring payment
|
|
67
|
+
* @returns {PredefinedQuery}
|
|
68
|
+
*/
|
|
69
|
+
export const findPermissionByRecurringPaymentId = recurringPaymentId => {
|
|
70
|
+
const { activePermission } = RecurringPayment.definition.relationships
|
|
71
|
+
const filter = `_defra_activepermission_value ne null and defra_recurringpaymentid eq ${recurringPaymentId} and ${RecurringPayment.definition.defaultFilter}`
|
|
72
|
+
|
|
73
|
+
return new PredefinedQuery({
|
|
74
|
+
root: RecurringPayment,
|
|
75
|
+
filter,
|
|
76
|
+
expand: [activePermission]
|
|
77
|
+
})
|
|
78
|
+
}
|