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