@defra-fish/dynamics-lib 1.75.0-rc.2 → 1.75.0-rc.4
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.75.0-rc.
|
|
3
|
+
"version": "1.75.0-rc.4",
|
|
4
4
|
"description": "Framework to support integration with dynamics",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -43,5 +43,5 @@
|
|
|
43
43
|
"simple-oauth2": "4.3.0",
|
|
44
44
|
"uuid": "8.3.2"
|
|
45
45
|
},
|
|
46
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "663e9bf7baaedb86adc812f4a99f4accd70191be"
|
|
47
47
|
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import {
|
|
2
2
|
findDueRecurringPayments,
|
|
3
3
|
findRecurringPaymentsByAgreementId,
|
|
4
|
-
findRecurringPaymentByPermissionId
|
|
4
|
+
findRecurringPaymentByPermissionId,
|
|
5
|
+
findRecurringPaymentById
|
|
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 = () => [
|
|
@@ -62,4 +64,33 @@ describe('Recurring Payment Queries', () => {
|
|
|
62
64
|
})
|
|
63
65
|
})
|
|
64
66
|
})
|
|
67
|
+
|
|
68
|
+
describe('findRecurringPaymentById', () => {
|
|
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
|
+
jest.spyOn(RecurringPayment, 'definition', 'get').mockReturnValue(createMockDefinition(mockDefaultFilter))
|
|
84
|
+
|
|
85
|
+
const request = findRecurringPaymentById(recurringPaymentId).toRetrieveRequest()
|
|
86
|
+
expect(request.filter).toBe(`defra_recurringpaymentid eq ${recurringPaymentId} and ${mockDefaultFilter}`)
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
it('expands active permission relationship', () => {
|
|
90
|
+
jest.spyOn(RecurringPayment, 'definition', 'get').mockReturnValue(createMockDefinition('mock_default_filter'))
|
|
91
|
+
|
|
92
|
+
const request = findRecurringPaymentById('rcp-456').toRetrieveRequest()
|
|
93
|
+
expect(request.expand).toContainEqual({ property: 'defra_ActivePermission' })
|
|
94
|
+
})
|
|
95
|
+
})
|
|
65
96
|
})
|
|
@@ -59,3 +59,20 @@ export const findRecurringPaymentByPermissionId = permissionId => {
|
|
|
59
59
|
expand: [activePermission]
|
|
60
60
|
})
|
|
61
61
|
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Builds a query to retrieve a recurring payment by id, with its linked active permission expanded
|
|
65
|
+
*
|
|
66
|
+
* @param recurringPaymentId the id of the recurring payment
|
|
67
|
+
* @returns {PredefinedQuery}
|
|
68
|
+
*/
|
|
69
|
+
export const findRecurringPaymentById = recurringPaymentId => {
|
|
70
|
+
const { activePermission } = RecurringPayment.definition.relationships
|
|
71
|
+
const filter = `defra_recurringpaymentid eq ${recurringPaymentId} and ${RecurringPayment.definition.defaultFilter}`
|
|
72
|
+
|
|
73
|
+
return new PredefinedQuery({
|
|
74
|
+
root: RecurringPayment,
|
|
75
|
+
filter,
|
|
76
|
+
expand: [activePermission]
|
|
77
|
+
})
|
|
78
|
+
}
|