]>
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 { join } from 'path' | |
7 | import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' | |
8 | import { | |
9 | checkUploadVideoParam, | |
10 | cleanupTests, | |
11 | createUser, | |
12 | flushAndRunServer, | |
13 | getMyUserInformation, | |
14 | getVideo, | |
15 | getVideosList, | |
16 | immutableAssign, | |
17 | makeDeleteRequest, | |
18 | makeGetRequest, | |
19 | makePutBodyRequest, | |
20 | makeUploadRequest, | |
21 | removeVideo, | |
22 | root, | |
23 | ServerInfo, | |
24 | setAccessTokensToServers, | |
25 | userLogin | |
26 | } from '../../../../shared/extra-utils' | |
27 | import { | |
28 | checkBadCountPagination, | |
29 | checkBadSortPagination, | |
30 | checkBadStartPagination | |
31 | } from '../../../../shared/extra-utils/requests/check-api-params' | |
32 | import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum' | |
33 | import { randomInt } from '@shared/core-utils' | |
34 | ||
35 | const expect = chai.expect | |
36 | ||
37 | describe('Test videos API validator', function () { | |
38 | const path = '/api/v1/videos/' | |
39 | let server: ServerInfo | |
40 | let userAccessToken = '' | |
41 | let accountName: string | |
42 | let channelId: number | |
43 | let channelName: string | |
44 | let videoId | |
45 | ||
46 | // --------------------------------------------------------------- | |
47 | ||
48 | before(async function () { | |
49 | this.timeout(30000) | |
50 | ||
51 | server = await flushAndRunServer(1) | |
52 | ||
53 | await setAccessTokensToServers([ server ]) | |
54 | ||
55 | const username = 'user1' | |
56 | const password = 'my super password' | |
57 | await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) | |
58 | userAccessToken = await userLogin(server, { username, password }) | |
59 | ||
60 | { | |
61 | const res = await getMyUserInformation(server.url, server.accessToken) | |
62 | channelId = res.body.videoChannels[0].id | |
63 | channelName = res.body.videoChannels[0].name | |
64 | accountName = res.body.account.name + '@' + res.body.account.host | |
65 | } | |
66 | }) | |
67 | ||
68 | describe('When listing videos', function () { | |
69 | it('Should fail with a bad start pagination', async function () { | |
70 | await checkBadStartPagination(server.url, path) | |
71 | }) | |
72 | ||
73 | it('Should fail with a bad count pagination', async function () { | |
74 | await checkBadCountPagination(server.url, path) | |
75 | }) | |
76 | ||
77 | it('Should fail with an incorrect sort', async function () { | |
78 | await checkBadSortPagination(server.url, path) | |
79 | }) | |
80 | ||
81 | it('Should fail with a bad skipVideos query', async function () { | |
82 | await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: 'toto' } }) | |
83 | }) | |
84 | ||
85 | it('Should success with the correct parameters', async function () { | |
86 | await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: false } }) | |
87 | }) | |
88 | }) | |
89 | ||
90 | describe('When searching a video', function () { | |
91 | ||
92 | it('Should fail with nothing', async function () { | |
93 | await makeGetRequest({ | |
94 | url: server.url, | |
95 | path: join(path, 'search'), | |
96 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
97 | }) | |
98 | }) | |
99 | ||
100 | it('Should fail with a bad start pagination', async function () { | |
101 | await checkBadStartPagination(server.url, join(path, 'search', 'test')) | |
102 | }) | |
103 | ||
104 | it('Should fail with a bad count pagination', async function () { | |
105 | await checkBadCountPagination(server.url, join(path, 'search', 'test')) | |
106 | }) | |
107 | ||
108 | it('Should fail with an incorrect sort', async function () { | |
109 | await checkBadSortPagination(server.url, join(path, 'search', 'test')) | |
110 | }) | |
111 | ||
112 | it('Should success with the correct parameters', async function () { | |
113 | await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 }) | |
114 | }) | |
115 | }) | |
116 | ||
117 | describe('When listing my videos', function () { | |
118 | const path = '/api/v1/users/me/videos' | |
119 | ||
120 | it('Should fail with a bad start pagination', async function () { | |
121 | await checkBadStartPagination(server.url, path, server.accessToken) | |
122 | }) | |
123 | ||
124 | it('Should fail with a bad count pagination', async function () { | |
125 | await checkBadCountPagination(server.url, path, server.accessToken) | |
126 | }) | |
127 | ||
128 | it('Should fail with an incorrect sort', async function () { | |
129 | await checkBadSortPagination(server.url, path, server.accessToken) | |
130 | }) | |
131 | ||
132 | it('Should success with the correct parameters', async function () { | |
133 | await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: HttpStatusCode.OK_200 }) | |
134 | }) | |
135 | }) | |
136 | ||
137 | describe('When listing account videos', function () { | |
138 | let path: string | |
139 | ||
140 | before(async function () { | |
141 | path = '/api/v1/accounts/' + accountName + '/videos' | |
142 | }) | |
143 | ||
144 | it('Should fail with a bad start pagination', async function () { | |
145 | await checkBadStartPagination(server.url, path, server.accessToken) | |
146 | }) | |
147 | ||
148 | it('Should fail with a bad count pagination', async function () { | |
149 | await checkBadCountPagination(server.url, path, server.accessToken) | |
150 | }) | |
151 | ||
152 | it('Should fail with an incorrect sort', async function () { | |
153 | await checkBadSortPagination(server.url, path, server.accessToken) | |
154 | }) | |
155 | ||
156 | it('Should success with the correct parameters', async function () { | |
157 | await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 }) | |
158 | }) | |
159 | }) | |
160 | ||
161 | describe('When listing video channel videos', function () { | |
162 | let path: string | |
163 | ||
164 | before(async function () { | |
165 | path = '/api/v1/video-channels/' + channelName + '/videos' | |
166 | }) | |
167 | ||
168 | it('Should fail with a bad start pagination', async function () { | |
169 | await checkBadStartPagination(server.url, path, server.accessToken) | |
170 | }) | |
171 | ||
172 | it('Should fail with a bad count pagination', async function () { | |
173 | await checkBadCountPagination(server.url, path, server.accessToken) | |
174 | }) | |
175 | ||
176 | it('Should fail with an incorrect sort', async function () { | |
177 | await checkBadSortPagination(server.url, path, server.accessToken) | |
178 | }) | |
179 | ||
180 | it('Should success with the correct parameters', async function () { | |
181 | await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 }) | |
182 | }) | |
183 | }) | |
184 | ||
185 | describe('When adding a video', function () { | |
186 | let baseCorrectParams | |
187 | const baseCorrectAttaches = { | |
188 | fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.webm') | |
189 | } | |
190 | ||
191 | before(function () { | |
192 | // Put in before to have channelId | |
193 | baseCorrectParams = { | |
194 | name: 'my super name', | |
195 | category: 5, | |
196 | licence: 1, | |
197 | language: 'pt', | |
198 | nsfw: false, | |
199 | commentsEnabled: true, | |
200 | downloadEnabled: true, | |
201 | waitTranscoding: true, | |
202 | description: 'my super description', | |
203 | support: 'my super support text', | |
204 | tags: [ 'tag1', 'tag2' ], | |
205 | privacy: VideoPrivacy.PUBLIC, | |
206 | channelId: channelId, | |
207 | originallyPublishedAt: new Date().toISOString() | |
208 | } | |
209 | }) | |
210 | ||
211 | function runSuite (mode: 'legacy' | 'resumable') { | |
212 | ||
213 | it('Should fail with nothing', async function () { | |
214 | const fields = {} | |
215 | const attaches = {} | |
216 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
217 | }) | |
218 | ||
219 | it('Should fail without name', async function () { | |
220 | const fields = omit(baseCorrectParams, 'name') | |
221 | const attaches = baseCorrectAttaches | |
222 | ||
223 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
224 | }) | |
225 | ||
226 | it('Should fail with a long name', async function () { | |
227 | const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) | |
228 | const attaches = baseCorrectAttaches | |
229 | ||
230 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
231 | }) | |
232 | ||
233 | it('Should fail with a bad category', async function () { | |
234 | const fields = immutableAssign(baseCorrectParams, { category: 125 }) | |
235 | const attaches = baseCorrectAttaches | |
236 | ||
237 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
238 | }) | |
239 | ||
240 | it('Should fail with a bad licence', async function () { | |
241 | const fields = immutableAssign(baseCorrectParams, { licence: 125 }) | |
242 | const attaches = baseCorrectAttaches | |
243 | ||
244 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
245 | }) | |
246 | ||
247 | it('Should fail with a bad language', async function () { | |
248 | const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) | |
249 | const attaches = baseCorrectAttaches | |
250 | ||
251 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
252 | }) | |
253 | ||
254 | it('Should fail with a long description', async function () { | |
255 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) | |
256 | const attaches = baseCorrectAttaches | |
257 | ||
258 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
259 | }) | |
260 | ||
261 | it('Should fail with a long support text', async function () { | |
262 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) | |
263 | const attaches = baseCorrectAttaches | |
264 | ||
265 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
266 | }) | |
267 | ||
268 | it('Should fail without a channel', async function () { | |
269 | const fields = omit(baseCorrectParams, 'channelId') | |
270 | const attaches = baseCorrectAttaches | |
271 | ||
272 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
273 | }) | |
274 | ||
275 | it('Should fail with a bad channel', async function () { | |
276 | const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) | |
277 | const attaches = baseCorrectAttaches | |
278 | ||
279 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
280 | }) | |
281 | ||
282 | it('Should fail with another user channel', async function () { | |
283 | const user = { | |
284 | username: 'fake' + randomInt(0, 1500), | |
285 | password: 'fake_password' | |
286 | } | |
287 | await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) | |
288 | ||
289 | const accessTokenUser = await userLogin(server, user) | |
290 | const res = await getMyUserInformation(server.url, accessTokenUser) | |
291 | const customChannelId = res.body.videoChannels[0].id | |
292 | ||
293 | const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) | |
294 | const attaches = baseCorrectAttaches | |
295 | ||
296 | await checkUploadVideoParam(server.url, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
297 | }) | |
298 | ||
299 | it('Should fail with too many tags', async function () { | |
300 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) | |
301 | const attaches = baseCorrectAttaches | |
302 | ||
303 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
304 | }) | |
305 | ||
306 | it('Should fail with a tag length too low', async function () { | |
307 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) | |
308 | const attaches = baseCorrectAttaches | |
309 | ||
310 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
311 | }) | |
312 | ||
313 | it('Should fail with a tag length too big', async function () { | |
314 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) | |
315 | const attaches = baseCorrectAttaches | |
316 | ||
317 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
318 | }) | |
319 | ||
320 | it('Should fail with a bad schedule update (miss updateAt)', async function () { | |
321 | const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }) | |
322 | const attaches = baseCorrectAttaches | |
323 | ||
324 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
325 | }) | |
326 | ||
327 | it('Should fail with a bad schedule update (wrong updateAt)', async function () { | |
328 | const fields = immutableAssign(baseCorrectParams, { | |
329 | scheduleUpdate: { | |
330 | privacy: VideoPrivacy.PUBLIC, | |
331 | updateAt: 'toto' | |
332 | } | |
333 | }) | |
334 | const attaches = baseCorrectAttaches | |
335 | ||
336 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
337 | }) | |
338 | ||
339 | it('Should fail with a bad originally published at attribute', async function () { | |
340 | const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' }) | |
341 | const attaches = baseCorrectAttaches | |
342 | ||
343 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
344 | }) | |
345 | ||
346 | it('Should fail without an input file', async function () { | |
347 | const fields = baseCorrectParams | |
348 | const attaches = {} | |
349 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
350 | }) | |
351 | ||
352 | it('Should fail with an incorrect input file', async function () { | |
353 | const fields = baseCorrectParams | |
354 | let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') } | |
355 | ||
356 | await checkUploadVideoParam( | |
357 | server.url, | |
358 | server.accessToken, | |
359 | { ...fields, ...attaches }, | |
360 | HttpStatusCode.UNPROCESSABLE_ENTITY_422, | |
361 | mode | |
362 | ) | |
363 | ||
364 | attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') } | |
365 | await checkUploadVideoParam( | |
366 | server.url, | |
367 | server.accessToken, | |
368 | { ...fields, ...attaches }, | |
369 | HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415, | |
370 | mode | |
371 | ) | |
372 | }) | |
373 | ||
374 | it('Should fail with an incorrect thumbnail file', async function () { | |
375 | const fields = baseCorrectParams | |
376 | const attaches = { | |
377 | thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'), | |
378 | fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') | |
379 | } | |
380 | ||
381 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
382 | }) | |
383 | ||
384 | it('Should fail with a big thumbnail file', async function () { | |
385 | const fields = baseCorrectParams | |
386 | const attaches = { | |
387 | thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'), | |
388 | fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') | |
389 | } | |
390 | ||
391 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
392 | }) | |
393 | ||
394 | it('Should fail with an incorrect preview file', async function () { | |
395 | const fields = baseCorrectParams | |
396 | const attaches = { | |
397 | previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'), | |
398 | fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') | |
399 | } | |
400 | ||
401 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
402 | }) | |
403 | ||
404 | it('Should fail with a big preview file', async function () { | |
405 | const fields = baseCorrectParams | |
406 | const attaches = { | |
407 | previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'), | |
408 | fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') | |
409 | } | |
410 | ||
411 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) | |
412 | }) | |
413 | ||
414 | it('Should succeed with the correct parameters', async function () { | |
415 | this.timeout(10000) | |
416 | ||
417 | const fields = baseCorrectParams | |
418 | ||
419 | { | |
420 | const attaches = baseCorrectAttaches | |
421 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) | |
422 | } | |
423 | ||
424 | { | |
425 | const attaches = immutableAssign(baseCorrectAttaches, { | |
426 | videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') | |
427 | }) | |
428 | ||
429 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) | |
430 | } | |
431 | ||
432 | { | |
433 | const attaches = immutableAssign(baseCorrectAttaches, { | |
434 | videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv') | |
435 | }) | |
436 | ||
437 | await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) | |
438 | } | |
439 | }) | |
440 | } | |
441 | ||
442 | describe('Resumable upload', function () { | |
443 | runSuite('resumable') | |
444 | }) | |
445 | ||
446 | describe('Legacy upload', function () { | |
447 | runSuite('legacy') | |
448 | }) | |
449 | }) | |
450 | ||
451 | describe('When updating a video', function () { | |
452 | const baseCorrectParams = { | |
453 | name: 'my super name', | |
454 | category: 5, | |
455 | licence: 2, | |
456 | language: 'pt', | |
457 | nsfw: false, | |
458 | commentsEnabled: false, | |
459 | downloadEnabled: false, | |
460 | description: 'my super description', | |
461 | privacy: VideoPrivacy.PUBLIC, | |
462 | tags: [ 'tag1', 'tag2' ] | |
463 | } | |
464 | ||
465 | before(async function () { | |
466 | const res = await getVideosList(server.url) | |
467 | videoId = res.body.data[0].uuid | |
468 | }) | |
469 | ||
470 | it('Should fail with nothing', async function () { | |
471 | const fields = {} | |
472 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
473 | }) | |
474 | ||
475 | it('Should fail without a valid uuid', async function () { | |
476 | const fields = baseCorrectParams | |
477 | await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields }) | |
478 | }) | |
479 | ||
480 | it('Should fail with an unknown id', async function () { | |
481 | const fields = baseCorrectParams | |
482 | ||
483 | await makePutBodyRequest({ | |
484 | url: server.url, | |
485 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06', | |
486 | token: server.accessToken, | |
487 | fields, | |
488 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | |
489 | }) | |
490 | }) | |
491 | ||
492 | it('Should fail with a long name', async function () { | |
493 | const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) | |
494 | ||
495 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
496 | }) | |
497 | ||
498 | it('Should fail with a bad category', async function () { | |
499 | const fields = immutableAssign(baseCorrectParams, { category: 125 }) | |
500 | ||
501 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
502 | }) | |
503 | ||
504 | it('Should fail with a bad licence', async function () { | |
505 | const fields = immutableAssign(baseCorrectParams, { licence: 125 }) | |
506 | ||
507 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
508 | }) | |
509 | ||
510 | it('Should fail with a bad language', async function () { | |
511 | const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) | |
512 | ||
513 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
514 | }) | |
515 | ||
516 | it('Should fail with a long description', async function () { | |
517 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) | |
518 | ||
519 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
520 | }) | |
521 | ||
522 | it('Should fail with a long support text', async function () { | |
523 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) | |
524 | ||
525 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
526 | }) | |
527 | ||
528 | it('Should fail with a bad channel', async function () { | |
529 | const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) | |
530 | ||
531 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
532 | }) | |
533 | ||
534 | it('Should fail with too many tags', async function () { | |
535 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) | |
536 | ||
537 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
538 | }) | |
539 | ||
540 | it('Should fail with a tag length too low', async function () { | |
541 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) | |
542 | ||
543 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
544 | }) | |
545 | ||
546 | it('Should fail with a tag length too big', async function () { | |
547 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) | |
548 | ||
549 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
550 | }) | |
551 | ||
552 | it('Should fail with a bad schedule update (miss updateAt)', async function () { | |
553 | const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }) | |
554 | ||
555 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
556 | }) | |
557 | ||
558 | it('Should fail with a bad schedule update (wrong updateAt)', async function () { | |
559 | const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } }) | |
560 | ||
561 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
562 | }) | |
563 | ||
564 | it('Should fail with a bad originally published at param', async function () { | |
565 | const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' }) | |
566 | ||
567 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
568 | }) | |
569 | ||
570 | it('Should fail with an incorrect thumbnail file', async function () { | |
571 | const fields = baseCorrectParams | |
572 | const attaches = { | |
573 | thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') | |
574 | } | |
575 | ||
576 | await makeUploadRequest({ | |
577 | url: server.url, | |
578 | method: 'PUT', | |
579 | path: path + videoId, | |
580 | token: server.accessToken, | |
581 | fields, | |
582 | attaches | |
583 | }) | |
584 | }) | |
585 | ||
586 | it('Should fail with a big thumbnail file', async function () { | |
587 | const fields = baseCorrectParams | |
588 | const attaches = { | |
589 | thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png') | |
590 | } | |
591 | ||
592 | await makeUploadRequest({ | |
593 | url: server.url, | |
594 | method: 'PUT', | |
595 | path: path + videoId, | |
596 | token: server.accessToken, | |
597 | fields, | |
598 | attaches | |
599 | }) | |
600 | }) | |
601 | ||
602 | it('Should fail with an incorrect preview file', async function () { | |
603 | const fields = baseCorrectParams | |
604 | const attaches = { | |
605 | previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') | |
606 | } | |
607 | ||
608 | await makeUploadRequest({ | |
609 | url: server.url, | |
610 | method: 'PUT', | |
611 | path: path + videoId, | |
612 | token: server.accessToken, | |
613 | fields, | |
614 | attaches | |
615 | }) | |
616 | }) | |
617 | ||
618 | it('Should fail with a big preview file', async function () { | |
619 | const fields = baseCorrectParams | |
620 | const attaches = { | |
621 | previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png') | |
622 | } | |
623 | ||
624 | await makeUploadRequest({ | |
625 | url: server.url, | |
626 | method: 'PUT', | |
627 | path: path + videoId, | |
628 | token: server.accessToken, | |
629 | fields, | |
630 | attaches | |
631 | }) | |
632 | }) | |
633 | ||
634 | it('Should fail with a video of another user without the appropriate right', async function () { | |
635 | const fields = baseCorrectParams | |
636 | ||
637 | await makePutBodyRequest({ | |
638 | url: server.url, | |
639 | path: path + videoId, | |
640 | token: userAccessToken, | |
641 | fields, | |
642 | statusCodeExpected: HttpStatusCode.FORBIDDEN_403 | |
643 | }) | |
644 | }) | |
645 | ||
646 | it('Should fail with a video of another server') | |
647 | ||
648 | it('Should succeed with the correct parameters', async function () { | |
649 | const fields = baseCorrectParams | |
650 | ||
651 | await makePutBodyRequest({ | |
652 | url: server.url, | |
653 | path: path + videoId, | |
654 | token: server.accessToken, | |
655 | fields, | |
656 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
657 | }) | |
658 | }) | |
659 | }) | |
660 | ||
661 | describe('When getting a video', function () { | |
662 | it('Should return the list of the videos with nothing', async function () { | |
663 | const res = await makeGetRequest({ | |
664 | url: server.url, | |
665 | path, | |
666 | statusCodeExpected: HttpStatusCode.OK_200 | |
667 | }) | |
668 | ||
669 | expect(res.body.data).to.be.an('array') | |
670 | expect(res.body.data.length).to.equal(6) | |
671 | }) | |
672 | ||
673 | it('Should fail without a correct uuid', async function () { | |
674 | await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400) | |
675 | }) | |
676 | ||
677 | it('Should return 404 with an incorrect video', async function () { | |
678 | await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) | |
679 | }) | |
680 | ||
681 | it('Should succeed with the correct parameters', async function () { | |
682 | await getVideo(server.url, videoId) | |
683 | }) | |
684 | }) | |
685 | ||
686 | describe('When rating a video', function () { | |
687 | let videoId | |
688 | ||
689 | before(async function () { | |
690 | const res = await getVideosList(server.url) | |
691 | videoId = res.body.data[0].id | |
692 | }) | |
693 | ||
694 | it('Should fail without a valid uuid', async function () { | |
695 | const fields = { | |
696 | rating: 'like' | |
697 | } | |
698 | await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields }) | |
699 | }) | |
700 | ||
701 | it('Should fail with an unknown id', async function () { | |
702 | const fields = { | |
703 | rating: 'like' | |
704 | } | |
705 | await makePutBodyRequest({ | |
706 | url: server.url, | |
707 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', | |
708 | token: server.accessToken, | |
709 | fields, | |
710 | statusCodeExpected: HttpStatusCode.NOT_FOUND_404 | |
711 | }) | |
712 | }) | |
713 | ||
714 | it('Should fail with a wrong rating', async function () { | |
715 | const fields = { | |
716 | rating: 'likes' | |
717 | } | |
718 | await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields }) | |
719 | }) | |
720 | ||
721 | it('Should succeed with the correct parameters', async function () { | |
722 | const fields = { | |
723 | rating: 'like' | |
724 | } | |
725 | await makePutBodyRequest({ | |
726 | url: server.url, | |
727 | path: path + videoId + '/rate', | |
728 | token: server.accessToken, | |
729 | fields, | |
730 | statusCodeExpected: HttpStatusCode.NO_CONTENT_204 | |
731 | }) | |
732 | }) | |
733 | }) | |
734 | ||
735 | describe('When removing a video', function () { | |
736 | it('Should have 404 with nothing', async function () { | |
737 | await makeDeleteRequest({ | |
738 | url: server.url, | |
739 | path, | |
740 | statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 | |
741 | }) | |
742 | }) | |
743 | ||
744 | it('Should fail without a correct uuid', async function () { | |
745 | await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) | |
746 | }) | |
747 | ||
748 | it('Should fail with a video which does not exist', async function () { | |
749 | await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) | |
750 | }) | |
751 | ||
752 | it('Should fail with a video of another user without the appropriate right', async function () { | |
753 | await removeVideo(server.url, userAccessToken, videoId, HttpStatusCode.FORBIDDEN_403) | |
754 | }) | |
755 | ||
756 | it('Should fail with a video of another server') | |
757 | ||
758 | it('Should succeed with the correct parameters', async function () { | |
759 | await removeVideo(server.url, server.accessToken, videoId) | |
760 | }) | |
761 | }) | |
762 | ||
763 | after(async function () { | |
764 | await cleanupTests([ server ]) | |
765 | }) | |
766 | }) |