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