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