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