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