@defra-fish/dynamics-lib 1.59.0-rc.5 → 1.59.0-rc.7

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.59.0-rc.5",
3
+ "version": "1.59.0-rc.7",
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": "a14e3194db1d9f75d1eb49ef3e873f442970fcf5"
46
+ "gitHead": "1c25db53364eccaad0d24eb7f1f7fc3bb2e48014"
47
47
  }
@@ -6,7 +6,7 @@ describe('recurring payment entity', () => {
6
6
  optionSetData = await retrieveGlobalOptionSets().cached()
7
7
  })
8
8
 
9
- const createRecurringPayment = (contact, permission, cancelledDate, cancelledReason) => {
9
+ const createRecurringPayment = ({ contact, permission, cancelledDate = null, cancelledReason = null, nextRecurringPayment } = {}) => {
10
10
  const recurringPayment = new RecurringPayment()
11
11
 
12
12
  recurringPayment.name = 'Test Name'
@@ -20,6 +20,9 @@ describe('recurring payment entity', () => {
20
20
 
21
21
  recurringPayment.bindToEntity(RecurringPayment.definition.relationships.contact, contact)
22
22
  recurringPayment.bindToEntity(RecurringPayment.definition.relationships.activePermission, permission)
23
+ if (nextRecurringPayment) {
24
+ recurringPayment.bindToEntity(RecurringPayment.definition.relationships.nextRecurringPayment, nextRecurringPayment)
25
+ }
23
26
 
24
27
  return recurringPayment
25
28
  }
@@ -37,7 +40,8 @@ describe('recurring payment entity', () => {
37
40
  defra_publicid: '649-213',
38
41
  statecode: 1,
39
42
  _defra_contact_value: 'b3d33cln-2e83-ea11-a811-000d3a649213',
40
- _defra_activepermission_value: 'a5b24adf-2e83-ea11-a811-000d3a649213'
43
+ _defra_activepermission_value: 'a5b24adf-2e83-ea11-a811-000d3a649213',
44
+ _defra_nextrecurringpayment_value: 'q4ra6lma-2e83-ea11-a811-000d3a649213'
41
45
  }
42
46
 
43
47
  const response = { ...defaultResponse, ...overrides }
@@ -72,12 +76,12 @@ describe('recurring payment entity', () => {
72
76
  it('maps to dynamics', async () => {
73
77
  const contact = new Contact()
74
78
  const permission = new Permission()
75
- const recurringPayment = createRecurringPayment(
79
+ const recurringPayment = createRecurringPayment({
76
80
  contact,
77
81
  permission,
78
- '2019-10-14T00:00:00Z',
79
- optionSetData.defra_cancelledreason.options['910400195']
80
- )
82
+ cancelledDate: '2019-10-14T00:00:00Z',
83
+ cancelledReason: optionSetData.defra_cancelledreason.options['910400195']
84
+ })
81
85
  const dynamicsEntity = recurringPayment.toRequestBody()
82
86
  expect(dynamicsEntity).toMatchObject(
83
87
  expect.objectContaining({
@@ -123,7 +127,7 @@ describe('recurring payment entity', () => {
123
127
  it('maps to dynamics', async () => {
124
128
  const contact = new Contact()
125
129
  const permission = new Permission()
126
- const recurringPayment = createRecurringPayment(contact, permission, null, null)
130
+ const recurringPayment = createRecurringPayment({ contact, permission })
127
131
  const dynamicsEntity = recurringPayment.toRequestBody()
128
132
  expect(dynamicsEntity).toMatchObject(
129
133
  expect.objectContaining({
@@ -141,4 +145,29 @@ describe('recurring payment entity', () => {
141
145
  )
142
146
  })
143
147
  })
148
+
149
+ describe('mappings with a nextRecurringPayment', () => {
150
+ it('maps to dynamics', async () => {
151
+ const contact = new Contact()
152
+ const permission = new Permission()
153
+ const nextRecurringPayment = new RecurringPayment()
154
+ const recurringPayment = createRecurringPayment({ contact, permission, nextRecurringPayment })
155
+ const dynamicsEntity = recurringPayment.toRequestBody()
156
+ expect(dynamicsEntity).toMatchObject(
157
+ expect.objectContaining({
158
+ defra_name: 'Test Name',
159
+ defra_nextduedate: '2019-12-14T00:00:00Z',
160
+ defra_cancelleddate: null,
161
+ defra_cancelledreason: null,
162
+ defra_enddate: '2019-12-15T00:00:00Z',
163
+ defra_agreementid: 'c9267c6e-573d-488b-99ab-ea18431fc472',
164
+ defra_publicid: '649-213',
165
+ statecode: 1,
166
+ 'defra_Contact@odata.bind': `$${contact.uniqueContentId}`,
167
+ 'defra_ActivePermission@odata.bind': `$${permission.uniqueContentId}`,
168
+ 'defra_NextRecurringPayment@odata.bind': `$${nextRecurringPayment.uniqueContentId}`
169
+ })
170
+ )
171
+ })
172
+ })
144
173
  })
@@ -23,11 +23,13 @@ export class RecurringPayment extends BaseEntity {
23
23
  agreementId: { field: 'defra_agreementid', type: 'string' },
24
24
  activePermission: { field: '_defra_activepermission_value', type: 'string' },
25
25
  contactId: { field: '_defra_contact_value', type: 'string' },
26
- publicId: { field: 'defra_publicid', type: 'string' }
26
+ publicId: { field: 'defra_publicid', type: 'string' },
27
+ nextRecurringPayment: { field: '_defra_nextrecurringpayment_value', type: 'string' }
27
28
  },
28
29
  relationships: {
29
30
  contact: { property: 'defra_Contact', entity: Contact, parent: true },
30
- activePermission: { property: 'defra_ActivePermission', entity: Permission, parent: true }
31
+ activePermission: { property: 'defra_ActivePermission', entity: Permission, parent: true },
32
+ nextRecurringPayment: { property: 'defra_NextRecurringPayment', entity: RecurringPayment, parent: true }
31
33
  }
32
34
  }))
33
35
 
@@ -22,7 +22,8 @@ describe('Recurring Payment Queries', () => {
22
22
  'defra_agreementid',
23
23
  '_defra_activepermission_value',
24
24
  '_defra_contact_value',
25
- 'defra_publicid'
25
+ 'defra_publicid',
26
+ '_defra_nextrecurringpayment_value'
26
27
  ],
27
28
  expand: [{ property: 'defra_Contact' }, { property: 'defra_ActivePermission' }]
28
29
  })