]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/jobs.ts
Merge from upstream
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / jobs.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4
5 import {
6 createUser,
7 flushTests,
8 killallServers,
9 runServer,
10 ServerInfo,
11 setAccessTokensToServers,
12 userLogin
13 } from '../../../../shared/utils'
14 import {
15 checkBadCountPagination,
16 checkBadSortPagination,
17 checkBadStartPagination
18 } from '../../../../shared/utils/requests/check-api-params'
19 import { makeGetRequest } from '../../../../shared/utils/requests/requests'
20
21 describe('Test jobs API validators', function () {
22 const path = '/api/v1/jobs/failed'
23 let server: ServerInfo
24 let userAccessToken = ''
25
26 // ---------------------------------------------------------------
27
28 before(async function () {
29 this.timeout(120000)
30
31 await flushTests()
32
33 server = await runServer(1)
34
35 await setAccessTokensToServers([ server ])
36
37 const user = {
38 username: 'user1',
39 password: 'my super password'
40 }
41 await createUser(server.url, server.accessToken, user.username, user.password)
42 userAccessToken = await userLogin(server, user)
43 })
44
45 describe('When listing jobs', function () {
46
47 it('Should fail with a bad state', async function () {
48 await makeGetRequest({
49 url: server.url,
50 token: server.accessToken,
51 path: path + 'ade'
52 })
53 })
54
55 it('Should fail with a bad start pagination', async function () {
56 await checkBadStartPagination(server.url, path, server.accessToken)
57 })
58
59 it('Should fail with a bad count pagination', async function () {
60 await checkBadCountPagination(server.url, path, server.accessToken)
61 })
62
63 it('Should fail with an incorrect sort', async function () {
64 await checkBadSortPagination(server.url, path, server.accessToken)
65 })
66
67 it('Should fail with a non authenticated user', async function () {
68 await makeGetRequest({
69 url: server.url,
70 path,
71 statusCodeExpected: 401
72 })
73 })
74
75 it('Should fail with a non admin user', async function () {
76 await makeGetRequest({
77 url: server.url,
78 path,
79 token: userAccessToken,
80 statusCodeExpected: 403
81 })
82 })
83 })
84
85 after(async function () {
86 killallServers([ server ])
87
88 // Keep the logs if the test failed
89 if (this['ok']) {
90 await flushTests()
91 }
92 })
93 })