]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import 'mocha' | |
4 | ||
5 | import { | |
6 | createUser, | |
7 | flushTests, | |
8 | killallServers, | |
9 | flushAndRunServer, | |
10 | ServerInfo, | |
11 | setAccessTokensToServers, | |
12 | userLogin, | |
13 | cleanupTests | |
14 | } from '../../../../shared/extra-utils' | |
15 | import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' | |
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 | ||
27 | server = await flushAndRunServer(1) | |
28 | ||
29 | await setAccessTokensToServers([ server ]) | |
30 | ||
31 | const user = { | |
32 | username: 'user1', | |
33 | password: 'my super password' | |
34 | } | |
35 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | |
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 | ||
108 | after(async function () { | |
109 | await cleanupTests([ server ]) | |
110 | }) | |
111 | }) |