@defra-fish/dynamics-lib 1.57.0-rc.1 → 1.57.0-rc.11

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.57.0-rc.1",
3
+ "version": "1.57.0-rc.11",
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": "1b6d44f5046f91900083fb0fad5f95e2461c92b5"
46
+ "gitHead": "4f3c85fc04e4e65ecaacd45da2a341b20471f24f"
47
47
  }
@@ -17,8 +17,6 @@ describe('recurring payment entity', () => {
17
17
  recurringPayment.agreementId = 'c9267c6e-573d-488b-99ab-ea18431fc472'
18
18
  recurringPayment.publicId = '649-213'
19
19
  recurringPayment.status = 1
20
- recurringPayment.contactId = 'b3d33cln-2e83-ea11-a811-000d3a649213'
21
- recurringPayment.activePermission = 'a5b24adf-2e83-ea11-a811-000d3a649213'
22
20
 
23
21
  recurringPayment.bindToEntity(RecurringPayment.definition.relationships.contact, contact)
24
22
  recurringPayment.bindToEntity(RecurringPayment.definition.relationships.activePermission, permission)
@@ -66,9 +64,7 @@ describe('recurring payment entity', () => {
66
64
  endDate: '2019-12-15T00:00:00Z',
67
65
  agreementId: 'c9267c6e-573d-488b-99ab-ea18431fc472',
68
66
  publicId: '649-213',
69
- status: 1,
70
- activePermission: 'a5b24adf-2e83-ea11-a811-000d3a649213',
71
- contactId: 'b3d33cln-2e83-ea11-a811-000d3a649213'
67
+ status: 1
72
68
  })
73
69
  )
74
70
  })
@@ -93,8 +89,6 @@ describe('recurring payment entity', () => {
93
89
  defra_agreementid: 'c9267c6e-573d-488b-99ab-ea18431fc472',
94
90
  defra_publicid: '649-213',
95
91
  statecode: 1,
96
- _defra_activepermission_value: 'a5b24adf-2e83-ea11-a811-000d3a649213',
97
- _defra_contact_value: 'b3d33cln-2e83-ea11-a811-000d3a649213',
98
92
  'defra_Contact@odata.bind': `$${contact.uniqueContentId}`,
99
93
  'defra_ActivePermission@odata.bind': `$${permission.uniqueContentId}`
100
94
  })
@@ -121,9 +115,7 @@ describe('recurring payment entity', () => {
121
115
  endDate: '2019-12-15T00:00:00Z',
122
116
  agreementId: 'c9267c6e-573d-488b-99ab-ea18431fc472',
123
117
  publicId: '649-213',
124
- status: 1,
125
- activePermission: 'a5b24adf-2e83-ea11-a811-000d3a649213',
126
- contactId: 'b3d33cln-2e83-ea11-a811-000d3a649213'
118
+ status: 1
127
119
  })
128
120
  )
129
121
  })
@@ -143,8 +135,6 @@ describe('recurring payment entity', () => {
143
135
  defra_agreementid: 'c9267c6e-573d-488b-99ab-ea18431fc472',
144
136
  defra_publicid: '649-213',
145
137
  statecode: 1,
146
- _defra_activepermission_value: 'a5b24adf-2e83-ea11-a811-000d3a649213',
147
- _defra_contact_value: 'b3d33cln-2e83-ea11-a811-000d3a649213',
148
138
  'defra_Contact@odata.bind': `$${contact.uniqueContentId}`,
149
139
  'defra_ActivePermission@odata.bind': `$${permission.uniqueContentId}`
150
140
  })
@@ -134,28 +134,4 @@ export class RecurringPayment extends BaseEntity {
134
134
  set status (status) {
135
135
  super._setState('status', status)
136
136
  }
137
-
138
- /**
139
- * The ID of the associated contact
140
- * @type {string}
141
- */
142
- get contactId () {
143
- return super._getState('contactId')
144
- }
145
-
146
- set contactId (contactId) {
147
- super._setState('contactId', contactId)
148
- }
149
-
150
- /**
151
- * The ID of the associated active permission
152
- * @type {string}
153
- */
154
- get activePermission () {
155
- return super._getState('activePermission')
156
- }
157
-
158
- set activePermission (activePermission) {
159
- super._setState('activePermission', activePermission)
160
- }
161
137
  }
@@ -1,4 +1,4 @@
1
- import { createActivity } from '../activity.queries.js'
1
+ import { createActivity, updateActivity } from '../activity.queries.js'
2
2
  import { dynamicsClient } from '../../client/dynamics-client.js'
3
3
 
4
4
  jest.mock('dynamics-web-api', () => {
@@ -11,26 +11,26 @@ jest.mock('dynamics-web-api', () => {
11
11
 
12
12
  describe('Activity Service', () => {
13
13
  describe('createActivity', () => {
14
- const mockResponse = {
14
+ const getSuccessResponse = () => ({
15
15
  '@odata.context': 'https://dynamics.com/api/data/v9.1/defra_CreateRCRActivityResponse',
16
16
  RCRActivityId: 'abc123',
17
17
  ReturnStatus: 'success',
18
18
  SuccessMessage: 'RCR Activity - created successfully',
19
19
  ErrorMessage: null,
20
20
  oDataContext: 'https://dynamics.com/api/data/v9.1/defra_CreateRCRActivityResponse'
21
- }
21
+ })
22
22
 
23
- const errorResponse = {
23
+ const getErrorResponse = () => ({
24
24
  '@odata.context': 'https://dynamics.com/api/data/v9.1/.defra_CreateRCRActivityResponse',
25
25
  RCRActivityId: null,
26
26
  ReturnStatus: 'error',
27
27
  SuccessMessage: '',
28
28
  ErrorMessage: 'Failed to create activity',
29
29
  oDataContext: 'https://dynamics.com/api/data/v9.1/$metadata#Microsoft.Dynamics.CRM.defra_CreateRCRActivityResponse'
30
- }
30
+ })
31
31
 
32
32
  it('should call dynamicsClient with correct parameters', async () => {
33
- dynamicsClient.executeUnboundAction.mockResolvedValue(mockResponse)
33
+ dynamicsClient.executeUnboundAction.mockResolvedValue(getSuccessResponse())
34
34
 
35
35
  await createActivity('contact-identifier-123', 2023)
36
36
 
@@ -42,11 +42,12 @@ describe('Activity Service', () => {
42
42
  })
43
43
 
44
44
  it('should return the CRM response correctly', async () => {
45
- dynamicsClient.executeUnboundAction.mockResolvedValue(mockResponse)
45
+ const successResponse = getSuccessResponse()
46
+ dynamicsClient.executeUnboundAction.mockResolvedValue(successResponse)
46
47
 
47
48
  const result = await createActivity('contact-identifier-123', 2024)
48
49
 
49
- expect(result).toEqual(mockResponse)
50
+ expect(result).toEqual(successResponse)
50
51
  })
51
52
 
52
53
  it('should handle error in dynamicsClient response', async () => {
@@ -57,7 +58,7 @@ describe('Activity Service', () => {
57
58
  })
58
59
 
59
60
  it('should handle the case where activity creation fails', async () => {
60
- dynamicsClient.executeUnboundAction.mockResolvedValue(errorResponse)
61
+ dynamicsClient.executeUnboundAction.mockResolvedValue(getErrorResponse())
61
62
 
62
63
  const result = await createActivity('invalid-contact-id', 2024)
63
64
 
@@ -69,4 +70,64 @@ describe('Activity Service', () => {
69
70
  })
70
71
  })
71
72
  })
73
+
74
+ describe('updateActivity', () => {
75
+ const getSuccessResponse = () => ({
76
+ '@odata.context': 'https://dynamics.om/api/data/v9.1/defra_UpdateRCRActivityResponse',
77
+ ReturnStatus: 'success',
78
+ SuccessMessage: 'RCR Activity - updated successfully',
79
+ ErrorMessage: null,
80
+ oDataContext: 'https://dynamics.com/api/data/v9.1/defra_UpdateRCRActivityResponse'
81
+ })
82
+
83
+ const getErrorResponse = () => ({
84
+ '@odata.context': 'https://dynamics.om/api/data/v9.1/defra_UpdateRCRActivityResponse',
85
+ RCRActivityId: null,
86
+ ReturnStatus: 'error',
87
+ SuccessMessage: '',
88
+ ErrorMessage: 'Failed to update activity',
89
+ oDataContext: 'https://dynamics.com/api/data/v9.1/defra_UpdateRCRActivityResponse'
90
+ })
91
+
92
+ it('should call dynamicsClient with correct parameters', async () => {
93
+ dynamicsClient.executeUnboundAction.mockResolvedValue(getSuccessResponse())
94
+
95
+ await updateActivity('contact-identifier-123', 2023)
96
+
97
+ expect(dynamicsClient.executeUnboundAction).toHaveBeenCalledWith('defra_UpdateRCRActivity', {
98
+ ContactId: 'contact-identifier-123',
99
+ ActivityStatus: 'SUBMITTED',
100
+ Season: 2023
101
+ })
102
+ })
103
+
104
+ it('should return the CRM response correctly', async () => {
105
+ const successResponse = getSuccessResponse()
106
+ dynamicsClient.executeUnboundAction.mockResolvedValue(successResponse)
107
+
108
+ const result = await updateActivity('contact-identifier-123', 2024)
109
+
110
+ expect(result).toEqual(successResponse)
111
+ })
112
+
113
+ it('should handle error in dynamicsClient response', async () => {
114
+ const error = new Error('Failed to update activity')
115
+ dynamicsClient.executeUnboundAction.mockRejectedValue(error)
116
+
117
+ await expect(updateActivity('contact-identifier-123', 2024)).rejects.toThrow('Failed to update activity')
118
+ })
119
+
120
+ it('should handle the case where activity creation fails', async () => {
121
+ dynamicsClient.executeUnboundAction.mockResolvedValue(getErrorResponse())
122
+
123
+ const result = await updateActivity('invalid-contact-id', 2024)
124
+
125
+ expect(result).toMatchObject({
126
+ RCRActivityId: null,
127
+ ReturnStatus: 'error',
128
+ SuccessMessage: '',
129
+ ErrorMessage: 'Failed to update activity'
130
+ })
131
+ })
132
+ })
72
133
  })
@@ -22,3 +22,26 @@ export const createActivity = (contactId, season) => {
22
22
 
23
23
  return dynamicsClient.executeUnboundAction('defra_CreateRCRActivity', request)
24
24
  }
25
+
26
+ /**
27
+ * Updates an RCR Activity in Microsoft Dynamics CRM.
28
+ *
29
+ * @param {string} contactId - The ID of the contact associated with the activity.
30
+ * @param {number} season - The season year for which the activity is being created.
31
+ * @returns {Promise<Object>} - A promise that resolves to the response from Dynamics CRM.
32
+ * @property {string} response.@odata.context - The OData context URL of the response.
33
+ * @property {string} response.RCRActivityId - The unique identifier of the created RCR activity.
34
+ * @property {string} response.ReturnStatus - The status of the activity creation operation (e.g., 'success').
35
+ * @property {string} response.SuccessMessage - A message indicating successful creation of the activity.
36
+ * @property {string|null} response.ErrorMessage - An error message if the activity creation failed, otherwise null.
37
+ * @property {string} response.oDataContext - The OData context URL of the response.
38
+ */
39
+ export const updateActivity = (contactId, season) => {
40
+ const request = {
41
+ ContactId: contactId,
42
+ ActivityStatus: 'SUBMITTED',
43
+ Season: season
44
+ }
45
+
46
+ return dynamicsClient.executeUnboundAction('defra_UpdateRCRActivity', request)
47
+ }