-
Notifications
You must be signed in to change notification settings - Fork 552
Expand file tree
/
Copy pathget-configuration.test.ts
More file actions
65 lines (56 loc) · 1.5 KB
/
get-configuration.test.ts
File metadata and controls
65 lines (56 loc) · 1.5 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
import { API_BASE, fetchConfiguration } from '../get-configuration';
describe('fetchConfiguration', () => {
it('should fetch and cache the configuration', async () => {
const settings = {
appId: 'appId',
apiKey: 'apiKey',
environment: 'prod' as const,
};
// @ts-ignore
global.fetch = vi.fn(() =>
Promise.resolve({
ok: true,
json: () =>
Promise.resolve({
id: '1',
name: 'name',
indexName: 'indexName',
blocks: [],
createdAt: 'createdAt',
updatedAt: 'updatedAt',
}),
})
);
await fetchConfiguration('1', settings);
expect(global.fetch).toHaveBeenCalledTimes(1);
await fetchConfiguration('1', settings);
expect(global.fetch).toHaveBeenCalledTimes(1);
});
it('should fetch from the relevant environment', async () => {
const settings = {
appId: 'appId',
apiKey: 'apiKey',
environment: 'beta' as const,
};
// @ts-ignore
global.fetch = vi.fn(() =>
Promise.resolve({
ok: true,
json: () =>
Promise.resolve({
id: '2',
name: 'name',
indexName: 'indexName',
blocks: [],
createdAt: 'createdAt',
updatedAt: 'updatedAt',
}),
})
);
await fetchConfiguration('2', settings);
expect(global.fetch).toHaveBeenLastCalledWith(
`${API_BASE.beta}/experiences/2`,
expect.anything()
);
});
});