]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
5cd80545 | 2 | |
c55e3d72 | 3 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared' |
c0e8b12e | 4 | import { HttpStatusCode } from '@shared/models' |
419b520c C |
5 | import { |
6 | cleanupTests, | |
7 | createSingleServer, | |
8 | makeGetRequest, | |
9 | makePostBodyRequest, | |
10 | PeerTubeServer, | |
11 | setAccessTokensToServers | |
12 | } from '@shared/server-commands' | |
5cd80545 C |
13 | |
14 | describe('Test jobs API validators', function () { | |
94a5ff8a | 15 | const path = '/api/v1/jobs/failed' |
254d3579 | 16 | let server: PeerTubeServer |
5cd80545 C |
17 | let userAccessToken = '' |
18 | ||
19 | // --------------------------------------------------------------- | |
20 | ||
21 | before(async function () { | |
22 | this.timeout(120000) | |
23 | ||
254d3579 | 24 | server = await createSingleServer(1) |
5cd80545 C |
25 | |
26 | await setAccessTokensToServers([ server ]) | |
27 | ||
28 | const user = { | |
29 | username: 'user1', | |
30 | password: 'my super password' | |
31 | } | |
89d241a7 C |
32 | await server.users.create({ username: user.username, password: user.password }) |
33 | userAccessToken = await server.login.getAccessToken(user) | |
5cd80545 C |
34 | }) |
35 | ||
36 | describe('When listing jobs', function () { | |
94a5ff8a C |
37 | |
38 | it('Should fail with a bad state', async function () { | |
39 | await makeGetRequest({ | |
40 | url: server.url, | |
41 | token: server.accessToken, | |
42 | path: path + 'ade' | |
43 | }) | |
44 | }) | |
45 | ||
1061c73f C |
46 | it('Should fail with an incorrect job type', async function () { |
47 | await makeGetRequest({ | |
48 | url: server.url, | |
49 | token: server.accessToken, | |
50 | path, | |
51 | query: { | |
52 | jobType: 'toto' | |
53 | } | |
54 | }) | |
55 | }) | |
56 | ||
5cd80545 | 57 | it('Should fail with a bad start pagination', async function () { |
93e4a311 | 58 | await checkBadStartPagination(server.url, path, server.accessToken) |
5cd80545 C |
59 | }) |
60 | ||
61 | it('Should fail with a bad count pagination', async function () { | |
93e4a311 | 62 | await checkBadCountPagination(server.url, path, server.accessToken) |
5cd80545 C |
63 | }) |
64 | ||
65 | it('Should fail with an incorrect sort', async function () { | |
93e4a311 | 66 | await checkBadSortPagination(server.url, path, server.accessToken) |
5cd80545 C |
67 | }) |
68 | ||
69 | it('Should fail with a non authenticated user', async function () { | |
93e4a311 C |
70 | await makeGetRequest({ |
71 | url: server.url, | |
72 | path, | |
c0e8b12e | 73 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
93e4a311 | 74 | }) |
5cd80545 C |
75 | }) |
76 | ||
77 | it('Should fail with a non admin user', async function () { | |
93e4a311 C |
78 | await makeGetRequest({ |
79 | url: server.url, | |
80 | path, | |
81 | token: userAccessToken, | |
c0e8b12e | 82 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
93e4a311 | 83 | }) |
5cd80545 | 84 | }) |
419b520c C |
85 | }) |
86 | ||
87 | describe('When pausing/resuming the job queue', async function () { | |
88 | const commands = [ 'pause', 'resume' ] | |
89 | ||
90 | it('Should fail with a non authenticated user', async function () { | |
91 | for (const command of commands) { | |
92 | await makePostBodyRequest({ | |
93 | url: server.url, | |
94 | path: '/api/v1/jobs/' + command, | |
95 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
96 | }) | |
97 | } | |
98 | }) | |
1061c73f | 99 | |
419b520c C |
100 | it('Should fail with a non admin user', async function () { |
101 | for (const command of commands) { | |
102 | await makePostBodyRequest({ | |
103 | url: server.url, | |
104 | path: '/api/v1/jobs/' + command, | |
105 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
106 | }) | |
107 | } | |
108 | }) | |
109 | ||
110 | it('Should succeed with the correct params', async function () { | |
111 | for (const command of commands) { | |
112 | await makePostBodyRequest({ | |
113 | url: server.url, | |
114 | path: '/api/v1/jobs/' + command, | |
115 | token: server.accessToken, | |
116 | expectedStatus: HttpStatusCode.NO_CONTENT_204 | |
117 | }) | |
118 | } | |
119 | }) | |
5cd80545 C |
120 | }) |
121 | ||
7c3b7976 C |
122 | after(async function () { |
123 | await cleanupTests([ server ]) | |
5cd80545 C |
124 | }) |
125 | }) |