]>
Commit | Line | Data |
---|---|---|
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | import { omit } from 'lodash' | |
6 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | |
7 | import { | |
8 | buildAbsoluteFixturePath, | |
9 | ChannelsCommand, | |
10 | cleanupTests, | |
11 | createUser, | |
12 | flushAndRunServer, | |
13 | immutableAssign, | |
14 | makeGetRequest, | |
15 | makePostBodyRequest, | |
16 | makePutBodyRequest, | |
17 | makeUploadRequest, | |
18 | ServerInfo, | |
19 | setAccessTokensToServers, | |
20 | userLogin | |
21 | } from '../../../../shared/extra-utils' | |
22 | import { | |
23 | checkBadCountPagination, | |
24 | checkBadSortPagination, | |
25 | checkBadStartPagination | |
26 | } from '../../../../shared/extra-utils/requests/check-api-params' | |
27 | import { VideoChannelUpdate } from '../../../../shared/models/videos' | |
28 | ||
29 | const expect = chai.expect | |
30 | ||
31 | describe('Test video channels API validator', function () { | |
32 | const videoChannelPath = '/api/v1/video-channels' | |
33 | let server: ServerInfo | |
34 | let accessTokenUser: string | |
35 | let command: ChannelsCommand | |
36 | ||
37 | // --------------------------------------------------------------- | |
38 | ||
39 | before(async function () { | |
40 | this.timeout(30000) | |
41 | ||
42 | server = await flushAndRunServer(1) | |
43 | ||
44 | await setAccessTokensToServers([ server ]) | |
45 | ||
46 | const user = { | |
47 | username: 'fake', | |
48 | password: 'fake_password' | |
49 | } | |
50 | ||
51 | { | |
52 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | |
53 | accessTokenUser = await userLogin(server, user) | |
54 | } | |
55 | ||
56 | command = server.channelsCommand | |
57 | }) | |
58 | ||
59 | describe('When listing a video channels', function () { | |
60 | it('Should fail with a bad start pagination', async function () { | |
61 | await checkBadStartPagination(server.url, videoChannelPath, server.accessToken) | |
62 | }) | |
63 | ||
64 | it('Should fail with a bad count pagination', async function () { | |
65 | await checkBadCountPagination(server.url, videoChannelPath, server.accessToken) | |
66 | }) | |
67 | ||
68 | it('Should fail with an incorrect sort', async function () { | |
69 | await checkBadSortPagination(server.url, videoChannelPath, server.accessToken) | |
70 | }) | |
71 | }) | |
72 | ||
73 | describe('When listing account video channels', function () { | |
74 | const accountChannelPath = '/api/v1/accounts/fake/video-channels' | |
75 | ||
76 | it('Should fail with a bad start pagination', async function () { | |
77 | await checkBadStartPagination(server.url, accountChannelPath, server.accessToken) | |
78 | }) | |
79 | ||
80 | it('Should fail with a bad count pagination', async function () { | |
81 | await checkBadCountPagination(server.url, accountChannelPath, server.accessToken) | |
82 | }) | |
83 | ||
84 | it('Should fail with an incorrect sort', async function () { | |
85 | await checkBadSortPagination(server.url, accountChannelPath, server.accessToken) | |
86 | }) | |
87 | ||
88 | it('Should fail with a unknown account', async function () { | |
89 | await server.channelsCommand.listByAccount({ accountName: 'unknown', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
90 | }) | |
91 | ||
92 | it('Should succeed with the correct parameters', async function () { | |
93 | await makeGetRequest({ | |
94 | url: server.url, | |
95 | path: accountChannelPath, | |
96 | statusCodeExpected: HttpStatusCode.OK_200 | |
97 | }) | |
98 | }) | |
99 | }) | |
100 | ||
101 | describe('When adding a video channel', function () { | |
102 | const baseCorrectParams = { | |
103 | name: 'super_channel', | |
104 | displayName: 'hello', | |
105 | description: 'super description', | |
106 | support: 'super support text' | |
107 | } | |
108 | ||
109 | it('Should fail with a non authenticated user', async function () { | |
110 | await makePostBodyRequest({ | |
111 | url: server.url, | |
112 | path: videoChannelPath, | |
113 | token: 'none', | |
114 | fields: baseCorrectParams, | |
115 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
116 | }) | |
117 | }) | |
118 | ||
119 | it('Should fail with nothing', async function () { | |
120 | const fields = {} | |
121 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
122 | }) | |
123 | ||
124 | it('Should fail without a name', async function () { | |
125 | const fields = omit(baseCorrectParams, 'name') | |
126 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
127 | }) | |
128 | ||
129 | it('Should fail with a bad name', async function () { | |
130 | const fields = immutableAssign(baseCorrectParams, { name: 'super name' }) | |
131 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
132 | }) | |
133 | ||
134 | it('Should fail without a name', async function () { | |
135 | const fields = omit(baseCorrectParams, 'displayName') | |
136 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
137 | }) | |
138 | ||
139 | it('Should fail with a long name', async function () { | |
140 | const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) | |
141 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
142 | }) | |
143 | ||
144 | it('Should fail with a long description', async function () { | |
145 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) }) | |
146 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
147 | }) | |
148 | ||
149 | it('Should fail with a long support text', async function () { | |
150 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) | |
151 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
152 | }) | |
153 | ||
154 | it('Should succeed with the correct parameters', async function () { | |
155 | await makePostBodyRequest({ | |
156 | url: server.url, | |
157 | path: videoChannelPath, | |
158 | token: server.accessToken, | |
159 | fields: baseCorrectParams, | |
160 | statusCodeExpected: HttpStatusCode.OK_200 | |
161 | }) | |
162 | }) | |
163 | ||
164 | it('Should fail when adding a channel with the same username', async function () { | |
165 | await makePostBodyRequest({ | |
166 | url: server.url, | |
167 | path: videoChannelPath, | |
168 | token: server.accessToken, | |
169 | fields: baseCorrectParams, | |
170 | statusCodeExpected: HttpStatusCode.CONFLICT_409 | |
171 | }) | |
172 | }) | |
173 | }) | |
174 | ||
175 | describe('When updating a video channel', function () { | |
176 | const baseCorrectParams: VideoChannelUpdate = { | |
177 | displayName: 'hello', | |
178 | description: 'super description', | |
179 | support: 'toto', | |
180 | bulkVideosSupportUpdate: false | |
181 | } | |
182 | let path: string | |
183 | ||
184 | before(async function () { | |
185 | path = videoChannelPath + '/super_channel' | |
186 | }) | |
187 | ||
188 | it('Should fail with a non authenticated user', async function () { | |
189 | await makePutBodyRequest({ | |
190 | url: server.url, | |
191 | path, | |
192 | token: 'hi', | |
193 | fields: baseCorrectParams, | |
194 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
195 | }) | |
196 | }) | |
197 | ||
198 | it('Should fail with another authenticated user', async function () { | |
199 | await makePutBodyRequest({ | |
200 | url: server.url, | |
201 | path, | |
202 | token: accessTokenUser, | |
203 | fields: baseCorrectParams, | |
204 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | |
205 | }) | |
206 | }) | |
207 | ||
208 | it('Should fail with a long name', async function () { | |
209 | const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) | |
210 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
211 | }) | |
212 | ||
213 | it('Should fail with a long description', async function () { | |
214 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) }) | |
215 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
216 | }) | |
217 | ||
218 | it('Should fail with a long support text', async function () { | |
219 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) | |
220 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
221 | }) | |
222 | ||
223 | it('Should fail with a bad bulkVideosSupportUpdate field', async function () { | |
224 | const fields = immutableAssign(baseCorrectParams, { bulkVideosSupportUpdate: 'super' }) | |
225 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
226 | }) | |
227 | ||
228 | it('Should succeed with the correct parameters', async function () { | |
229 | await makePutBodyRequest({ | |
230 | url: server.url, | |
231 | path, | |
232 | token: server.accessToken, | |
233 | fields: baseCorrectParams, | |
234 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
235 | }) | |
236 | }) | |
237 | }) | |
238 | ||
239 | describe('When updating video channel avatar/banner', function () { | |
240 | const types = [ 'avatar', 'banner' ] | |
241 | let path: string | |
242 | ||
243 | before(async function () { | |
244 | path = videoChannelPath + '/super_channel' | |
245 | }) | |
246 | ||
247 | it('Should fail with an incorrect input file', async function () { | |
248 | for (const type of types) { | |
249 | const fields = {} | |
250 | const attaches = { | |
251 | [type + 'file']: buildAbsoluteFixturePath('video_short.mp4') | |
252 | } | |
253 | ||
254 | await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches }) | |
255 | } | |
256 | }) | |
257 | ||
258 | it('Should fail with a big file', async function () { | |
259 | for (const type of types) { | |
260 | const fields = {} | |
261 | const attaches = { | |
262 | [type + 'file']: buildAbsoluteFixturePath('avatar-big.png') | |
263 | } | |
264 | await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches }) | |
265 | } | |
266 | }) | |
267 | ||
268 | it('Should fail with an unauthenticated user', async function () { | |
269 | for (const type of types) { | |
270 | const fields = {} | |
271 | const attaches = { | |
272 | [type + 'file']: buildAbsoluteFixturePath('avatar.png') | |
273 | } | |
274 | await makeUploadRequest({ | |
275 | url: server.url, | |
276 | path: `${path}/${type}/pick`, | |
277 | fields, | |
278 | attaches, | |
279 | statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 | |
280 | }) | |
281 | } | |
282 | }) | |
283 | ||
284 | it('Should succeed with the correct params', async function () { | |
285 | for (const type of types) { | |
286 | const fields = {} | |
287 | const attaches = { | |
288 | [type + 'file']: buildAbsoluteFixturePath('avatar.png') | |
289 | } | |
290 | await makeUploadRequest({ | |
291 | url: server.url, | |
292 | path: `${path}/${type}/pick`, | |
293 | token: server.accessToken, | |
294 | fields, | |
295 | attaches, | |
296 | statusCodeExpected: HttpStatusCode.OK_200 | |
297 | }) | |
298 | } | |
299 | }) | |
300 | }) | |
301 | ||
302 | describe('When getting a video channel', function () { | |
303 | it('Should return the list of the video channels with nothing', async function () { | |
304 | const res = await makeGetRequest({ | |
305 | url: server.url, | |
306 | path: videoChannelPath, | |
307 | statusCodeExpected: HttpStatusCode.OK_200 | |
308 | }) | |
309 | ||
310 | expect(res.body.data).to.be.an('array') | |
311 | }) | |
312 | ||
313 | it('Should return 404 with an incorrect video channel', async function () { | |
314 | await makeGetRequest({ | |
315 | url: server.url, | |
316 | path: videoChannelPath + '/super_channel2', | |
317 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | |
318 | }) | |
319 | }) | |
320 | ||
321 | it('Should succeed with the correct parameters', async function () { | |
322 | await makeGetRequest({ | |
323 | url: server.url, | |
324 | path: videoChannelPath + '/super_channel', | |
325 | statusCodeExpected: HttpStatusCode.OK_200 | |
326 | }) | |
327 | }) | |
328 | }) | |
329 | ||
330 | describe('When deleting a video channel', function () { | |
331 | it('Should fail with a non authenticated user', async function () { | |
332 | await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
333 | }) | |
334 | ||
335 | it('Should fail with another authenticated user', async function () { | |
336 | await command.delete({ token: accessTokenUser, channelName: 'super_channel', expectedStatus: HttpStatusCode.FORBIDDEN_403 }) | |
337 | }) | |
338 | ||
339 | it('Should fail with an unknown video channel id', async function () { | |
340 | await command.delete({ channelName: 'super_channel2', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) | |
341 | }) | |
342 | ||
343 | it('Should succeed with the correct parameters', async function () { | |
344 | await command.delete({ channelName: 'super_channel' }) | |
345 | }) | |
346 | ||
347 | it('Should fail to delete the last user video channel', async function () { | |
348 | await command.delete({ channelName: 'root_channel', expectedStatus: HttpStatusCode.CONFLICT_409 }) | |
349 | }) | |
350 | }) | |
351 | ||
352 | after(async function () { | |
353 | await cleanupTests([ server ]) | |
354 | }) | |
355 | }) |