]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/logs.ts
Use an object to represent a server
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / logs.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4
5 import {
6 cleanupTests,
7 createSingleServer,
8 PeerTubeServer,
9 setAccessTokensToServers
10 } from '../../../../shared/extra-utils'
11 import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
12 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
13
14 describe('Test logs API validators', function () {
15 const path = '/api/v1/server/logs'
16 let server: PeerTubeServer
17 let userAccessToken = ''
18
19 // ---------------------------------------------------------------
20
21 before(async function () {
22 this.timeout(120000)
23
24 server = await createSingleServer(1)
25
26 await setAccessTokensToServers([ server ])
27
28 const user = {
29 username: 'user1',
30 password: 'my super password'
31 }
32 await server.users.create({ username: user.username, password: user.password })
33 userAccessToken = await server.login.getAccessToken(user)
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,
42 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
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,
51 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
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,
60 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
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' },
70 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
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' },
80 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
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' },
90 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
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() },
100 statusCodeExpected: HttpStatusCode.OK_200
101 })
102 })
103 })
104
105 after(async function () {
106 await cleanupTests([ server ])
107 })
108 })