]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/jobs.ts
Introduce videos command
[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'
5cd80545 4
9639bd17 5import {
a1587156 6 cleanupTests,
210feb6c 7 flushAndRunServer,
9639bd17 8 ServerInfo,
41d1d075 9 setAccessTokensToServers
94565d52 10} from '../../../../shared/extra-utils'
9639bd17 11import {
12 checkBadCountPagination,
13 checkBadSortPagination,
14 checkBadStartPagination
94565d52
C
15} from '../../../../shared/extra-utils/requests/check-api-params'
16import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
2d53be02 17import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
5cd80545
C
18
19describe('Test jobs API validators', function () {
94a5ff8a 20 const path = '/api/v1/jobs/failed'
5cd80545
C
21 let server: ServerInfo
22 let userAccessToken = ''
23
24 // ---------------------------------------------------------------
25
26 before(async function () {
27 this.timeout(120000)
28
210feb6c 29 server = await flushAndRunServer(1)
5cd80545
C
30
31 await setAccessTokensToServers([ server ])
32
33 const user = {
34 username: 'user1',
35 password: 'my super password'
36 }
7926c5f9 37 await server.usersCommand.create({ username: user.username, password: user.password })
41d1d075 38 userAccessToken = await server.loginCommand.getAccessToken(user)
5cd80545
C
39 })
40
41 describe('When listing jobs', function () {
94a5ff8a
C
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
1061c73f
C
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
5cd80545 62 it('Should fail with a bad start pagination', async function () {
93e4a311 63 await checkBadStartPagination(server.url, path, server.accessToken)
5cd80545
C
64 })
65
66 it('Should fail with a bad count pagination', async function () {
93e4a311 67 await checkBadCountPagination(server.url, path, server.accessToken)
5cd80545
C
68 })
69
70 it('Should fail with an incorrect sort', async function () {
93e4a311 71 await checkBadSortPagination(server.url, path, server.accessToken)
5cd80545
C
72 })
73
74 it('Should fail with a non authenticated user', async function () {
93e4a311
C
75 await makeGetRequest({
76 url: server.url,
77 path,
2d53be02 78 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
93e4a311 79 })
5cd80545
C
80 })
81
82 it('Should fail with a non admin user', async function () {
93e4a311
C
83 await makeGetRequest({
84 url: server.url,
85 path,
86 token: userAccessToken,
2d53be02 87 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
93e4a311 88 })
5cd80545 89 })
1061c73f 90
5cd80545
C
91 })
92
7c3b7976
C
93 after(async function () {
94 await cleanupTests([ server ])
5cd80545
C
95 })
96})