aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params/jobs.ts43
-rw-r--r--server/tests/utils/requests/check-api-params.ts9
2 files changed, 22 insertions, 30 deletions
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts
index 3795d1d64..46b05cb4e 100644
--- a/server/tests/api/check-params/jobs.ts
+++ b/server/tests/api/check-params/jobs.ts
@@ -4,6 +4,8 @@ import 'mocha'
4import * as request from 'supertest' 4import * as request from 'supertest'
5 5
6import { createUser, flushTests, userLogin, killallServers, runServer, ServerInfo, setAccessTokensToServers } from '../../utils' 6import { createUser, flushTests, userLogin, killallServers, runServer, ServerInfo, setAccessTokensToServers } from '../../utils'
7import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
8import { makeGetRequest } from '../../utils/requests/requests'
7 9
8describe('Test jobs API validators', function () { 10describe('Test jobs API validators', function () {
9 const path = '/api/v1/jobs/' 11 const path = '/api/v1/jobs/'
@@ -31,45 +33,32 @@ describe('Test jobs API validators', function () {
31 33
32 describe('When listing jobs', function () { 34 describe('When listing jobs', function () {
33 it('Should fail with a bad start pagination', async function () { 35 it('Should fail with a bad start pagination', async function () {
34 await request(server.url) 36 await checkBadStartPagination(server.url, path, server.accessToken)
35 .get(path)
36 .query({ start: 'hello' })
37 .set('Accept', 'application/json')
38 .set('Authorization', 'Bearer ' + server.accessToken)
39 .expect(400)
40 }) 37 })
41 38
42 it('Should fail with a bad count pagination', async function () { 39 it('Should fail with a bad count pagination', async function () {
43 await request(server.url) 40 await checkBadCountPagination(server.url, path, server.accessToken)
44 .get(path)
45 .query({ count: 'hello' })
46 .set('Accept', 'application/json')
47 .set('Authorization', 'Bearer ' + server.accessToken)
48 .expect(400)
49 }) 41 })
50 42
51 it('Should fail with an incorrect sort', async function () { 43 it('Should fail with an incorrect sort', async function () {
52 await request(server.url) 44 await checkBadSortPagination(server.url, path, server.accessToken)
53 .get(path)
54 .query({ sort: 'hello' })
55 .set('Accept', 'application/json')
56 .set('Authorization', 'Bearer ' + server.accessToken)
57 .expect(400)
58 }) 45 })
59 46
60 it('Should fail with a non authenticated user', async function () { 47 it('Should fail with a non authenticated user', async function () {
61 await request(server.url) 48 await makeGetRequest({
62 .get(path) 49 url: server.url,
63 .set('Accept', 'application/json') 50 path,
64 .expect(401) 51 statusCodeExpected: 401
52 })
65 }) 53 })
66 54
67 it('Should fail with a non admin user', async function () { 55 it('Should fail with a non admin user', async function () {
68 await request(server.url) 56 await makeGetRequest({
69 .get(path) 57 url: server.url,
70 .set('Accept', 'application/json') 58 path,
71 .set('Authorization', 'Bearer ' + userAccessToken) 59 token: userAccessToken,
72 .expect(403) 60 statusCodeExpected: 403
61 })
73 }) 62 })
74 }) 63 })
75 64
diff --git a/server/tests/utils/requests/check-api-params.ts b/server/tests/utils/requests/check-api-params.ts
index fbd660629..7550eb3d8 100644
--- a/server/tests/utils/requests/check-api-params.ts
+++ b/server/tests/utils/requests/check-api-params.ts
@@ -1,27 +1,30 @@
1import { makeGetRequest } from './requests' 1import { makeGetRequest } from './requests'
2 2
3function checkBadStartPagination (url: string, path: string) { 3function checkBadStartPagination (url: string, path: string, token?: string) {
4 return makeGetRequest({ 4 return makeGetRequest({
5 url, 5 url,
6 path, 6 path,
7 token,
7 query: { start: 'hello' }, 8 query: { start: 'hello' },
8 statusCodeExpected: 400 9 statusCodeExpected: 400
9 }) 10 })
10} 11}
11 12
12function checkBadCountPagination (url: string, path: string) { 13function checkBadCountPagination (url: string, path: string, token?: string) {
13 return makeGetRequest({ 14 return makeGetRequest({
14 url, 15 url,
15 path, 16 path,
17 token,
16 query: { count: 'hello' }, 18 query: { count: 'hello' },
17 statusCodeExpected: 400 19 statusCodeExpected: 400
18 }) 20 })
19} 21}
20 22
21function checkBadSortPagination (url: string, path: string) { 23function checkBadSortPagination (url: string, path: string, token?: string) {
22 return makeGetRequest({ 24 return makeGetRequest({
23 url, 25 url,
24 path, 26 path,
27 token,
25 query: { sort: 'hello' }, 28 query: { sort: 'hello' },
26 statusCodeExpected: 400 29 statusCodeExpected: 400
27 }) 30 })