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