]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/jobs.ts
Shorter server command names
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / jobs.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4
5 import {
6 cleanupTests,
7 flushAndRunServer,
8 ServerInfo,
9 setAccessTokensToServers
10 } from '../../../../shared/extra-utils'
11 import {
12 checkBadCountPagination,
13 checkBadSortPagination,
14 checkBadStartPagination
15 } from '../../../../shared/extra-utils/requests/check-api-params'
16 import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
17 import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
18
19 describe('Test jobs API validators', function () {
20 const path = '/api/v1/jobs/failed'
21 let server: ServerInfo
22 let userAccessToken = ''
23
24 // ---------------------------------------------------------------
25
26 before(async function () {
27 this.timeout(120000)
28
29 server = await flushAndRunServer(1)
30
31 await setAccessTokensToServers([ server ])
32
33 const user = {
34 username: 'user1',
35 password: 'my super password'
36 }
37 await server.users.create({ username: user.username, password: user.password })
38 userAccessToken = await server.login.getAccessToken(user)
39 })
40
41 describe('When listing jobs', function () {
42
43 it('Should fail with a bad state', async function () {
44 await makeGetRequest({
45 url: server.url,
46 token: server.accessToken,
47 path: path + 'ade'
48 })
49 })
50
51 it('Should fail with an incorrect job type', async function () {
52 await makeGetRequest({
53 url: server.url,
54 token: server.accessToken,
55 path,
56 query: {
57 jobType: 'toto'
58 }
59 })
60 })
61
62 it('Should fail with a bad start pagination', async function () {
63 await checkBadStartPagination(server.url, path, server.accessToken)
64 })
65
66 it('Should fail with a bad count pagination', async function () {
67 await checkBadCountPagination(server.url, path, server.accessToken)
68 })
69
70 it('Should fail with an incorrect sort', async function () {
71 await checkBadSortPagination(server.url, path, server.accessToken)
72 })
73
74 it('Should fail with a non authenticated user', async function () {
75 await makeGetRequest({
76 url: server.url,
77 path,
78 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
79 })
80 })
81
82 it('Should fail with a non admin user', async function () {
83 await makeGetRequest({
84 url: server.url,
85 path,
86 token: userAccessToken,
87 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
88 })
89 })
90
91 })
92
93 after(async function () {
94 await cleanupTests([ server ])
95 })
96 })