-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
supertest.js
112 lines (109 loc) · 3.44 KB
/
supertest.js
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const request = require('supertest');
const server = 'http://localhost:3000';
xdescribe('Route integration', () => {
xdescribe('/', () => {
// describe('GET', () => {
// // Note that we return the evaluation of `request` here! It evaluates to
// // a promise, so Jest knows not to say this test passes until that
// // promise resolves. See https://jestjs.io/docs/en/asynchronous
// it('responds with 200 status and text/html content type', () =>
// request(server)
// .get('/')
// .expect('Content-Type', /text\/html/)
// .expect(200));
// });
});
xdescribe('setup router', () => {
describe('/promSetup', () => {
it('responds with status 200', () =>
request(server).get('/setup/promSetup').expect(200));
});
describe('/grafSetup', () => {
it('responds with status 200', () =>
request(server).get('/setup/grafSetup').expect(200));
});
describe('/forwardPorts', () => {
it('responds with status 200', () =>
request(server).get('/setup/forwardPorts').expect(200));
});
});
xdescribe('/clusterdata', () => {
describe('/clusterdata', () => {
it('responds with object', () =>
request(server)
.get('/clusterdata')
.expect(200)
.expect((res) => {
expect(res.body).toMatchObject({
nodes: expect.any(Array),
pods: expect.any(Array),
namespaces: expect.any(Array),
services: expect.any(Array),
deployments: expect.any(Array),
ingresses: expect.any(Array),
});
}));
});
});
xdescribe('alertsRouter', () => {
describe('/alerts', () => {
it('should create an alert successfuly', () =>
request(server)
.post('/alerts')
.send({ type: 'CPU', threshold: 80, name: 'HighCPUUsage' })
.expect(200)
.then((res) => {
expect(res.text).toBe('Alert created successfully');
}));
});
describe('/alerts', () => {
it('should handle errors correctly', () => {
const mockCreateAlert = jest.fn((req, res, next) =>
next(new Error('An error occured'))
);
jest.doMock('../server/controllers/alertController', () => ({
createAlert: mockCreateAlert,
}));
request(server)
.post('/alerts')
.send({
type: 'CPU',
threshold: 80,
name: 'MyAlert',
})
.expect(500)
.then((res) => {
expect(res.text).toContain('An error occured');
});
jest.resetModules();
});
});
});
describe('grafana router', () => {
xdescribe('/key GET', () => {
it('should return an API key', () => {
request(server)
.get('/grafana/key')
.expect((res) => {
expect(typeof res.body.key).toBe('string');
})
.expect(200);
});
});
describe('/Uid', () => {
it('should return Uid', () => {
request(server)
.post('/grafana/uid')
.send({
key: 'eyJrIjoiaHFjejVnb0Vua0xFRWFwbjMzVHd1ZnZBWThPZjlDMnUiLCJuIjoia2NzYXIiLCJpZCI6MX0=',
dashboard: 'Kubernetes / API server',
})
.expect(200)
.then((res) => {
// console.log(res.body);
expect(typeof res.body).toBe('string');
});
});
});
});
});