]>
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 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | |
20 | ||
21 | describe('Test jobs API validators', function () { | |
22 | const path = '/api/v1/jobs/failed' | |
23 | let server: ServerInfo | |
24 | let userAccessToken = '' | |
25 | ||
26 | // --------------------------------------------------------------- | |
27 | ||
28 | before(async function () { | |
29 | this.timeout(120000) | |
30 | ||
31 | server = await flushAndRunServer(1) | |
32 | ||
33 | await setAccessTokensToServers([ server ]) | |
34 | ||
35 | const user = { | |
36 | username: 'user1', | |
37 | password: 'my super password' | |
38 | } | |
39 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | |
40 | userAccessToken = await userLogin(server, user) | |
41 | }) | |
42 | ||
43 | describe('When listing jobs', function () { | |
44 | ||
45 | it('Should fail with a bad state', async function () { | |
46 | await makeGetRequest({ | |
47 | url: server.url, | |
48 | token: server.accessToken, | |
49 | path: path + 'ade' | |
50 | }) | |
51 | }) | |
52 | ||
53 | it('Should fail with an incorrect job type', async function () { | |
54 | await makeGetRequest({ | |
55 | url: server.url, | |
56 | token: server.accessToken, | |
57 | path, | |
58 | query: { | |
59 | jobType: 'toto' | |
60 | } | |
61 | }) | |
62 | }) | |
63 | ||
64 | it('Should fail with a bad start pagination', async function () { | |
65 | await checkBadStartPagination(server.url, path, server.accessToken) | |
66 | }) | |
67 | ||
68 | it('Should fail with a bad count pagination', async function () { | |
69 | await checkBadCountPagination(server.url, path, server.accessToken) | |
70 | }) | |
71 | ||
72 | it('Should fail with an incorrect sort', async function () { | |
73 | await checkBadSortPagination(server.url, path, server.accessToken) | |
74 | }) | |
75 | ||
76 | it('Should fail with a non authenticated user', async function () { | |
77 | await makeGetRequest({ | |
78 | url: server.url, | |
79 | path, | |
80 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
81 | }) | |
82 | }) | |
83 | ||
84 | it('Should fail with a non admin user', async function () { | |
85 | await makeGetRequest({ | |
86 | url: server.url, | |
87 | path, | |
88 | token: userAccessToken, | |
89 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | |
90 | }) | |
91 | }) | |
92 | ||
93 | }) | |
94 | ||
95 | after(async function () { | |
96 | await cleanupTests([ server ]) | |
97 | }) | |
98 | }) |