]>
Commit | Line | Data |
---|---|---|
1 | /* tslint:disable:no-unused-expression */ | |
2 | ||
3 | import 'mocha' | |
4 | ||
5 | import { | |
6 | createUser, | |
7 | flushTests, | |
8 | killallServers, | |
9 | flushAndRunServer, | |
10 | ServerInfo, | |
11 | setAccessTokensToServers, | |
12 | userLogin, | |
13 | cleanupTests | |
14 | } from '../../../../shared/extra-utils' | |
15 | import { | |
16 | checkBadCountPagination, | |
17 | checkBadSortPagination, | |
18 | checkBadStartPagination | |
19 | } from '../../../../shared/extra-utils/requests/check-api-params' | |
20 | import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' | |
21 | ||
22 | describe('Test jobs API validators', function () { | |
23 | const path = '/api/v1/jobs/failed' | |
24 | let server: ServerInfo | |
25 | let userAccessToken = '' | |
26 | ||
27 | // --------------------------------------------------------------- | |
28 | ||
29 | before(async function () { | |
30 | this.timeout(120000) | |
31 | ||
32 | server = await flushAndRunServer(1) | |
33 | ||
34 | await setAccessTokensToServers([ server ]) | |
35 | ||
36 | const user = { | |
37 | username: 'user1', | |
38 | password: 'my super password' | |
39 | } | |
40 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | |
41 | userAccessToken = await userLogin(server, user) | |
42 | }) | |
43 | ||
44 | describe('When listing jobs', function () { | |
45 | ||
46 | it('Should fail with a bad state', async function () { | |
47 | await makeGetRequest({ | |
48 | url: server.url, | |
49 | token: server.accessToken, | |
50 | path: path + 'ade' | |
51 | }) | |
52 | }) | |
53 | ||
54 | it('Should fail with an incorrect job type', async function () { | |
55 | await makeGetRequest({ | |
56 | url: server.url, | |
57 | token: server.accessToken, | |
58 | path, | |
59 | query: { | |
60 | jobType: 'toto' | |
61 | } | |
62 | }) | |
63 | }) | |
64 | ||
65 | it('Should fail with a bad start pagination', async function () { | |
66 | await checkBadStartPagination(server.url, path, server.accessToken) | |
67 | }) | |
68 | ||
69 | it('Should fail with a bad count pagination', async function () { | |
70 | await checkBadCountPagination(server.url, path, server.accessToken) | |
71 | }) | |
72 | ||
73 | it('Should fail with an incorrect sort', async function () { | |
74 | await checkBadSortPagination(server.url, path, server.accessToken) | |
75 | }) | |
76 | ||
77 | it('Should fail with a non authenticated user', async function () { | |
78 | await makeGetRequest({ | |
79 | url: server.url, | |
80 | path, | |
81 | statusCodeExpected: 401 | |
82 | }) | |
83 | }) | |
84 | ||
85 | it('Should fail with a non admin user', async function () { | |
86 | await makeGetRequest({ | |
87 | url: server.url, | |
88 | path, | |
89 | token: userAccessToken, | |
90 | statusCodeExpected: 403 | |
91 | }) | |
92 | }) | |
93 | ||
94 | }) | |
95 | ||
96 | after(async function () { | |
97 | await cleanupTests([ server ]) | |
98 | }) | |
99 | }) |