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