Cleanup tests
[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 } from '../../../../shared/extra-utils'
14 import {
15   checkBadCountPagination,
16   checkBadSortPagination,
17   checkBadStartPagination
18 } from '../../../../shared/extra-utils/requests/check-api-params'
19 import { makeGetRequest } from '../../../../shared/extra-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     server = await flushAndRunServer(1)
32
33     await setAccessTokensToServers([ server ])
34
35     const user = {
36       username: 'user1',
37       password: 'my super password'
38     }
39     await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
40     userAccessToken = await userLogin(server, user)
41   })
42
43   describe('When listing jobs', function () {
44
45     it('Should fail with a bad state', async function () {
46       await makeGetRequest({
47         url: server.url,
48         token: server.accessToken,
49         path: path + 'ade'
50       })
51     })
52
53     it('Should fail with a bad start pagination', async function () {
54       await checkBadStartPagination(server.url, path, server.accessToken)
55     })
56
57     it('Should fail with a bad count pagination', async function () {
58       await checkBadCountPagination(server.url, path, server.accessToken)
59     })
60
61     it('Should fail with an incorrect sort', async function () {
62       await checkBadSortPagination(server.url, path, server.accessToken)
63     })
64
65     it('Should fail with a non authenticated user', async function () {
66       await makeGetRequest({
67         url: server.url,
68         path,
69         statusCodeExpected: 401
70       })
71     })
72
73     it('Should fail with a non admin user', async function () {
74       await makeGetRequest({
75         url: server.url,
76         path,
77         token: userAccessToken,
78         statusCodeExpected: 403
79       })
80     })
81   })
82
83   after(function () {
84     killallServers([ server ])
85   })
86 })