forked from elastic/kibana
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.test.ts
69 lines (58 loc) · 2.38 KB
/
index.test.ts
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
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { httpServiceMock } from '@kbn/core/public/mocks';
import { bulkGetCases, getCases, getCasesMetrics } from '.';
import { allCases, allCasesSnake } from '../containers/mock';
describe('api', () => {
beforeEach(() => {
jest.clearAllMocks();
});
describe('getCases', () => {
const http = httpServiceMock.createStartContract({ basePath: '' });
http.get.mockResolvedValue(allCasesSnake);
it('should return the correct response', async () => {
expect(await getCases({ http, query: { from: 'now-1d' } })).toEqual(allCases);
});
it('should have been called with the correct path', async () => {
await getCases({ http, query: { perPage: 10 } });
expect(http.get).toHaveBeenCalledWith('/api/cases/_find', {
query: { perPage: 10 },
});
});
});
describe('getCasesMetrics', () => {
const http = httpServiceMock.createStartContract({ basePath: '' });
http.get.mockResolvedValue({ mttr: 0 });
it('should return the correct response', async () => {
expect(
await getCasesMetrics({ http, query: { features: ['mttr'], from: 'now-1d' } })
).toEqual({ mttr: 0 });
});
it('should have been called with the correct path', async () => {
await getCasesMetrics({ http, query: { features: ['mttr'], to: 'now-1d' } });
expect(http.get).toHaveBeenCalledWith('/api/cases/metrics', {
query: { features: ['mttr'], to: 'now-1d' },
});
});
});
describe('bulkGetCases', () => {
const http = httpServiceMock.createStartContract({ basePath: '' });
http.post.mockResolvedValue({ cases: allCasesSnake, errors: [] });
it('should return the correct response', async () => {
expect(await bulkGetCases({ http, params: { ids: ['test'], fields: ['title'] } })).toEqual({
cases: allCasesSnake,
errors: [],
});
});
it('should have been called with the correct path', async () => {
await bulkGetCases({ http, params: { ids: ['test'], fields: ['title'] } });
expect(http.post).toHaveBeenCalledWith('/internal/cases/_bulk_get', {
body: '{"ids":["test"],"fields":["title"]}',
});
});
});
});