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