]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/jobs.ts
Save replay of permanent live in client
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / jobs.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5cd80545
C
2
3import 'mocha'
c55e3d72 4import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
c0e8b12e 5import { HttpStatusCode } from '@shared/models'
419b520c
C
6import {
7 cleanupTests,
8 createSingleServer,
9 makeGetRequest,
10 makePostBodyRequest,
11 PeerTubeServer,
12 setAccessTokensToServers
13} from '@shared/server-commands'
5cd80545
C
14
15describe('Test jobs API validators', function () {
94a5ff8a 16 const path = '/api/v1/jobs/failed'
254d3579 17 let server: PeerTubeServer
5cd80545
C
18 let userAccessToken = ''
19
20 // ---------------------------------------------------------------
21
22 before(async function () {
23 this.timeout(120000)
24
254d3579 25 server = await createSingleServer(1)
5cd80545
C
26
27 await setAccessTokensToServers([ server ])
28
29 const user = {
30 username: 'user1',
31 password: 'my super password'
32 }
89d241a7
C
33 await server.users.create({ username: user.username, password: user.password })
34 userAccessToken = await server.login.getAccessToken(user)
5cd80545
C
35 })
36
37 describe('When listing jobs', function () {
94a5ff8a
C
38
39 it('Should fail with a bad state', async function () {
40 await makeGetRequest({
41 url: server.url,
42 token: server.accessToken,
43 path: path + 'ade'
44 })
45 })
46
1061c73f
C
47 it('Should fail with an incorrect job type', async function () {
48 await makeGetRequest({
49 url: server.url,
50 token: server.accessToken,
51 path,
52 query: {
53 jobType: 'toto'
54 }
55 })
56 })
57
5cd80545 58 it('Should fail with a bad start pagination', async function () {
93e4a311 59 await checkBadStartPagination(server.url, path, server.accessToken)
5cd80545
C
60 })
61
62 it('Should fail with a bad count pagination', async function () {
93e4a311 63 await checkBadCountPagination(server.url, path, server.accessToken)
5cd80545
C
64 })
65
66 it('Should fail with an incorrect sort', async function () {
93e4a311 67 await checkBadSortPagination(server.url, path, server.accessToken)
5cd80545
C
68 })
69
70 it('Should fail with a non authenticated user', async function () {
93e4a311
C
71 await makeGetRequest({
72 url: server.url,
73 path,
c0e8b12e 74 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
93e4a311 75 })
5cd80545
C
76 })
77
78 it('Should fail with a non admin user', async function () {
93e4a311
C
79 await makeGetRequest({
80 url: server.url,
81 path,
82 token: userAccessToken,
c0e8b12e 83 expectedStatus: HttpStatusCode.FORBIDDEN_403
93e4a311 84 })
5cd80545 85 })
419b520c
C
86 })
87
88 describe('When pausing/resuming the job queue', async function () {
89 const commands = [ 'pause', 'resume' ]
90
91 it('Should fail with a non authenticated user', async function () {
92 for (const command of commands) {
93 await makePostBodyRequest({
94 url: server.url,
95 path: '/api/v1/jobs/' + command,
96 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
97 })
98 }
99 })
1061c73f 100
419b520c
C
101 it('Should fail with a non admin user', async function () {
102 for (const command of commands) {
103 await makePostBodyRequest({
104 url: server.url,
105 path: '/api/v1/jobs/' + command,
106 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
107 })
108 }
109 })
110
111 it('Should succeed with the correct params', async function () {
112 for (const command of commands) {
113 await makePostBodyRequest({
114 url: server.url,
115 path: '/api/v1/jobs/' + command,
116 token: server.accessToken,
117 expectedStatus: HttpStatusCode.NO_CONTENT_204
118 })
119 }
120 })
5cd80545
C
121 })
122
7c3b7976
C
123 after(async function () {
124 await cleanupTests([ server ])
5cd80545
C
125 })
126})