]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/debug.ts
2a7485cf33364efe8cec9dc9c74d5e65a221a1c1
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / debug.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4
5 import {
6 cleanupTests,
7 flushAndRunServer,
8 ServerInfo,
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 debug API validators', function () {
15 const path = '/api/v1/server/debug'
16 let server: ServerInfo
17 let userAccessToken = ''
18
19 // ---------------------------------------------------------------
20
21 before(async function () {
22 this.timeout(120000)
23
24 server = await flushAndRunServer(1)
25
26 await setAccessTokensToServers([ server ])
27
28 const user = {
29 username: 'user1',
30 password: 'my super password'
31 }
32 await server.usersCommand.create({ username: user.username, password: user.password })
33 userAccessToken = await server.loginCommand.getAccessToken(user)
34 })
35
36 describe('When getting debug endpoint', 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 succeed with the correct params', async function () {
56 await makeGetRequest({
57 url: server.url,
58 path,
59 token: server.accessToken,
60 query: { startDate: new Date().toISOString() },
61 statusCodeExpected: HttpStatusCode.OK_200
62 })
63 })
64 })
65
66 after(async function () {
67 await cleanupTests([ server ])
68 })
69 })