Filter on follows actor types in about page
[oweals/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   flushAndRunServer,
10   ServerInfo,
11   setAccessTokensToServers,
12   userLogin,
13   cleanupTests
14 } from '../../../../shared/extra-utils'
15 import {
16   checkBadCountPagination,
17   checkBadSortPagination,
18   checkBadStartPagination
19 } from '../../../../shared/extra-utils/requests/check-api-params'
20 import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
21
22 describe('Test jobs API validators', function () {
23   const path = '/api/v1/jobs/failed'
24   let server: ServerInfo
25   let userAccessToken = ''
26
27   // ---------------------------------------------------------------
28
29   before(async function () {
30     this.timeout(120000)
31
32     server = await flushAndRunServer(1)
33
34     await setAccessTokensToServers([ server ])
35
36     const user = {
37       username: 'user1',
38       password: 'my super password'
39     }
40     await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
41     userAccessToken = await userLogin(server, user)
42   })
43
44   describe('When listing jobs', function () {
45
46     it('Should fail with a bad state', async function () {
47       await makeGetRequest({
48         url: server.url,
49         token: server.accessToken,
50         path: path + 'ade'
51       })
52     })
53
54     it('Should fail with a bad start pagination', async function () {
55       await checkBadStartPagination(server.url, path, server.accessToken)
56     })
57
58     it('Should fail with a bad count pagination', async function () {
59       await checkBadCountPagination(server.url, path, server.accessToken)
60     })
61
62     it('Should fail with an incorrect sort', async function () {
63       await checkBadSortPagination(server.url, path, server.accessToken)
64     })
65
66     it('Should fail with a non authenticated user', async function () {
67       await makeGetRequest({
68         url: server.url,
69         path,
70         statusCodeExpected: 401
71       })
72     })
73
74     it('Should fail with a non admin user', async function () {
75       await makeGetRequest({
76         url: server.url,
77         path,
78         token: userAccessToken,
79         statusCodeExpected: 403
80       })
81     })
82   })
83
84   after(async function () {
85     await cleanupTests([ server ])
86   })
87 })