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