aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/index.ts1
-rw-r--r--server/tests/api/check-params/jobs.ts84
2 files changed, 85 insertions, 0 deletions
diff --git a/server/tests/api/check-params/index.ts b/server/tests/api/check-params/index.ts
index 287480808..b22bf054a 100644
--- a/server/tests/api/check-params/index.ts
+++ b/server/tests/api/check-params/index.ts
@@ -1,5 +1,6 @@
1// Order of the tests we want to execute 1// Order of the tests we want to execute
2import './follows' 2import './follows'
3import './jobs'
3import './users' 4import './users'
4import './services' 5import './services'
5import './videos' 6import './videos'
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts
new file mode 100644
index 000000000..7a0dd6e8c
--- /dev/null
+++ b/server/tests/api/check-params/jobs.ts
@@ -0,0 +1,84 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import * as request from 'supertest'
5
6import { createUser, flushTests, getUserAccessToken, killallServers, runServer, ServerInfo, setAccessTokensToServers } from '../../utils'
7
8describe('Test jobs API validators', function () {
9 const path = '/api/v1/jobs/'
10 let server: ServerInfo
11 let userAccessToken = ''
12
13 // ---------------------------------------------------------------
14
15 before(async function () {
16 this.timeout(120000)
17
18 await flushTests()
19
20 server = await runServer(1)
21
22 await setAccessTokensToServers([ server ])
23
24 const user = {
25 username: 'user1',
26 password: 'my super password'
27 }
28 await createUser(server.url, server.accessToken, user.username, user.password)
29 userAccessToken = await getUserAccessToken(server, user)
30 })
31
32 describe('When listing jobs', function () {
33 it('Should fail with a bad start pagination', async function () {
34 await request(server.url)
35 .get(path)
36 .query({ start: 'hello' })
37 .set('Accept', 'application/json')
38 .set('Authorization', 'Bearer ' + server.accessToken)
39 .expect(400)
40 })
41
42 it('Should fail with a bad count pagination', async function () {
43 await request(server.url)
44 .get(path)
45 .query({ count: 'hello' })
46 .set('Accept', 'application/json')
47 .set('Authorization', 'Bearer ' + server.accessToken)
48 .expect(400)
49 })
50
51 it('Should fail with an incorrect sort', async function () {
52 await request(server.url)
53 .get(path)
54 .query({ sort: 'hello' })
55 .set('Accept', 'application/json')
56 .set('Authorization', 'Bearer ' + server.accessToken)
57 .expect(400)
58 })
59
60 it('Should fail with a non authenticated user', async function () {
61 await request(server.url)
62 .get(path)
63 .set('Accept', 'application/json')
64 .expect(401)
65 })
66
67 it('Should fail with a non admin user', async function () {
68 await request(server.url)
69 .get(path)
70 .set('Accept', 'application/json')
71 .set('Authorization', 'Bearer ' + userAccessToken)
72 .expect(403)
73 })
74 })
75
76 after(async function () {
77 killallServers([ server ])
78
79 // Keep the logs if the test failed
80 if (this['ok']) {
81 await flushTests()
82 }
83 })
84})