]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | ||
5 | import { | |
6 | cleanupTests, | |
7 | createUser, | |
8 | flushAndRunServer, | |
9 | ServerInfo, | |
10 | setAccessTokensToServers, | |
11 | userLogin | |
12 | } from '../../../../shared/extra-utils' | |
13 | import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' | |
14 | ||
15 | describe('Test logs API validators', function () { | |
16 | const path = '/api/v1/server/logs' | |
17 | let server: ServerInfo | |
18 | let userAccessToken = '' | |
19 | ||
20 | // --------------------------------------------------------------- | |
21 | ||
22 | before(async function () { | |
23 | this.timeout(120000) | |
24 | ||
25 | server = await flushAndRunServer(1) | |
26 | ||
27 | await setAccessTokensToServers([ server ]) | |
28 | ||
29 | const user = { | |
30 | username: 'user1', | |
31 | password: 'my super password' | |
32 | } | |
33 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | |
34 | userAccessToken = await userLogin(server, user) | |
35 | }) | |
36 | ||
37 | describe('When getting logs', function () { | |
38 | ||
39 | it('Should fail with a non authenticated user', async function () { | |
40 | await makeGetRequest({ | |
41 | url: server.url, | |
42 | path, | |
43 | statusCodeExpected: 401 | |
44 | }) | |
45 | }) | |
46 | ||
47 | it('Should fail with a non admin user', async function () { | |
48 | await makeGetRequest({ | |
49 | url: server.url, | |
50 | path, | |
51 | token: userAccessToken, | |
52 | statusCodeExpected: 403 | |
53 | }) | |
54 | }) | |
55 | ||
56 | it('Should fail with a missing startDate query', async function () { | |
57 | await makeGetRequest({ | |
58 | url: server.url, | |
59 | path, | |
60 | token: server.accessToken, | |
61 | statusCodeExpected: 400 | |
62 | }) | |
63 | }) | |
64 | ||
65 | it('Should fail with a bad startDate query', async function () { | |
66 | await makeGetRequest({ | |
67 | url: server.url, | |
68 | path, | |
69 | token: server.accessToken, | |
70 | query: { startDate: 'toto' }, | |
71 | statusCodeExpected: 400 | |
72 | }) | |
73 | }) | |
74 | ||
75 | it('Should fail with a bad endDate query', async function () { | |
76 | await makeGetRequest({ | |
77 | url: server.url, | |
78 | path, | |
79 | token: server.accessToken, | |
80 | query: { startDate: new Date().toISOString(), endDate: 'toto' }, | |
81 | statusCodeExpected: 400 | |
82 | }) | |
83 | }) | |
84 | ||
85 | it('Should fail with a bad level parameter', async function () { | |
86 | await makeGetRequest({ | |
87 | url: server.url, | |
88 | path, | |
89 | token: server.accessToken, | |
90 | query: { startDate: new Date().toISOString(), level: 'toto' }, | |
91 | statusCodeExpected: 400 | |
92 | }) | |
93 | }) | |
94 | ||
95 | it('Should succeed with the correct params', async function () { | |
96 | await makeGetRequest({ | |
97 | url: server.url, | |
98 | path, | |
99 | token: server.accessToken, | |
100 | query: { startDate: new Date().toISOString() }, | |
101 | statusCodeExpected: 200 | |
102 | }) | |
103 | }) | |
104 | }) | |
105 | ||
106 | after(async function () { | |
107 | await cleanupTests([ server ]) | |
108 | }) | |
109 | }) |