@defra-fish/dynamics-lib 1.55.0-rc.5 → 1.55.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.55.0
|
|
3
|
+
"version": "1.55.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": "3405322b81a2016ba22e530de8d096a49be0bea4"
|
|
47
47
|
}
|
package/src/index.js
CHANGED
|
@@ -28,7 +28,6 @@ export * from './queries/concession-proof.queries.js'
|
|
|
28
28
|
export * from './queries/pocl-validation-error.queries.js'
|
|
29
29
|
export * from './queries/recurring-payments.queries.js'
|
|
30
30
|
export * from './queries/contact.queries.js'
|
|
31
|
-
export * from './queries/activity.queries.js'
|
|
32
31
|
|
|
33
32
|
// Framework functionality
|
|
34
33
|
export * from './client/util.js'
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { createActivity } from '../activity.queries.js'
|
|
2
|
-
import { dynamicsClient } from '../../client/dynamics-client.js'
|
|
3
|
-
|
|
4
|
-
jest.mock('dynamics-web-api', () => {
|
|
5
|
-
return jest.fn().mockImplementation(() => {
|
|
6
|
-
return {
|
|
7
|
-
executeUnboundAction: jest.fn()
|
|
8
|
-
}
|
|
9
|
-
})
|
|
10
|
-
})
|
|
11
|
-
|
|
12
|
-
describe('Activity Service', () => {
|
|
13
|
-
describe('createActivity', () => {
|
|
14
|
-
const mockResponse = {
|
|
15
|
-
'@odata.context': 'https://dynamics.com/api/data/v9.1/defra_CreateRCRActivityResponse',
|
|
16
|
-
RCRActivityId: 'abc123',
|
|
17
|
-
ReturnStatus: 'success',
|
|
18
|
-
SuccessMessage: 'RCR Activity - created successfully',
|
|
19
|
-
ErrorMessage: null,
|
|
20
|
-
oDataContext: 'https://dynamics.com/api/data/v9.1/defra_CreateRCRActivityResponse'
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
const errorResponse = {
|
|
24
|
-
'@odata.context': 'https://dynamics.com/api/data/v9.1/.defra_CreateRCRActivityResponse',
|
|
25
|
-
RCRActivityId: null,
|
|
26
|
-
ReturnStatus: 'error',
|
|
27
|
-
SuccessMessage: '',
|
|
28
|
-
ErrorMessage: 'Failed to create activity',
|
|
29
|
-
oDataContext: 'https://dynamics.com/api/data/v9.1/$metadata#Microsoft.Dynamics.CRM.defra_CreateRCRActivityResponse'
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
it('should call dynamicsClient with correct parameters', async () => {
|
|
33
|
-
dynamicsClient.executeUnboundAction.mockResolvedValue(mockResponse)
|
|
34
|
-
|
|
35
|
-
await createActivity('contact-identifier-123', 2023)
|
|
36
|
-
|
|
37
|
-
expect(dynamicsClient.executeUnboundAction).toHaveBeenCalledWith('defra_CreateRCRActivity', {
|
|
38
|
-
ContactId: 'contact-identifier-123',
|
|
39
|
-
ActivityStatus: 'STARTED',
|
|
40
|
-
Season: 2023
|
|
41
|
-
})
|
|
42
|
-
})
|
|
43
|
-
|
|
44
|
-
it('should return the CRM response correctly', async () => {
|
|
45
|
-
dynamicsClient.executeUnboundAction.mockResolvedValue(mockResponse)
|
|
46
|
-
|
|
47
|
-
const result = await createActivity('contact-identifier-123', 2024)
|
|
48
|
-
|
|
49
|
-
expect(result).toEqual(mockResponse)
|
|
50
|
-
})
|
|
51
|
-
|
|
52
|
-
it('should handle error in dynamicsClient response', async () => {
|
|
53
|
-
const error = new Error('Failed to create activity')
|
|
54
|
-
dynamicsClient.executeUnboundAction.mockRejectedValue(error)
|
|
55
|
-
|
|
56
|
-
await expect(createActivity('contact-identifier-123', 2024)).rejects.toThrow('Failed to create activity')
|
|
57
|
-
})
|
|
58
|
-
|
|
59
|
-
it('should handle the case where activity creation fails', async () => {
|
|
60
|
-
dynamicsClient.executeUnboundAction.mockResolvedValue(errorResponse)
|
|
61
|
-
|
|
62
|
-
const result = await createActivity('invalid-contact-id', 2024)
|
|
63
|
-
|
|
64
|
-
expect(result).toMatchObject({
|
|
65
|
-
RCRActivityId: null,
|
|
66
|
-
ReturnStatus: 'error',
|
|
67
|
-
SuccessMessage: '',
|
|
68
|
-
ErrorMessage: 'Failed to create activity'
|
|
69
|
-
})
|
|
70
|
-
})
|
|
71
|
-
})
|
|
72
|
-
})
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { dynamicsClient } from '../client/dynamics-client.js'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Creates an RCR Activity in Microsoft Dynamics CRM.
|
|
5
|
-
*
|
|
6
|
-
* @param {string} contactId - The ID of the contact associated with the activity.
|
|
7
|
-
* @param {number} season - The season year for which the activity is being created.
|
|
8
|
-
* @returns {Promise<Object>} - A promise that resolves to the response from Dynamics CRM.
|
|
9
|
-
* @property {string} response.@odata.context - The OData context URL of the response.
|
|
10
|
-
* @property {string} response.RCRActivityId - The unique identifier of the created RCR activity.
|
|
11
|
-
* @property {string} response.ReturnStatus - The status of the activity creation operation (e.g., 'success').
|
|
12
|
-
* @property {string} response.SuccessMessage - A message indicating successful creation of the activity.
|
|
13
|
-
* @property {string|null} response.ErrorMessage - An error message if the activity creation failed, otherwise null.
|
|
14
|
-
* @property {string} response.oDataContext - The OData context URL of the response.
|
|
15
|
-
*/
|
|
16
|
-
export const createActivity = (contactId, season) => {
|
|
17
|
-
const request = {
|
|
18
|
-
ContactId: contactId,
|
|
19
|
-
ActivityStatus: 'STARTED',
|
|
20
|
-
Season: season
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
return dynamicsClient.executeUnboundAction('defra_CreateRCRActivity', request)
|
|
24
|
-
}
|