-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Expand file tree
/
Copy pathresolveConfig.test.ts
More file actions
92 lines (77 loc) · 2.29 KB
/
resolveConfig.test.ts
File metadata and controls
92 lines (77 loc) · 2.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0
import { Amplify } from '@aws-amplify/core';
import {
DEFAULT_PERSONALIZE_CONFIG,
PERSONALIZE_FLUSH_SIZE_MAX,
resolveConfig,
} from '../../../../src/providers/personalize/utils';
describe('Analytics Personalize Provider Util: resolveConfig', () => {
const providedConfig = {
region: 'us-east-1',
trackingId: 'trackingId0',
flushSize: 10,
flushInterval: 1000,
};
const getConfigSpy = jest.spyOn(Amplify, 'getConfig');
const assertConfiguredSpy = jest.spyOn(Amplify, 'assertConfigured');
beforeEach(() => {
getConfigSpy.mockReset();
assertConfiguredSpy.mockReset();
});
it('throws if Amplify is not configured', () => {
assertConfiguredSpy.mockImplementation(() => {
throw new Error(
'Amplify has not been configured. Please call Amplify.configure() before using this service.',
);
});
expect(resolveConfig).toThrow(
'Amplify has not been configured. Please call Amplify.configure() before using this service.',
);
});
it('returns required config', () => {
assertConfiguredSpy.mockImplementation(jest.fn());
getConfigSpy.mockReturnValue({
Analytics: { Personalize: providedConfig },
});
expect(resolveConfig()).toStrictEqual({
...providedConfig,
bufferSize: providedConfig.flushSize + 1,
});
});
it('use default config for optional fields', () => {
assertConfiguredSpy.mockImplementation(jest.fn());
const requiredFields = {
region: 'us-east-1',
trackingId: 'trackingId1',
};
getConfigSpy.mockReturnValue({
Analytics: { Personalize: requiredFields },
});
expect(resolveConfig()).toStrictEqual({
...DEFAULT_PERSONALIZE_CONFIG,
region: requiredFields.region,
trackingId: requiredFields.trackingId,
bufferSize: DEFAULT_PERSONALIZE_CONFIG.flushSize + 1,
});
});
it('throws if region is missing', () => {
getConfigSpy.mockReturnValue({
Analytics: {
Personalize: { ...providedConfig, region: undefined as any },
},
});
expect(resolveConfig).toThrow();
});
it('throws if flushSize is larger than max', () => {
getConfigSpy.mockReturnValue({
Analytics: {
Personalize: {
...providedConfig,
flushSize: PERSONALIZE_FLUSH_SIZE_MAX + 1,
},
},
});
expect(resolveConfig).toThrow();
});
});