@hubspot/ui-extensions 0.11.1 → 0.11.3
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/dist/__tests__/crm/hooks/useAssociations.spec.js +36 -32
- package/dist/__tests__/crm/hooks/useCrmProperties.spec.js +20 -19
- package/dist/__tests__/crm/utils/fetchAssociations.spec.js +13 -12
- package/dist/__tests__/crm/utils/fetchCrmProperties.spec.js +38 -37
- package/dist/clientTypes.d.ts +1 -0
- package/dist/clientTypes.js +1 -1
- package/dist/crm/hooks/useAssociations.d.ts +5 -3
- package/dist/crm/hooks/useAssociations.js +4 -2
- package/dist/crm/hooks/useCrmProperties.d.ts +4 -2
- package/dist/crm/hooks/useCrmProperties.js +4 -2
- package/dist/crm/index.d.ts +4 -4
- package/dist/crm/index.js +3 -3
- package/dist/crm/utils/fetchAssociations.d.ts +1 -1
- package/dist/experimental/index.d.ts +4 -4
- package/dist/experimental/index.js +3 -3
- package/dist/experimental/testing/__tests__/createRenderer.spec.js +23 -0
- package/dist/experimental/testing/__tests__/debug.spec.js +57 -0
- package/dist/experimental/testing/__tests__/find.spec.js +48 -0
- package/dist/experimental/testing/__tests__/findAll.spec.js +13 -0
- package/dist/experimental/testing/__tests__/findAllChildren.spec.js +54 -0
- package/dist/experimental/testing/__tests__/findByTestId.spec.js +126 -0
- package/dist/experimental/testing/__tests__/findChild.spec.js +33 -0
- package/dist/experimental/testing/__tests__/fragments.spec.js +66 -0
- package/dist/experimental/testing/__tests__/invalid-components.spec.js +96 -0
- package/dist/experimental/testing/__tests__/isMatch.spec.js +113 -0
- package/dist/experimental/testing/__tests__/logger.spec.js +10 -0
- package/dist/experimental/testing/__tests__/maybeFind.spec.js +67 -0
- package/dist/experimental/testing/__tests__/maybeFindByTestId.spec.js +65 -0
- package/dist/experimental/testing/__tests__/maybeFindChild.spec.js +75 -0
- package/dist/experimental/testing/__tests__/mocks.actions.spec.js +19 -0
- package/dist/experimental/testing/__tests__/mocks.context.spec.js +24 -0
- package/dist/experimental/testing/__tests__/mocks.runServerlessFunction.spec.js +35 -0
- package/dist/experimental/testing/__tests__/mocks.useAssociations.spec.js +47 -0
- package/dist/experimental/testing/__tests__/mocks.useCrmProperties.spec.js +58 -0
- package/dist/experimental/testing/__tests__/props.spec.js +13 -0
- package/dist/experimental/testing/__tests__/testId.spec.js +18 -0
- package/dist/experimental/testing/__tests__/trigger.spec.js +43 -0
- package/dist/experimental/testing/__tests__/type-utils.spec.js +165 -0
- package/dist/experimental/testing/__tests__/waitFor.spec.js +57 -0
- package/dist/experimental/testing/index.d.ts +4 -0
- package/dist/experimental/testing/index.js +4 -0
- package/dist/experimental/testing/internal/constants.d.ts +2 -2
- package/dist/experimental/testing/internal/constants.js +1 -1
- package/dist/experimental/testing/internal/convert.d.ts +10 -0
- package/dist/experimental/testing/internal/convert.js +149 -0
- package/dist/experimental/testing/internal/debug.d.ts +3 -3
- package/dist/experimental/testing/internal/debug.js +12 -4
- package/dist/experimental/testing/internal/document.d.ts +14 -0
- package/dist/experimental/testing/internal/document.js +40 -0
- package/dist/experimental/testing/internal/element.d.ts +4 -3
- package/dist/experimental/testing/internal/element.js +15 -10
- package/dist/experimental/testing/internal/errors.d.ts +57 -2
- package/dist/experimental/testing/internal/errors.js +62 -2
- package/dist/experimental/testing/internal/fragment.d.ts +3 -2
- package/dist/experimental/testing/internal/fragment.js +13 -9
- package/dist/experimental/testing/internal/match.d.ts +10 -0
- package/dist/experimental/testing/internal/match.js +19 -0
- package/dist/experimental/testing/internal/mocks/index.d.ts +17 -0
- package/dist/experimental/testing/internal/mocks/index.js +46 -0
- package/dist/experimental/testing/internal/mocks/mock-extension-point-api.d.ts +2 -0
- package/dist/experimental/testing/internal/mocks/mock-extension-point-api.js +166 -0
- package/dist/experimental/testing/internal/mocks/mock-hooks.d.ts +2 -0
- package/dist/experimental/testing/internal/mocks/mock-hooks.js +59 -0
- package/dist/experimental/testing/internal/print.d.ts +2 -2
- package/dist/experimental/testing/internal/print.js +17 -11
- package/dist/experimental/testing/internal/query.d.ts +19 -9
- package/dist/experimental/testing/internal/query.js +91 -46
- package/dist/experimental/testing/internal/root.d.ts +1 -1
- package/dist/experimental/testing/internal/root.js +12 -8
- package/dist/experimental/testing/internal/text.d.ts +3 -2
- package/dist/experimental/testing/internal/text.js +12 -3
- package/dist/experimental/testing/internal/type-utils-internal.d.ts +44 -0
- package/dist/experimental/testing/internal/type-utils-internal.js +54 -0
- package/dist/experimental/testing/internal/types-internal.d.ts +20 -2
- package/dist/experimental/testing/internal/utils/promise-utils.d.ts +14 -0
- package/dist/experimental/testing/internal/utils/promise-utils.js +14 -0
- package/dist/experimental/testing/render.d.ts +35 -0
- package/dist/experimental/testing/render.js +219 -0
- package/dist/experimental/testing/type-utils.d.ts +2 -2
- package/dist/experimental/testing/type-utils.js +1 -1
- package/dist/experimental/testing/types.d.ts +127 -9
- package/dist/experimental/testing/utils.d.ts +11 -0
- package/dist/experimental/testing/utils.js +24 -0
- package/dist/hubspot.d.ts +2 -4
- package/dist/hubspot.js +3 -3
- package/dist/index.d.ts +5 -5
- package/dist/index.js +5 -5
- package/dist/internal/global-utils.d.ts +6 -0
- package/dist/internal/global-utils.js +37 -0
- package/dist/internal/hook-utils.d.ts +19 -0
- package/dist/internal/hook-utils.js +34 -0
- package/dist/logger.d.ts +1 -8
- package/dist/logger.js +3 -2
- package/dist/pages/home/index.d.ts +1 -1
- package/dist/pages/home/index.js +1 -1
- package/dist/{__synced__/remoteComponents.synced.d.ts → shared/remoteComponents.d.ts} +159 -77
- package/dist/{__synced__/remoteComponents.synced.js → shared/remoteComponents.js} +99 -1
- package/dist/{__synced__/types/components/accordion.synced.d.ts → shared/types/components/accordion.d.ts} +2 -2
- package/dist/{__synced__/types/components/alert.synced.d.ts → shared/types/components/alert.d.ts} +2 -1
- package/dist/{__synced__/types/components/app-home-header-actions.synced.d.ts → shared/types/components/app-home-header-actions.d.ts} +4 -4
- package/dist/{__synced__/types/components/button-row.synced.d.ts → shared/types/components/button-row.d.ts} +2 -2
- package/dist/{__synced__/types/components/button.synced.d.ts → shared/types/components/button.d.ts} +9 -3
- package/dist/{__synced__/types/components/card.synced.d.ts → shared/types/components/card.d.ts} +2 -1
- package/dist/{__synced__/types/components/chart.synced.d.ts → shared/types/components/chart.d.ts} +2 -1
- package/dist/{__synced__/types/components/description-list.synced.d.ts → shared/types/components/description-list.d.ts} +3 -2
- package/dist/{__synced__/types/components/divider.synced.d.ts → shared/types/components/divider.d.ts} +2 -2
- package/dist/{__synced__/types/components/dropdown.synced.d.ts → shared/types/components/dropdown.d.ts} +5 -5
- package/dist/{__synced__/types/components/empty-state.synced.d.ts → shared/types/components/empty-state.d.ts} +2 -1
- package/dist/{__synced__/types/components/error-state.synced.d.ts → shared/types/components/error-state.d.ts} +2 -1
- package/dist/{__synced__/types/components/form.synced.d.ts → shared/types/components/form.d.ts} +3 -3
- package/dist/{__synced__/types/components/heading.synced.d.ts → shared/types/components/heading.d.ts} +2 -1
- package/dist/{__synced__/types/components/icon.synced.d.ts → shared/types/components/icon.d.ts} +2 -2
- package/dist/{__synced__/types/components/iframe.synced.d.ts → shared/types/components/iframe.d.ts} +2 -2
- package/dist/{__synced__/types/components/illustration.synced.d.ts → shared/types/components/illustration.d.ts} +2 -1
- package/dist/{__synced__/types/components/image.synced.d.ts → shared/types/components/image.d.ts} +3 -3
- package/dist/shared/types/components/index.d.ts +38 -0
- package/dist/shared/types/components/index.js +1 -0
- package/dist/{__synced__/types/components/inputs.synced.d.ts → shared/types/components/inputs.d.ts} +2 -1
- package/dist/shared/types/components/inputs.js +1 -0
- package/dist/{__synced__/types/components/layouts.synced.d.ts → shared/types/components/layouts.d.ts} +6 -6
- package/dist/shared/types/components/layouts.js +1 -0
- package/dist/{__synced__/types/components/link.synced.d.ts → shared/types/components/link.d.ts} +3 -3
- package/dist/shared/types/components/link.js +1 -0
- package/dist/{__synced__/types/components/list.synced.d.ts → shared/types/components/list.d.ts} +2 -1
- package/dist/shared/types/components/list.js +1 -0
- package/dist/{__synced__/types/components/loading-spinner.synced.d.ts → shared/types/components/loading-spinner.d.ts} +2 -2
- package/dist/shared/types/components/loading-spinner.js +1 -0
- package/dist/{__synced__/types/components/modal.synced.d.ts → shared/types/components/modal.d.ts} +4 -4
- package/dist/shared/types/components/modal.js +1 -0
- package/dist/{__synced__/types/components/panel.synced.d.ts → shared/types/components/panel.d.ts} +5 -5
- package/dist/shared/types/components/panel.js +1 -0
- package/dist/{__synced__/types/components/progress-bar.synced.d.ts → shared/types/components/progress-bar.d.ts} +2 -1
- package/dist/shared/types/components/progress-bar.js +1 -0
- package/dist/{__synced__/types/components/selects.synced.d.ts → shared/types/components/selects.d.ts} +2 -1
- package/dist/shared/types/components/selects.js +1 -0
- package/dist/{__synced__/types/components/statistics.synced.d.ts → shared/types/components/statistics.d.ts} +4 -3
- package/dist/shared/types/components/statistics.js +1 -0
- package/dist/{__synced__/types/components/status-tag.synced.d.ts → shared/types/components/status-tag.d.ts} +2 -1
- package/dist/shared/types/components/status-tag.js +1 -0
- package/dist/{__synced__/types/components/step-indicator.synced.d.ts → shared/types/components/step-indicator.d.ts} +2 -2
- package/dist/shared/types/components/step-indicator.js +1 -0
- package/dist/{__synced__/types/components/table.synced.d.ts → shared/types/components/table.d.ts} +5 -4
- package/dist/shared/types/components/table.js +1 -0
- package/dist/{__synced__/types/components/tabs.synced.d.ts → shared/types/components/tabs.d.ts} +3 -2
- package/dist/shared/types/components/tabs.js +1 -0
- package/dist/{__synced__/types/components/tag.synced.d.ts → shared/types/components/tag.d.ts} +3 -3
- package/dist/shared/types/components/tag.js +1 -0
- package/dist/{__synced__/types/components/text.synced.d.ts → shared/types/components/text.d.ts} +2 -1
- package/dist/shared/types/components/text.js +1 -0
- package/dist/{__synced__/types/components/tile.synced.d.ts → shared/types/components/tile.d.ts} +2 -1
- package/dist/shared/types/components/tile.js +1 -0
- package/dist/{__synced__/types/components/toggle.synced.d.ts → shared/types/components/toggle.d.ts} +2 -2
- package/dist/shared/types/components/toggle.js +1 -0
- package/dist/{__synced__/types/components/toggleInputs.synced.d.ts → shared/types/components/toggleInputs.d.ts} +4 -4
- package/dist/shared/types/components/toggleInputs.js +1 -0
- package/dist/{__synced__/types/components/tooltip.synced.d.ts → shared/types/components/tooltip.d.ts} +2 -1
- package/dist/shared/types/components/tooltip.js +1 -0
- package/dist/{__synced__/types/context.synced.d.ts → shared/types/context.d.ts} +1 -1
- package/dist/shared/types/context.js +1 -0
- package/dist/{__synced__/types/crm.synced.d.ts → shared/types/crm.d.ts} +13 -13
- package/dist/shared/types/crm.js +1 -0
- package/dist/{__synced__/experimental/types.synced.d.ts → shared/types/experimental.d.ts} +12 -17
- package/dist/shared/types/experimental.js +1 -0
- package/dist/shared/types/extend.d.ts +4 -0
- package/dist/shared/types/extend.js +1 -0
- package/dist/{__synced__/types/extension-points.synced.d.ts → shared/types/extension-points.d.ts} +18 -10
- package/dist/{__synced__/types/http-requests.synced.d.ts → shared/types/http-requests.d.ts} +1 -1
- package/dist/shared/types/index.d.ts +8 -0
- package/dist/shared/types/index.js +1 -0
- package/dist/shared/types/logger.d.ts +7 -0
- package/dist/shared/types/logger.js +1 -0
- package/dist/shared/types/reactions.js +1 -0
- package/dist/{__synced__/types/shared.synced.d.ts → shared/types/shared.d.ts} +3 -0
- package/dist/shared/types/worker-globals.d.ts +17 -0
- package/dist/shared/types/worker-globals.js +1 -0
- package/dist/{__synced__/utils/remote-component-registry.synced.d.ts → shared/utils/remote-component-registry.d.ts} +1 -1
- package/dist/{__synced__/utils/remote-component-registry.synced.js → shared/utils/remote-component-registry.js} +0 -1
- package/package.json +13 -14
- package/dist/__synced__/appHomeRemoteComponents.synced.d.ts +0 -28
- package/dist/__synced__/appHomeRemoteComponents.synced.js +0 -21
- package/dist/__synced__/crmRemoteComponents.synced.d.ts +0 -66
- package/dist/__synced__/crmRemoteComponents.synced.js +0 -15
- package/dist/__synced__/experimental/types.synced.js +0 -5
- package/dist/__synced__/experimentalRemoteComponents.synced.d.ts +0 -94
- package/dist/__synced__/experimentalRemoteComponents.synced.js +0 -56
- package/dist/__synced__/types/components/index.synced.d.ts +0 -38
- package/dist/__synced__/types/index.synced.d.ts +0 -8
- package/dist/__synced__/types/index.synced.js +0 -1
- /package/dist/{__synced__/types/actions.synced.js → experimental/testing/__tests__/createRenderer.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/accordion.synced.js → experimental/testing/__tests__/debug.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/alert.synced.js → experimental/testing/__tests__/find.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/app-home-header-actions.synced.js → experimental/testing/__tests__/findAll.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/button-row.synced.js → experimental/testing/__tests__/findAllChildren.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/button.synced.js → experimental/testing/__tests__/findByTestId.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/card.synced.js → experimental/testing/__tests__/findChild.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/description-list.synced.js → experimental/testing/__tests__/fragments.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/divider.synced.js → experimental/testing/__tests__/invalid-components.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/dropdown.synced.js → experimental/testing/__tests__/isMatch.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/empty-state.synced.js → experimental/testing/__tests__/logger.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/error-state.synced.js → experimental/testing/__tests__/maybeFind.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/form.synced.js → experimental/testing/__tests__/maybeFindByTestId.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/heading.synced.js → experimental/testing/__tests__/maybeFindChild.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/icon.synced.js → experimental/testing/__tests__/mocks.actions.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/iframe.synced.js → experimental/testing/__tests__/mocks.context.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/image.synced.js → experimental/testing/__tests__/mocks.runServerlessFunction.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/index.synced.js → experimental/testing/__tests__/mocks.useAssociations.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/inputs.synced.js → experimental/testing/__tests__/mocks.useCrmProperties.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/layouts.synced.js → experimental/testing/__tests__/props.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/link.synced.js → experimental/testing/__tests__/testId.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/list.synced.js → experimental/testing/__tests__/trigger.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/loading-spinner.synced.js → experimental/testing/__tests__/type-utils.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/components/modal.synced.js → experimental/testing/__tests__/waitFor.spec.d.ts} +0 -0
- /package/dist/{__synced__/types/actions.synced.d.ts → shared/types/actions.d.ts} +0 -0
- /package/dist/{__synced__/types/components/panel.synced.js → shared/types/actions.js} +0 -0
- /package/dist/{__synced__/types/components/progress-bar.synced.js → shared/types/components/accordion.js} +0 -0
- /package/dist/{__synced__/types/components/selects.synced.js → shared/types/components/alert.js} +0 -0
- /package/dist/{__synced__/types/components/statistics.synced.js → shared/types/components/app-home-header-actions.js} +0 -0
- /package/dist/{__synced__/types/components/status-tag.synced.js → shared/types/components/button-row.js} +0 -0
- /package/dist/{__synced__/types/components/step-indicator.synced.js → shared/types/components/button.js} +0 -0
- /package/dist/{__synced__/types/components/table.synced.js → shared/types/components/card.js} +0 -0
- /package/dist/{__synced__/types/components/chart.synced.js → shared/types/components/chart.js} +0 -0
- /package/dist/{__synced__/types/components/tabs.synced.js → shared/types/components/description-list.js} +0 -0
- /package/dist/{__synced__/types/components/tag.synced.js → shared/types/components/divider.js} +0 -0
- /package/dist/{__synced__/types/components/text.synced.js → shared/types/components/dropdown.js} +0 -0
- /package/dist/{__synced__/types/components/tile.synced.js → shared/types/components/empty-state.js} +0 -0
- /package/dist/{__synced__/types/components/toggle.synced.js → shared/types/components/error-state.js} +0 -0
- /package/dist/{__synced__/types/components/toggleInputs.synced.js → shared/types/components/form.js} +0 -0
- /package/dist/{__synced__/types/components/tooltip.synced.js → shared/types/components/heading.js} +0 -0
- /package/dist/{__synced__/types/context.synced.js → shared/types/components/icon.js} +0 -0
- /package/dist/{__synced__/types/crm.synced.js → shared/types/components/iframe.js} +0 -0
- /package/dist/{__synced__/types/components/illustration.synced.js → shared/types/components/illustration.js} +0 -0
- /package/dist/{__synced__/types/reactions.synced.js → shared/types/components/image.js} +0 -0
- /package/dist/{__synced__/types/extension-points.synced.js → shared/types/extension-points.js} +0 -0
- /package/dist/{__synced__/types/http-requests.synced.js → shared/types/http-requests.js} +0 -0
- /package/dist/{__synced__/types/reactions.synced.d.ts → shared/types/reactions.d.ts} +0 -0
- /package/dist/{__synced__/types/shared.synced.js → shared/types/shared.js} +0 -0
|
@@ -1,20 +1,24 @@
|
|
|
1
1
|
import { renderHook, waitFor } from '@testing-library/react';
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { vi } from 'vitest';
|
|
3
|
+
import { useAssociations } from "../../../crm/hooks/useAssociations.js";
|
|
4
|
+
import { fetchAssociations } from "../../../crm/utils/fetchAssociations.js";
|
|
4
5
|
// Mock the logger module
|
|
5
|
-
|
|
6
|
+
vi.mock('../../../logger', () => ({
|
|
6
7
|
logger: {
|
|
7
|
-
debug:
|
|
8
|
-
info:
|
|
9
|
-
warn:
|
|
10
|
-
error:
|
|
8
|
+
debug: vi.fn(),
|
|
9
|
+
info: vi.fn(),
|
|
10
|
+
warn: vi.fn(),
|
|
11
|
+
error: vi.fn(),
|
|
11
12
|
},
|
|
12
13
|
}));
|
|
13
14
|
// Mock the fetchAssociations function, keep utility functions
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
15
|
+
vi.mock('../../../crm/utils/fetchAssociations.ts', async (importOriginal) => {
|
|
16
|
+
const actual = (await importOriginal());
|
|
17
|
+
return {
|
|
18
|
+
...actual,
|
|
19
|
+
fetchAssociations: vi.fn(),
|
|
20
|
+
};
|
|
21
|
+
});
|
|
18
22
|
// Get reference to the mocked function
|
|
19
23
|
const mockFetchAssociations = fetchAssociations;
|
|
20
24
|
describe('useAssociations with Pagination', () => {
|
|
@@ -45,7 +49,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
45
49
|
hasMore: false,
|
|
46
50
|
nextOffset: 0,
|
|
47
51
|
},
|
|
48
|
-
cleanup:
|
|
52
|
+
cleanup: vi.fn(),
|
|
49
53
|
});
|
|
50
54
|
const { result } = renderHook(() => useAssociations({
|
|
51
55
|
toObjectType: '0-1',
|
|
@@ -69,7 +73,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
69
73
|
hasMore: false,
|
|
70
74
|
nextOffset: 0,
|
|
71
75
|
},
|
|
72
|
-
cleanup:
|
|
76
|
+
cleanup: vi.fn(),
|
|
73
77
|
});
|
|
74
78
|
const { result } = renderHook(() => useAssociations({
|
|
75
79
|
toObjectType: '0-1',
|
|
@@ -99,7 +103,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
99
103
|
hasMore: true,
|
|
100
104
|
nextOffset: 10,
|
|
101
105
|
},
|
|
102
|
-
cleanup:
|
|
106
|
+
cleanup: vi.fn(),
|
|
103
107
|
});
|
|
104
108
|
const { result } = renderHook(() => useAssociations({
|
|
105
109
|
toObjectType: '0-1',
|
|
@@ -128,7 +132,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
128
132
|
hasMore: false,
|
|
129
133
|
nextOffset: 0,
|
|
130
134
|
},
|
|
131
|
-
cleanup:
|
|
135
|
+
cleanup: vi.fn(),
|
|
132
136
|
});
|
|
133
137
|
const { result } = renderHook(() => useAssociations({
|
|
134
138
|
toObjectType: '0-1',
|
|
@@ -153,7 +157,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
153
157
|
hasMore: true,
|
|
154
158
|
nextOffset: 10,
|
|
155
159
|
},
|
|
156
|
-
cleanup:
|
|
160
|
+
cleanup: vi.fn(),
|
|
157
161
|
});
|
|
158
162
|
// Second page response
|
|
159
163
|
mockFetchAssociations.mockResolvedValueOnce({
|
|
@@ -162,7 +166,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
162
166
|
hasMore: false,
|
|
163
167
|
nextOffset: 20,
|
|
164
168
|
},
|
|
165
|
-
cleanup:
|
|
169
|
+
cleanup: vi.fn(),
|
|
166
170
|
});
|
|
167
171
|
const { result } = renderHook(() => useAssociations({
|
|
168
172
|
toObjectType: '0-1',
|
|
@@ -193,7 +197,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
193
197
|
hasMore: true,
|
|
194
198
|
nextOffset: 10,
|
|
195
199
|
},
|
|
196
|
-
cleanup:
|
|
200
|
+
cleanup: vi.fn(),
|
|
197
201
|
});
|
|
198
202
|
// Second call: page 2 with hasMore: false
|
|
199
203
|
mockFetchAssociations.mockResolvedValueOnce({
|
|
@@ -202,7 +206,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
202
206
|
hasMore: false,
|
|
203
207
|
nextOffset: 20,
|
|
204
208
|
},
|
|
205
|
-
cleanup:
|
|
209
|
+
cleanup: vi.fn(),
|
|
206
210
|
});
|
|
207
211
|
// Third call: back to page 1
|
|
208
212
|
mockFetchAssociations.mockResolvedValueOnce({
|
|
@@ -211,7 +215,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
211
215
|
hasMore: true,
|
|
212
216
|
nextOffset: 10,
|
|
213
217
|
},
|
|
214
|
-
cleanup:
|
|
218
|
+
cleanup: vi.fn(),
|
|
215
219
|
});
|
|
216
220
|
const { result } = renderHook(() => useAssociations({
|
|
217
221
|
toObjectType: '0-1',
|
|
@@ -243,7 +247,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
243
247
|
hasMore: true,
|
|
244
248
|
nextOffset: 10,
|
|
245
249
|
},
|
|
246
|
-
cleanup:
|
|
250
|
+
cleanup: vi.fn(),
|
|
247
251
|
});
|
|
248
252
|
const { result } = renderHook(() => useAssociations({
|
|
249
253
|
toObjectType: '0-1',
|
|
@@ -274,10 +278,10 @@ describe('useAssociations with Pagination', () => {
|
|
|
274
278
|
mockFetchAssociations.mockResolvedValue({
|
|
275
279
|
data: {
|
|
276
280
|
results: [],
|
|
277
|
-
hasMore: false,
|
|
281
|
+
hasMore: false, // No more pages
|
|
278
282
|
nextOffset: 10,
|
|
279
283
|
},
|
|
280
|
-
cleanup:
|
|
284
|
+
cleanup: vi.fn(),
|
|
281
285
|
});
|
|
282
286
|
const { result } = renderHook(() => useAssociations({
|
|
283
287
|
toObjectType: '0-1',
|
|
@@ -320,7 +324,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
320
324
|
hasMore: false,
|
|
321
325
|
nextOffset: 0,
|
|
322
326
|
},
|
|
323
|
-
cleanup:
|
|
327
|
+
cleanup: vi.fn(),
|
|
324
328
|
});
|
|
325
329
|
// @ts-expect-error - intentional type issue to check the failure state
|
|
326
330
|
const { result } = renderHook(() => useAssociations(null));
|
|
@@ -343,7 +347,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
343
347
|
hasMore: false,
|
|
344
348
|
nextOffset: 0,
|
|
345
349
|
},
|
|
346
|
-
cleanup:
|
|
350
|
+
cleanup: vi.fn(),
|
|
347
351
|
});
|
|
348
352
|
// @ts-expect-error - intentional type issue to check the failure state
|
|
349
353
|
const { result } = renderHook(() => useAssociations(undefined));
|
|
@@ -366,7 +370,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
366
370
|
hasMore: false,
|
|
367
371
|
nextOffset: 0,
|
|
368
372
|
},
|
|
369
|
-
cleanup:
|
|
373
|
+
cleanup: vi.fn(),
|
|
370
374
|
});
|
|
371
375
|
// @ts-expect-error - intentional type issue to check the failure state
|
|
372
376
|
const { result } = renderHook(() => useAssociations({}));
|
|
@@ -389,7 +393,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
389
393
|
hasMore: false,
|
|
390
394
|
nextOffset: 0,
|
|
391
395
|
},
|
|
392
|
-
cleanup:
|
|
396
|
+
cleanup: vi.fn(),
|
|
393
397
|
});
|
|
394
398
|
const { result } = renderHook(() =>
|
|
395
399
|
// @ts-expect-error - intentional type issue to check the failure state
|
|
@@ -415,7 +419,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
415
419
|
hasMore: false,
|
|
416
420
|
nextOffset: 0,
|
|
417
421
|
},
|
|
418
|
-
cleanup:
|
|
422
|
+
cleanup: vi.fn(),
|
|
419
423
|
});
|
|
420
424
|
const { result } = renderHook(() => useAssociations({
|
|
421
425
|
toObjectType: '0-1',
|
|
@@ -441,7 +445,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
441
445
|
hasMore: false,
|
|
442
446
|
nextOffset: 0,
|
|
443
447
|
},
|
|
444
|
-
cleanup:
|
|
448
|
+
cleanup: vi.fn(),
|
|
445
449
|
});
|
|
446
450
|
const config = {
|
|
447
451
|
toObjectType: '0-1',
|
|
@@ -469,7 +473,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
469
473
|
hasMore: false,
|
|
470
474
|
nextOffset: 0,
|
|
471
475
|
},
|
|
472
|
-
cleanup:
|
|
476
|
+
cleanup: vi.fn(),
|
|
473
477
|
});
|
|
474
478
|
const config = {
|
|
475
479
|
toObjectType: '0-1',
|
|
@@ -484,7 +488,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
484
488
|
});
|
|
485
489
|
describe('lifecycle management', () => {
|
|
486
490
|
it('should call cleanup function on unmount', async () => {
|
|
487
|
-
const mockCleanup =
|
|
491
|
+
const mockCleanup = vi.fn();
|
|
488
492
|
mockFetchAssociations.mockResolvedValue({
|
|
489
493
|
data: {
|
|
490
494
|
results: [],
|
|
@@ -514,7 +518,7 @@ describe('useAssociations with Pagination', () => {
|
|
|
514
518
|
hasMore: false,
|
|
515
519
|
nextOffset: 0,
|
|
516
520
|
},
|
|
517
|
-
cleanup:
|
|
521
|
+
cleanup: vi.fn(),
|
|
518
522
|
});
|
|
519
523
|
const config = {
|
|
520
524
|
toObjectType: '0-1',
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
import { renderHook, waitFor } from '@testing-library/react';
|
|
2
|
-
import {
|
|
2
|
+
import { vi } from 'vitest';
|
|
3
|
+
import { useCrmProperties } from "../../../crm/hooks/useCrmProperties.js";
|
|
4
|
+
import * as fetchCrmPropertiesModule from "../../../crm/utils/fetchCrmProperties.js";
|
|
3
5
|
// Mock the logger module
|
|
4
|
-
|
|
6
|
+
vi.mock('../../../logger', () => ({
|
|
5
7
|
logger: {
|
|
6
|
-
debug:
|
|
7
|
-
info:
|
|
8
|
-
warn:
|
|
9
|
-
error:
|
|
8
|
+
debug: vi.fn(),
|
|
9
|
+
info: vi.fn(),
|
|
10
|
+
warn: vi.fn(),
|
|
11
|
+
error: vi.fn(),
|
|
10
12
|
},
|
|
11
13
|
}));
|
|
12
14
|
// Mock the fetchCrmProperties module
|
|
13
|
-
|
|
14
|
-
const mockFetchCrmProperties =
|
|
15
|
-
import * as fetchCrmPropertiesModule from '../../../crm/utils/fetchCrmProperties';
|
|
15
|
+
vi.mock('../../../crm/utils/fetchCrmProperties');
|
|
16
|
+
const mockFetchCrmProperties = vi.fn();
|
|
16
17
|
fetchCrmPropertiesModule.fetchCrmProperties = mockFetchCrmProperties;
|
|
17
18
|
describe('useCrmProperties', () => {
|
|
18
19
|
let originalError;
|
|
@@ -46,7 +47,7 @@ describe('useCrmProperties', () => {
|
|
|
46
47
|
firstname: 'Test value for firstname',
|
|
47
48
|
lastname: 'Test value for lastname',
|
|
48
49
|
},
|
|
49
|
-
cleanup:
|
|
50
|
+
cleanup: vi.fn(),
|
|
50
51
|
});
|
|
51
52
|
const propertyNames = ['firstname', 'lastname'];
|
|
52
53
|
const { result } = renderHook(() => useCrmProperties(propertyNames));
|
|
@@ -78,7 +79,7 @@ describe('useCrmProperties', () => {
|
|
|
78
79
|
capturedCallback = propertiesUpdatedCallback;
|
|
79
80
|
return {
|
|
80
81
|
data: { firstname: 'Initial', lastname: 'Initial' },
|
|
81
|
-
cleanup:
|
|
82
|
+
cleanup: vi.fn(),
|
|
82
83
|
};
|
|
83
84
|
});
|
|
84
85
|
const propertyNames = ['firstname', 'lastname'];
|
|
@@ -105,7 +106,7 @@ describe('useCrmProperties', () => {
|
|
|
105
106
|
capturedCallback = propertiesUpdatedCallback;
|
|
106
107
|
return {
|
|
107
108
|
data: { firstname: 'Initial', lastname: null },
|
|
108
|
-
cleanup:
|
|
109
|
+
cleanup: vi.fn(),
|
|
109
110
|
};
|
|
110
111
|
});
|
|
111
112
|
const propertyNames = ['firstname', 'lastname'];
|
|
@@ -132,7 +133,7 @@ describe('useCrmProperties', () => {
|
|
|
132
133
|
firstname: 'John',
|
|
133
134
|
lastname: 'Doe',
|
|
134
135
|
},
|
|
135
|
-
cleanup:
|
|
136
|
+
cleanup: vi.fn(),
|
|
136
137
|
});
|
|
137
138
|
const propertyNames = ['firstname', 'lastname'];
|
|
138
139
|
const options = {
|
|
@@ -148,7 +149,7 @@ describe('useCrmProperties', () => {
|
|
|
148
149
|
data: {
|
|
149
150
|
firstname: 'John',
|
|
150
151
|
},
|
|
151
|
-
cleanup:
|
|
152
|
+
cleanup: vi.fn(),
|
|
152
153
|
});
|
|
153
154
|
const propertyNames = ['firstname'];
|
|
154
155
|
const defaultOptions = {};
|
|
@@ -162,7 +163,7 @@ describe('useCrmProperties', () => {
|
|
|
162
163
|
data: {
|
|
163
164
|
firstname: 'John',
|
|
164
165
|
},
|
|
165
|
-
cleanup:
|
|
166
|
+
cleanup: vi.fn(),
|
|
166
167
|
});
|
|
167
168
|
const propertyNames = ['firstname'];
|
|
168
169
|
const initialOptions = { propertiesToFormat: ['firstname'] };
|
|
@@ -181,7 +182,7 @@ describe('useCrmProperties', () => {
|
|
|
181
182
|
data: {
|
|
182
183
|
firstname: 'John',
|
|
183
184
|
},
|
|
184
|
-
cleanup:
|
|
185
|
+
cleanup: vi.fn(),
|
|
185
186
|
});
|
|
186
187
|
const propertyNames = ['firstname'];
|
|
187
188
|
const initialOptions = { propertiesToFormat: ['firstname'] };
|
|
@@ -201,7 +202,7 @@ describe('useCrmProperties', () => {
|
|
|
201
202
|
});
|
|
202
203
|
});
|
|
203
204
|
it('should call cleanup function when component unmounts', async () => {
|
|
204
|
-
const mockCleanup =
|
|
205
|
+
const mockCleanup = vi.fn();
|
|
205
206
|
mockFetchCrmProperties.mockResolvedValue({
|
|
206
207
|
data: {
|
|
207
208
|
firstname: 'John',
|
|
@@ -217,8 +218,8 @@ describe('useCrmProperties', () => {
|
|
|
217
218
|
expect(mockCleanup).toHaveBeenCalledTimes(1);
|
|
218
219
|
});
|
|
219
220
|
it('should call cleanup function when dependencies change', async () => {
|
|
220
|
-
const mockCleanup1 =
|
|
221
|
-
const mockCleanup2 =
|
|
221
|
+
const mockCleanup1 = vi.fn();
|
|
222
|
+
const mockCleanup2 = vi.fn();
|
|
222
223
|
mockFetchCrmProperties
|
|
223
224
|
.mockResolvedValueOnce({
|
|
224
225
|
data: { firstname: 'John' },
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
1
2
|
// Set up the mock before importing the module
|
|
2
|
-
const mockFetchAssociations =
|
|
3
|
+
const mockFetchAssociations = vi.fn();
|
|
3
4
|
const mockSelf = {
|
|
4
5
|
fetchAssociations: mockFetchAssociations,
|
|
5
6
|
};
|
|
@@ -8,18 +9,18 @@ Object.defineProperty(global, 'self', {
|
|
|
8
9
|
value: mockSelf,
|
|
9
10
|
writable: true,
|
|
10
11
|
});
|
|
11
|
-
import { fetchAssociations, calculatePaginationFlags, } from
|
|
12
|
+
import { fetchAssociations, calculatePaginationFlags, } from "../../../crm/utils/fetchAssociations.js";
|
|
12
13
|
describe('fetchAssociations', () => {
|
|
13
14
|
// Helper functions
|
|
14
15
|
const createMockResponse = (data, overrides = {}) => ({
|
|
15
16
|
ok: true,
|
|
16
|
-
json:
|
|
17
|
+
json: vi.fn().mockResolvedValue({ data, cleanup: vi.fn() }),
|
|
17
18
|
...overrides,
|
|
18
19
|
});
|
|
19
20
|
const createErrorResponse = (statusText) => ({
|
|
20
21
|
ok: false,
|
|
21
22
|
statusText,
|
|
22
|
-
json:
|
|
23
|
+
json: vi.fn().mockResolvedValue({}),
|
|
23
24
|
});
|
|
24
25
|
const expectError = async (request, expectedMessage) => {
|
|
25
26
|
await expect(fetchAssociations(request)).rejects.toThrow(expectedMessage);
|
|
@@ -30,7 +31,7 @@ describe('fetchAssociations', () => {
|
|
|
30
31
|
...overrides,
|
|
31
32
|
});
|
|
32
33
|
beforeEach(() => {
|
|
33
|
-
|
|
34
|
+
vi.clearAllMocks();
|
|
34
35
|
// Set up dynamic mock that responds to request parameters
|
|
35
36
|
mockFetchAssociations.mockImplementation((request) => {
|
|
36
37
|
const { pageLength = 100, offset = 0, properties = [] } = request;
|
|
@@ -61,7 +62,7 @@ describe('fetchAssociations', () => {
|
|
|
61
62
|
];
|
|
62
63
|
const mockData = {
|
|
63
64
|
results: mockResults,
|
|
64
|
-
hasMore: offset < 200,
|
|
65
|
+
hasMore: offset < 200, // Has more until offset 200
|
|
65
66
|
nextOffset: offset + pageLength,
|
|
66
67
|
};
|
|
67
68
|
return Promise.resolve(createMockResponse(mockData));
|
|
@@ -210,7 +211,7 @@ describe('fetchAssociations', () => {
|
|
|
210
211
|
});
|
|
211
212
|
it('should handle different object types', async () => {
|
|
212
213
|
const request = createBasicRequest({
|
|
213
|
-
toObjectType: '0-2',
|
|
214
|
+
toObjectType: '0-2', // Company
|
|
214
215
|
properties: ['name'],
|
|
215
216
|
});
|
|
216
217
|
const result = await fetchAssociations(request);
|
|
@@ -250,7 +251,7 @@ describe('fetchAssociations', () => {
|
|
|
250
251
|
});
|
|
251
252
|
it('should throw error for invalid association result structure', async () => {
|
|
252
253
|
const invalidData = {
|
|
253
|
-
results: [{ invalidStructure: true }],
|
|
254
|
+
results: [{ invalidStructure: true }], // missing required fields
|
|
254
255
|
hasMore: false,
|
|
255
256
|
nextOffset: 0,
|
|
256
257
|
};
|
|
@@ -263,7 +264,7 @@ describe('fetchAssociations', () => {
|
|
|
263
264
|
results: [
|
|
264
265
|
{
|
|
265
266
|
toObjectId: 1000,
|
|
266
|
-
associationTypes: 'not an array',
|
|
267
|
+
associationTypes: 'not an array', // should be array
|
|
267
268
|
properties: {},
|
|
268
269
|
},
|
|
269
270
|
],
|
|
@@ -296,12 +297,12 @@ describe('fetchAssociations', () => {
|
|
|
296
297
|
expect(mockFetchAssociations).toHaveBeenCalledWith(request, undefined);
|
|
297
298
|
});
|
|
298
299
|
it('should return cleanup function from API response', async () => {
|
|
299
|
-
const mockCleanup =
|
|
300
|
+
const mockCleanup = vi.fn();
|
|
300
301
|
const emptyData = { results: [], hasMore: false, nextOffset: 0 };
|
|
301
302
|
const mockApiResponse = { data: emptyData, cleanup: mockCleanup };
|
|
302
303
|
mockFetchAssociations.mockResolvedValueOnce({
|
|
303
304
|
ok: true,
|
|
304
|
-
json:
|
|
305
|
+
json: vi.fn().mockResolvedValue(mockApiResponse),
|
|
305
306
|
});
|
|
306
307
|
const result = await fetchAssociations(createBasicRequest());
|
|
307
308
|
expect(result.cleanup).toBe(mockCleanup);
|
|
@@ -313,7 +314,7 @@ describe('fetchAssociations', () => {
|
|
|
313
314
|
const mockApiResponse = { data: emptyData }; // no cleanup function provided
|
|
314
315
|
mockFetchAssociations.mockResolvedValueOnce({
|
|
315
316
|
ok: true,
|
|
316
|
-
json:
|
|
317
|
+
json: vi.fn().mockResolvedValue(mockApiResponse),
|
|
317
318
|
});
|
|
318
319
|
const result = await fetchAssociations(createBasicRequest());
|
|
319
320
|
expect(typeof result.cleanup).toBe('function');
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { vi } from 'vitest';
|
|
1
2
|
// Set up the mock before importing the module
|
|
2
|
-
const mockFetchCrmProperties =
|
|
3
|
+
const mockFetchCrmProperties = vi.fn();
|
|
3
4
|
const mockSelf = {
|
|
4
5
|
fetchCrmProperties: mockFetchCrmProperties,
|
|
5
6
|
};
|
|
@@ -8,11 +9,11 @@ Object.defineProperty(global, 'self', {
|
|
|
8
9
|
value: mockSelf,
|
|
9
10
|
writable: true,
|
|
10
11
|
});
|
|
11
|
-
import { fetchCrmProperties } from
|
|
12
|
+
import { fetchCrmProperties } from "../../../crm/utils/fetchCrmProperties.js";
|
|
12
13
|
const DEFAULT_OPTIONS = {};
|
|
13
14
|
describe('fetchCrmProperties', () => {
|
|
14
15
|
beforeEach(() => {
|
|
15
|
-
|
|
16
|
+
vi.clearAllMocks();
|
|
16
17
|
});
|
|
17
18
|
it('successfully fetches CRM properties', async () => {
|
|
18
19
|
const mockApiResponse = {
|
|
@@ -20,15 +21,15 @@ describe('fetchCrmProperties', () => {
|
|
|
20
21
|
firstname: 'Test value for firstname',
|
|
21
22
|
lastname: 'Test value for lastname',
|
|
22
23
|
},
|
|
23
|
-
cleanup:
|
|
24
|
+
cleanup: vi.fn(),
|
|
24
25
|
};
|
|
25
26
|
const mockResponse = {
|
|
26
27
|
ok: true,
|
|
27
|
-
json:
|
|
28
|
+
json: vi.fn().mockResolvedValue(mockApiResponse),
|
|
28
29
|
};
|
|
29
30
|
mockFetchCrmProperties.mockResolvedValue(mockResponse);
|
|
30
31
|
const propertyNames = ['firstname', 'lastname'];
|
|
31
|
-
const result = await fetchCrmProperties(propertyNames,
|
|
32
|
+
const result = await fetchCrmProperties(propertyNames, vi.fn(), DEFAULT_OPTIONS);
|
|
32
33
|
expect(mockFetchCrmProperties).toHaveBeenCalledWith(propertyNames, expect.any(Function), DEFAULT_OPTIONS);
|
|
33
34
|
expect(result).toEqual({
|
|
34
35
|
data: {
|
|
@@ -46,15 +47,15 @@ describe('fetchCrmProperties', () => {
|
|
|
46
47
|
email: 'john@example.com',
|
|
47
48
|
phone: null,
|
|
48
49
|
},
|
|
49
|
-
cleanup:
|
|
50
|
+
cleanup: vi.fn(),
|
|
50
51
|
};
|
|
51
52
|
const mockResponse = {
|
|
52
53
|
ok: true,
|
|
53
|
-
json:
|
|
54
|
+
json: vi.fn().mockResolvedValue(mockApiResponse),
|
|
54
55
|
};
|
|
55
56
|
mockFetchCrmProperties.mockResolvedValue(mockResponse);
|
|
56
57
|
const propertyNames = ['firstname', 'lastname', 'email', 'phone'];
|
|
57
|
-
const result = await fetchCrmProperties(propertyNames,
|
|
58
|
+
const result = await fetchCrmProperties(propertyNames, vi.fn(), DEFAULT_OPTIONS);
|
|
58
59
|
expect(mockFetchCrmProperties).toHaveBeenCalledWith(propertyNames, expect.any(Function), DEFAULT_OPTIONS);
|
|
59
60
|
expect(result).toEqual({
|
|
60
61
|
data: {
|
|
@@ -70,46 +71,46 @@ describe('fetchCrmProperties', () => {
|
|
|
70
71
|
const mockResponse = {
|
|
71
72
|
ok: false,
|
|
72
73
|
statusText: 'Not Found',
|
|
73
|
-
json:
|
|
74
|
+
json: vi.fn().mockResolvedValue({}),
|
|
74
75
|
};
|
|
75
76
|
mockFetchCrmProperties.mockResolvedValue(mockResponse);
|
|
76
77
|
const propertyNames = ['firstname'];
|
|
77
|
-
await expect(fetchCrmProperties(propertyNames,
|
|
78
|
+
await expect(fetchCrmProperties(propertyNames, vi.fn(), DEFAULT_OPTIONS)).rejects.toThrow('Failed to fetch CRM properties: Not Found');
|
|
78
79
|
});
|
|
79
80
|
it('throws an error when fetch fails', async () => {
|
|
80
81
|
mockFetchCrmProperties.mockRejectedValue(new Error('Network error'));
|
|
81
82
|
const propertyNames = ['firstname'];
|
|
82
|
-
await expect(fetchCrmProperties(propertyNames,
|
|
83
|
+
await expect(fetchCrmProperties(propertyNames, vi.fn(), DEFAULT_OPTIONS)).rejects.toThrow('Network error');
|
|
83
84
|
});
|
|
84
85
|
it('throws an error if the response is not an object', async () => {
|
|
85
86
|
const mockApiResponse = {
|
|
86
|
-
data: 'Invalid response',
|
|
87
|
-
cleanup:
|
|
87
|
+
data: 'Invalid response', // data should be an object
|
|
88
|
+
cleanup: vi.fn(),
|
|
88
89
|
};
|
|
89
90
|
const mockResponse = {
|
|
90
91
|
ok: true,
|
|
91
|
-
json:
|
|
92
|
+
json: vi.fn().mockResolvedValue(mockApiResponse),
|
|
92
93
|
};
|
|
93
94
|
mockFetchCrmProperties.mockResolvedValue(mockResponse);
|
|
94
95
|
const propertyNames = ['firstname'];
|
|
95
|
-
await expect(fetchCrmProperties(propertyNames,
|
|
96
|
+
await expect(fetchCrmProperties(propertyNames, vi.fn(), DEFAULT_OPTIONS)).rejects.toThrow('Invalid response format');
|
|
96
97
|
});
|
|
97
98
|
it('throws an error if response contains invalid property values', async () => {
|
|
98
99
|
const mockApiResponse = {
|
|
99
100
|
data: {
|
|
100
101
|
firstname: 'John',
|
|
101
|
-
lastname: 123,
|
|
102
|
+
lastname: 123, // Invalid: should be string or null
|
|
102
103
|
email: 'john@example.com',
|
|
103
104
|
},
|
|
104
|
-
cleanup:
|
|
105
|
+
cleanup: vi.fn(),
|
|
105
106
|
};
|
|
106
107
|
const mockResponse = {
|
|
107
108
|
ok: true,
|
|
108
|
-
json:
|
|
109
|
+
json: vi.fn().mockResolvedValue(mockApiResponse),
|
|
109
110
|
};
|
|
110
111
|
mockFetchCrmProperties.mockResolvedValue(mockResponse);
|
|
111
112
|
const propertyNames = ['firstname', 'lastname', 'email'];
|
|
112
|
-
await expect(fetchCrmProperties(propertyNames,
|
|
113
|
+
await expect(fetchCrmProperties(propertyNames, vi.fn(), DEFAULT_OPTIONS)).rejects.toThrow('Invalid response format');
|
|
113
114
|
});
|
|
114
115
|
it('passes the propertiesUpdatedCallback and allows it to be called', async () => {
|
|
115
116
|
let capturedCallback;
|
|
@@ -118,18 +119,18 @@ describe('fetchCrmProperties', () => {
|
|
|
118
119
|
firstname: 'Initial',
|
|
119
120
|
lastname: 'Initial',
|
|
120
121
|
},
|
|
121
|
-
cleanup:
|
|
122
|
+
cleanup: vi.fn(),
|
|
122
123
|
};
|
|
123
124
|
const mockResponse = {
|
|
124
125
|
ok: true,
|
|
125
|
-
json:
|
|
126
|
+
json: vi.fn().mockResolvedValue(mockApiResponse),
|
|
126
127
|
};
|
|
127
128
|
mockFetchCrmProperties.mockImplementation((propertyNames, callback) => {
|
|
128
129
|
capturedCallback = callback;
|
|
129
130
|
return Promise.resolve(mockResponse);
|
|
130
131
|
});
|
|
131
132
|
const propertyNames = ['firstname', 'lastname'];
|
|
132
|
-
const mockCallback =
|
|
133
|
+
const mockCallback = vi.fn();
|
|
133
134
|
await fetchCrmProperties(propertyNames, mockCallback, DEFAULT_OPTIONS);
|
|
134
135
|
expect(typeof capturedCallback).toBe('function');
|
|
135
136
|
// Simulate the callback being called with new properties
|
|
@@ -146,18 +147,18 @@ describe('fetchCrmProperties', () => {
|
|
|
146
147
|
firstname: 'Initial',
|
|
147
148
|
lastname: null,
|
|
148
149
|
},
|
|
149
|
-
cleanup:
|
|
150
|
+
cleanup: vi.fn(),
|
|
150
151
|
};
|
|
151
152
|
const mockResponse = {
|
|
152
153
|
ok: true,
|
|
153
|
-
json:
|
|
154
|
+
json: vi.fn().mockResolvedValue(mockApiResponse),
|
|
154
155
|
};
|
|
155
156
|
mockFetchCrmProperties.mockImplementation((propertyNames, callback) => {
|
|
156
157
|
capturedCallback = callback;
|
|
157
158
|
return Promise.resolve(mockResponse);
|
|
158
159
|
});
|
|
159
160
|
const propertyNames = ['firstname', 'lastname'];
|
|
160
|
-
const mockCallback =
|
|
161
|
+
const mockCallback = vi.fn();
|
|
161
162
|
await fetchCrmProperties(propertyNames, mockCallback, DEFAULT_OPTIONS);
|
|
162
163
|
expect(typeof capturedCallback).toBe('function');
|
|
163
164
|
// Simulate the callback being called with new properties including null values
|
|
@@ -173,11 +174,11 @@ describe('fetchCrmProperties', () => {
|
|
|
173
174
|
firstname: 'John',
|
|
174
175
|
lastname: 'Doe',
|
|
175
176
|
},
|
|
176
|
-
cleanup:
|
|
177
|
+
cleanup: vi.fn(),
|
|
177
178
|
};
|
|
178
179
|
const mockResponse = {
|
|
179
180
|
ok: true,
|
|
180
|
-
json:
|
|
181
|
+
json: vi.fn().mockResolvedValue(mockApiResponse),
|
|
181
182
|
};
|
|
182
183
|
mockFetchCrmProperties.mockResolvedValue(mockResponse);
|
|
183
184
|
const propertyNames = ['firstname', 'lastname'];
|
|
@@ -192,7 +193,7 @@ describe('fetchCrmProperties', () => {
|
|
|
192
193
|
},
|
|
193
194
|
},
|
|
194
195
|
};
|
|
195
|
-
await fetchCrmProperties(propertyNames,
|
|
196
|
+
await fetchCrmProperties(propertyNames, vi.fn(), options);
|
|
196
197
|
expect(mockFetchCrmProperties).toHaveBeenCalledWith(propertyNames, expect.any(Function), options);
|
|
197
198
|
});
|
|
198
199
|
it('preserves error handling with formatting options', async () => {
|
|
@@ -206,27 +207,27 @@ describe('fetchCrmProperties', () => {
|
|
|
206
207
|
},
|
|
207
208
|
},
|
|
208
209
|
};
|
|
209
|
-
await expect(fetchCrmProperties(propertyNames,
|
|
210
|
+
await expect(fetchCrmProperties(propertyNames, vi.fn(), options)).rejects.toThrow('Network error');
|
|
210
211
|
expect(mockFetchCrmProperties).toHaveBeenCalledWith(propertyNames, expect.any(Function), options);
|
|
211
212
|
});
|
|
212
213
|
it('preserves response validation with formatting options', async () => {
|
|
213
214
|
const mockApiResponse = {
|
|
214
|
-
data: 'Invalid response',
|
|
215
|
-
cleanup:
|
|
215
|
+
data: 'Invalid response', // data should be an object
|
|
216
|
+
cleanup: vi.fn(),
|
|
216
217
|
};
|
|
217
218
|
const mockResponse = {
|
|
218
219
|
ok: true,
|
|
219
|
-
json:
|
|
220
|
+
json: vi.fn().mockResolvedValue(mockApiResponse),
|
|
220
221
|
};
|
|
221
222
|
mockFetchCrmProperties.mockResolvedValue(mockResponse);
|
|
222
223
|
const propertyNames = ['firstname'];
|
|
223
224
|
const options = {
|
|
224
225
|
propertiesToFormat: 'all',
|
|
225
226
|
};
|
|
226
|
-
await expect(fetchCrmProperties(propertyNames,
|
|
227
|
+
await expect(fetchCrmProperties(propertyNames, vi.fn(), options)).rejects.toThrow('Invalid response format');
|
|
227
228
|
});
|
|
228
229
|
it('returns cleanup function that can be called', async () => {
|
|
229
|
-
const mockCleanup =
|
|
230
|
+
const mockCleanup = vi.fn();
|
|
230
231
|
const mockApiResponse = {
|
|
231
232
|
data: {
|
|
232
233
|
firstname: 'John',
|
|
@@ -235,11 +236,11 @@ describe('fetchCrmProperties', () => {
|
|
|
235
236
|
};
|
|
236
237
|
const mockResponse = {
|
|
237
238
|
ok: true,
|
|
238
|
-
json:
|
|
239
|
+
json: vi.fn().mockResolvedValue(mockApiResponse),
|
|
239
240
|
};
|
|
240
241
|
mockFetchCrmProperties.mockResolvedValue(mockResponse);
|
|
241
242
|
const propertyNames = ['firstname'];
|
|
242
|
-
const result = await fetchCrmProperties(propertyNames,
|
|
243
|
+
const result = await fetchCrmProperties(propertyNames, vi.fn(), DEFAULT_OPTIONS);
|
|
243
244
|
expect(result.cleanup).toBe(mockCleanup);
|
|
244
245
|
expect(typeof result.cleanup).toBe('function');
|
|
245
246
|
// Verify cleanup can be called without errors
|
package/dist/clientTypes.d.ts
CHANGED
package/dist/clientTypes.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
|
|
1
|
+
export {};
|