]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/debug.ts
Shared utils -> extra-utils
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / debug.ts
CommitLineData
5d79474c
C
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4
5import {
6 createUser,
7 flushTests,
8 killallServers,
9 runServer,
10 ServerInfo,
11 setAccessTokensToServers,
12 userLogin
94565d52
C
13} from '../../../../shared/extra-utils'
14import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
5d79474c
C
15
16describe('Test debug API validators', function () {
17 const path = '/api/v1/server/debug'
18 let server: ServerInfo
19 let userAccessToken = ''
20
21 // ---------------------------------------------------------------
22
23 before(async function () {
24 this.timeout(120000)
25
26 await flushTests()
27
28 server = await runServer(1)
29
30 await setAccessTokensToServers([ server ])
31
32 const user = {
33 username: 'user1',
34 password: 'my super password'
35 }
1eddc9a7 36 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
5d79474c
C
37 userAccessToken = await userLogin(server, user)
38 })
39
40 describe('When getting debug endpoint', function () {
41
42 it('Should fail with a non authenticated user', async function () {
43 await makeGetRequest({
44 url: server.url,
45 path,
46 statusCodeExpected: 401
47 })
48 })
49
50 it('Should fail with a non admin user', async function () {
51 await makeGetRequest({
52 url: server.url,
53 path,
54 token: userAccessToken,
55 statusCodeExpected: 403
56 })
57 })
58
59 it('Should succeed with the correct params', async function () {
60 await makeGetRequest({
61 url: server.url,
62 path,
63 token: server.accessToken,
64 query: { startDate: new Date().toISOString() },
65 statusCodeExpected: 200
66 })
67 })
68 })
69
70 after(async function () {
71 killallServers([ server ])
72
73 // Keep the logs if the test failed
74 if (this['ok']) {
75 await flushTests()
76 }
77 })
78})