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