@defra-fish/dynamics-lib 1.57.0-rc.9 → 1.57.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.57.0
|
|
3
|
+
"version": "1.57.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": "
|
|
46
|
+
"gitHead": "518fbfa16b2b97d78e8d924122344b1f444edfde"
|
|
47
47
|
}
|
|
@@ -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
|
|
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
|
|
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(
|
|
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
|
-
|
|
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(
|
|
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(
|
|
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
|
+
}
|