1 /* tslint:disable:no-unused-expression */
4 import * as request from 'supertest'
6 import { createUser, flushTests, getUserAccessToken, killallServers, runServer, ServerInfo, setAccessTokensToServers } from '../../utils'
8 describe('Test jobs API validators', function () {
9 const path = '/api/v1/jobs/'
10 let server: ServerInfo
11 let userAccessToken = ''
13 // ---------------------------------------------------------------
15 before(async function () {
20 server = await runServer(1)
22 await setAccessTokensToServers([ server ])
26 password: 'my super password'
28 await createUser(server.url, server.accessToken, user.username, user.password)
29 userAccessToken = await getUserAccessToken(server, user)
32 describe('When listing jobs', function () {
33 it('Should fail with a bad start pagination', async function () {
34 await request(server.url)
36 .query({ start: 'hello' })
37 .set('Accept', 'application/json')
38 .set('Authorization', 'Bearer ' + server.accessToken)
42 it('Should fail with a bad count pagination', async function () {
43 await request(server.url)
45 .query({ count: 'hello' })
46 .set('Accept', 'application/json')
47 .set('Authorization', 'Bearer ' + server.accessToken)
51 it('Should fail with an incorrect sort', async function () {
52 await request(server.url)
54 .query({ sort: 'hello' })
55 .set('Accept', 'application/json')
56 .set('Authorization', 'Bearer ' + server.accessToken)
60 it('Should fail with a non authenticated user', async function () {
61 await request(server.url)
63 .set('Accept', 'application/json')
67 it('Should fail with a non admin user', async function () {
68 await request(server.url)
70 .set('Accept', 'application/json')
71 .set('Authorization', 'Bearer ' + userAccessToken)
76 after(async function () {
77 killallServers([ server ])
79 // Keep the logs if the test failed