From 93e4a311f37d7fc82ec81190553f8beae28fdef5 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 28 Dec 2017 14:40:11 +0100 Subject: Improve check jobs parameters tests --- server/tests/api/check-params/jobs.ts | 43 +++++++++++++---------------------- 1 file changed, 16 insertions(+), 27 deletions(-) (limited to 'server/tests/api') 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' import * as request from 'supertest' import { createUser, flushTests, userLogin, killallServers, runServer, ServerInfo, setAccessTokensToServers } from '../../utils' +import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' +import { makeGetRequest } from '../../utils/requests/requests' describe('Test jobs API validators', function () { const path = '/api/v1/jobs/' @@ -31,45 +33,32 @@ describe('Test jobs API validators', function () { describe('When listing jobs', function () { it('Should fail with a bad start pagination', async function () { - await request(server.url) - .get(path) - .query({ start: 'hello' }) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400) + await checkBadStartPagination(server.url, path, server.accessToken) }) it('Should fail with a bad count pagination', async function () { - await request(server.url) - .get(path) - .query({ count: 'hello' }) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400) + await checkBadCountPagination(server.url, path, server.accessToken) }) it('Should fail with an incorrect sort', async function () { - await request(server.url) - .get(path) - .query({ sort: 'hello' }) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + server.accessToken) - .expect(400) + await checkBadSortPagination(server.url, path, server.accessToken) }) it('Should fail with a non authenticated user', async function () { - await request(server.url) - .get(path) - .set('Accept', 'application/json') - .expect(401) + await makeGetRequest({ + url: server.url, + path, + statusCodeExpected: 401 + }) }) it('Should fail with a non admin user', async function () { - await request(server.url) - .get(path) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + userAccessToken) - .expect(403) + await makeGetRequest({ + url: server.url, + path, + token: userAccessToken, + statusCodeExpected: 403 + }) }) }) -- cgit v1.2.3