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