]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
5cd80545 C |
2 | |
3 | import 'mocha' | |
5cd80545 | 4 | |
9639bd17 | 5 | import { |
a1587156 | 6 | cleanupTests, |
9639bd17 | 7 | createUser, |
210feb6c | 8 | flushAndRunServer, |
9639bd17 | 9 | ServerInfo, |
10 | setAccessTokensToServers, | |
a1587156 | 11 | userLogin |
94565d52 | 12 | } from '../../../../shared/extra-utils' |
9639bd17 | 13 | import { |
14 | checkBadCountPagination, | |
15 | checkBadSortPagination, | |
16 | checkBadStartPagination | |
94565d52 C |
17 | } from '../../../../shared/extra-utils/requests/check-api-params' |
18 | import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' | |
2d53be02 | 19 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' |
5cd80545 C |
20 | |
21 | describe('Test jobs API validators', function () { | |
94a5ff8a | 22 | const path = '/api/v1/jobs/failed' |
5cd80545 C |
23 | let server: ServerInfo |
24 | let userAccessToken = '' | |
25 | ||
26 | // --------------------------------------------------------------- | |
27 | ||
28 | before(async function () { | |
29 | this.timeout(120000) | |
30 | ||
210feb6c | 31 | server = await flushAndRunServer(1) |
5cd80545 C |
32 | |
33 | await setAccessTokensToServers([ server ]) | |
34 | ||
35 | const user = { | |
36 | username: 'user1', | |
37 | password: 'my super password' | |
38 | } | |
1eddc9a7 | 39 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) |
eec63bbc | 40 | userAccessToken = await userLogin(server, user) |
5cd80545 C |
41 | }) |
42 | ||
43 | describe('When listing jobs', function () { | |
94a5ff8a C |
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 | ||
1061c73f C |
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 | ||
5cd80545 | 64 | it('Should fail with a bad start pagination', async function () { |
93e4a311 | 65 | await checkBadStartPagination(server.url, path, server.accessToken) |
5cd80545 C |
66 | }) |
67 | ||
68 | it('Should fail with a bad count pagination', async function () { | |
93e4a311 | 69 | await checkBadCountPagination(server.url, path, server.accessToken) |
5cd80545 C |
70 | }) |
71 | ||
72 | it('Should fail with an incorrect sort', async function () { | |
93e4a311 | 73 | await checkBadSortPagination(server.url, path, server.accessToken) |
5cd80545 C |
74 | }) |
75 | ||
76 | it('Should fail with a non authenticated user', async function () { | |
93e4a311 C |
77 | await makeGetRequest({ |
78 | url: server.url, | |
79 | path, | |
2d53be02 | 80 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 |
93e4a311 | 81 | }) |
5cd80545 C |
82 | }) |
83 | ||
84 | it('Should fail with a non admin user', async function () { | |
93e4a311 C |
85 | await makeGetRequest({ |
86 | url: server.url, | |
87 | path, | |
88 | token: userAccessToken, | |
2d53be02 | 89 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 |
93e4a311 | 90 | }) |
5cd80545 | 91 | }) |
1061c73f | 92 | |
5cd80545 C |
93 | }) |
94 | ||
7c3b7976 C |
95 | after(async function () { |
96 | await cleanupTests([ server ]) | |
5cd80545 C |
97 | }) |
98 | }) |