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