@defra-fish/dynamics-lib 1.64.0-rc.8 → 1.64.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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@defra-fish/dynamics-lib",
3
- "version": "1.64.0-rc.8",
3
+ "version": "1.64.0",
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": "88a60cab95e119b46cec17336d784aec1aeabae8"
46
+ "gitHead": "d6a3d30c7a20169fdf5afb1a93eb1d411fe96abf"
47
47
  }
@@ -1,6 +1,23 @@
1
- import { findDueRecurringPayments, findRecurringPaymentsByAgreementId } from '../recurring-payments.queries.js'
1
+ import {
2
+ findDueRecurringPayments,
3
+ findRecurringPaymentsByAgreementId,
4
+ findRecurringPaymentByPermissionId
5
+ } from '../recurring-payments.queries.js'
2
6
 
3
7
  describe('Recurring Payment Queries', () => {
8
+ const baseSelection = () => [
9
+ 'defra_recurringpaymentid',
10
+ 'defra_name',
11
+ 'statecode',
12
+ 'defra_nextduedate',
13
+ 'defra_cancelleddate',
14
+ 'defra_cancelledreason',
15
+ 'defra_enddate',
16
+ 'defra_agreementid',
17
+ 'defra_publicid',
18
+ 'defra_lastdigitscardnumbers'
19
+ ]
20
+
4
21
  describe('findDueRecurringPayments', () => {
5
22
  it('builds a query to retrieve active recurring payments', () => {
6
23
  const date = new Date('2023-11-08')
@@ -11,18 +28,7 @@ describe('Recurring Payment Queries', () => {
11
28
  collection: 'defra_recurringpayments',
12
29
  filter:
13
30
  "defra_nextduedate eq 'Wed Nov 08 2023 00:00:00 GMT+0000 (Greenwich Mean Time)' and defra_cancelleddate eq null and _defra_nextrecurringpayment_value eq null and statecode eq 0",
14
- select: [
15
- 'defra_recurringpaymentid',
16
- 'defra_name',
17
- 'statecode',
18
- 'defra_nextduedate',
19
- 'defra_cancelleddate',
20
- 'defra_cancelledreason',
21
- 'defra_enddate',
22
- 'defra_agreementid',
23
- 'defra_publicid',
24
- 'defra_lastdigitscardnumbers'
25
- ],
31
+ select: baseSelection(),
26
32
  expand: [{ property: 'defra_Contact' }, { property: 'defra_ActivePermission' }]
27
33
  })
28
34
  })
@@ -37,18 +43,22 @@ describe('Recurring Payment Queries', () => {
37
43
  expect(query.toRetrieveRequest()).toEqual({
38
44
  collection: 'defra_recurringpayments',
39
45
  filter: `defra_agreementid eq '${agreementId}' and statecode eq 0`,
40
- select: [
41
- 'defra_recurringpaymentid',
42
- 'defra_name',
43
- 'statecode',
44
- 'defra_nextduedate',
45
- 'defra_cancelleddate',
46
- 'defra_cancelledreason',
47
- 'defra_enddate',
48
- 'defra_agreementid',
49
- 'defra_publicid',
50
- 'defra_lastdigitscardnumbers'
51
- ]
46
+ select: baseSelection()
47
+ })
48
+ })
49
+ })
50
+
51
+ describe('findRecurringPaymentByPermissionId', () => {
52
+ it('builds a query to retrieve recurring payments by permissionId', () => {
53
+ const permissionId = 'perm-123'
54
+
55
+ const query = findRecurringPaymentByPermissionId(permissionId)
56
+
57
+ expect(query.toRetrieveRequest()).toEqual({
58
+ collection: 'defra_recurringpayments',
59
+ filter: `_defra_activepermission_value eq ${permissionId} and statecode eq 0`,
60
+ select: baseSelection(),
61
+ expand: [{ property: 'defra_ActivePermission' }]
52
62
  })
53
63
  })
54
64
  })
@@ -42,3 +42,20 @@ export const findRecurringPaymentsByAgreementId = agreementId => {
42
42
  filter: filters.join(' and ')
43
43
  })
44
44
  }
45
+
46
+ /**
47
+ * Builds a query to retrieve recurring payments by permissionId
48
+ *
49
+ * @param permissionId the id generated by a permission
50
+ * @returns {PredefinedQuery}
51
+ */
52
+ export const findRecurringPaymentByPermissionId = permissionId => {
53
+ const { activePermission } = RecurringPayment.definition.relationships
54
+ const filter = `_defra_activepermission_value eq ${permissionId} and ${RecurringPayment.definition.defaultFilter}`
55
+
56
+ return new PredefinedQuery({
57
+ root: RecurringPayment,
58
+ filter,
59
+ expand: [activePermission]
60
+ })
61
+ }