1 /* tslint:disable:no-unused-expression */
4 import * as request from 'supertest'
6 import { createUser, flushTests, userLogin, killallServers, runServer, ServerInfo, setAccessTokensToServers } from '../../utils'
7 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
8 import { makeGetRequest } from '../../utils/requests/requests'
10 describe('Test jobs API validators', function () {
11 const path = '/api/v1/jobs/'
12 let server: ServerInfo
13 let userAccessToken = ''
15 // ---------------------------------------------------------------
17 before(async function () {
22 server = await runServer(1)
24 await setAccessTokensToServers([ server ])
28 password: 'my super password'
30 await createUser(server.url, server.accessToken, user.username, user.password)
31 userAccessToken = await userLogin(server, user)
34 describe('When listing jobs', function () {
35 it('Should fail with a bad start pagination', async function () {
36 await checkBadStartPagination(server.url, path, server.accessToken)
39 it('Should fail with a bad count pagination', async function () {
40 await checkBadCountPagination(server.url, path, server.accessToken)
43 it('Should fail with an incorrect sort', async function () {
44 await checkBadSortPagination(server.url, path, server.accessToken)
47 it('Should fail with a non authenticated user', async function () {
48 await makeGetRequest({
51 statusCodeExpected: 401
55 it('Should fail with a non admin user', async function () {
56 await makeGetRequest({
59 token: userAccessToken,
60 statusCodeExpected: 403
65 after(async function () {
66 killallServers([ server ])
68 // Keep the logs if the test failed