generated from BeeMyDesk/github-action-typescript-template
-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathgrafana.test.ts
84 lines (74 loc) · 2.31 KB
/
grafana.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import axios from 'axios';
import { GrafanaClient } from './grafana';
jest.mock('axios');
// eslint-disable-next-line @typescript-eslint/no-explicit-any
const mockedAxiosCreate = axios.create as any;
it('should instantiate an Axios client', () => {
new GrafanaClient('https://grafana.example.com', 'TOKEN');
expect(axios.create).toHaveBeenCalledWith({
baseURL: 'https://grafana.example.com/api',
headers: {
Authorization: 'Bearer TOKEN',
},
});
});
describe('createAnnotation', () => {
let client: GrafanaClient;
let postMock: jest.Mock;
beforeEach(() => {
postMock = jest.fn().mockResolvedValue({ data: { id: 1 } });
mockedAxiosCreate.mockReturnValue({ post: postMock });
client = new GrafanaClient('https://grafana.example.com', 'TOKEN');
});
it('should call annotations API with text and time', async () => {
await client.createAnnotation('TEXT', 1583681439000);
expect(postMock).toHaveBeenCalledWith(
'/annotations',
{
text: 'TEXT',
time: 1583681439000,
});
});
it('should call annotations API with dashboardId', async () => {
await client.createAnnotation('TEXT', 1583681439000, 1);
expect(postMock).toHaveBeenCalledWith(
'/annotations',
{
text: 'TEXT',
time: 1583681439000,
dashboardId: 1,
});
});
it('should call annotations API with panelId', async () => {
await client.createAnnotation('TEXT', 1583681439000, undefined, 2);
expect(postMock).toHaveBeenCalledWith(
'/annotations',
{
text: 'TEXT',
time: 1583681439000,
panelId: 2,
});
});
it('should call annotations API with tags', async () => {
await client.createAnnotation('TEXT', 1583681439000, undefined, undefined, ['tag1', 'tag2']);
expect(postMock).toHaveBeenCalledWith(
'/annotations',
{
text: 'TEXT',
time: 1583681439000,
tags: ['tag1', 'tag2'],
});
});
it('should call annotations API with dashboardId, panelId and tags', async () => {
await client.createAnnotation('TEXT', 1583681439000, 1, 2, ['tag1', 'tag2']);
expect(postMock).toHaveBeenCalledWith(
'/annotations',
{
text: 'TEXT',
time: 1583681439000,
dashboardId: 1,
panelId: 2,
tags: ['tag1', 'tag2'],
});
});
});