]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/jobs.ts
Merge remote-tracking branch 'weblate/develop' into develop
[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'
c55e3d72 6import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/server-commands'
5cd80545
C
7
8describe('Test jobs API validators', function () {
94a5ff8a 9 const path = '/api/v1/jobs/failed'
254d3579 10 let server: PeerTubeServer
5cd80545
C
11 let userAccessToken = ''
12
13 // ---------------------------------------------------------------
14
15 before(async function () {
16 this.timeout(120000)
17
254d3579 18 server = await createSingleServer(1)
5cd80545
C
19
20 await setAccessTokensToServers([ server ])
21
22 const user = {
23 username: 'user1',
24 password: 'my super password'
25 }
89d241a7
C
26 await server.users.create({ username: user.username, password: user.password })
27 userAccessToken = await server.login.getAccessToken(user)
5cd80545
C
28 })
29
30 describe('When listing jobs', function () {
94a5ff8a
C
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
1061c73f
C
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
5cd80545 51 it('Should fail with a bad start pagination', async function () {
93e4a311 52 await checkBadStartPagination(server.url, path, server.accessToken)
5cd80545
C
53 })
54
55 it('Should fail with a bad count pagination', async function () {
93e4a311 56 await checkBadCountPagination(server.url, path, server.accessToken)
5cd80545
C
57 })
58
59 it('Should fail with an incorrect sort', async function () {
93e4a311 60 await checkBadSortPagination(server.url, path, server.accessToken)
5cd80545
C
61 })
62
63 it('Should fail with a non authenticated user', async function () {
93e4a311
C
64 await makeGetRequest({
65 url: server.url,
66 path,
c0e8b12e 67 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
93e4a311 68 })
5cd80545
C
69 })
70
71 it('Should fail with a non admin user', async function () {
93e4a311
C
72 await makeGetRequest({
73 url: server.url,
74 path,
75 token: userAccessToken,
c0e8b12e 76 expectedStatus: HttpStatusCode.FORBIDDEN_403
93e4a311 77 })
5cd80545 78 })
1061c73f 79
5cd80545
C
80 })
81
7c3b7976
C
82 after(async function () {
83 await cleanupTests([ server ])
5cd80545
C
84 })
85})