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