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