]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/jobs.ts
Add videos list filters
[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
11ba2ab3 5import { createUser, flushTests, killallServers, runServer, ServerInfo, setAccessTokensToServers, userLogin } from '../../utils'
93e4a311
C
6import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
7import { makeGetRequest } from '../../utils/requests/requests'
5cd80545
C
8
9describe('Test jobs API validators', function () {
94a5ff8a 10 const path = '/api/v1/jobs/failed'
5cd80545
C
11 let server: ServerInfo
12 let userAccessToken = ''
13
14 // ---------------------------------------------------------------
15
16 before(async function () {
17 this.timeout(120000)
18
19 await flushTests()
20
21 server = await runServer(1)
22
23 await setAccessTokensToServers([ server ])
24
25 const user = {
26 username: 'user1',
27 password: 'my super password'
28 }
29 await createUser(server.url, server.accessToken, user.username, user.password)
eec63bbc 30 userAccessToken = await userLogin(server, user)
5cd80545
C
31 })
32
33 describe('When listing jobs', function () {
94a5ff8a
C
34
35 it('Should fail with a bad state', async function () {
36 await makeGetRequest({
37 url: server.url,
38 token: server.accessToken,
39 path: path + 'ade'
40 })
41 })
42
5cd80545 43 it('Should fail with a bad start pagination', async function () {
93e4a311 44 await checkBadStartPagination(server.url, path, server.accessToken)
5cd80545
C
45 })
46
47 it('Should fail with a bad count pagination', async function () {
93e4a311 48 await checkBadCountPagination(server.url, path, server.accessToken)
5cd80545
C
49 })
50
51 it('Should fail with an incorrect sort', async function () {
93e4a311 52 await checkBadSortPagination(server.url, path, server.accessToken)
5cd80545
C
53 })
54
55 it('Should fail with a non authenticated user', async function () {
93e4a311
C
56 await makeGetRequest({
57 url: server.url,
58 path,
59 statusCodeExpected: 401
60 })
5cd80545
C
61 })
62
63 it('Should fail with a non admin user', async function () {
93e4a311
C
64 await makeGetRequest({
65 url: server.url,
66 path,
67 token: userAccessToken,
68 statusCodeExpected: 403
69 })
5cd80545
C
70 })
71 })
72
73 after(async function () {
74 killallServers([ server ])
75
76 // Keep the logs if the test failed
77 if (this['ok']) {
78 await flushTests()
79 }
80 })
81})