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