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