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