1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import { omit } from 'lodash'
6 import { join } from 'path'
7 import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
22 setAccessTokensToServers,
25 } from '../../../../shared/extra-utils'
27 checkBadCountPagination,
28 checkBadSortPagination,
29 checkBadStartPagination
30 } from '../../../../shared/extra-utils/requests/check-api-params'
32 const expect = chai.expect
34 describe('Test videos API validator', function () {
35 const path = '/api/v1/videos/'
36 let server: ServerInfo
37 let userAccessToken = ''
38 let accountName: string
40 let channelName: string
43 // ---------------------------------------------------------------
45 before(async function () {
48 server = await flushAndRunServer(1)
50 await setAccessTokensToServers([ server ])
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 })
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
65 describe('When listing a video', function () {
66 it('Should fail with a bad start pagination', async function () {
67 await checkBadStartPagination(server.url, path)
70 it('Should fail with a bad count pagination', async function () {
71 await checkBadCountPagination(server.url, path)
74 it('Should fail with an incorrect sort', async function () {
75 await checkBadSortPagination(server.url, path)
78 it('Should success with the correct parameters', async function () {
79 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
83 describe('When searching a video', function () {
85 it('Should fail with nothing', async function () {
86 await makeGetRequest({
88 path: join(path, 'search'),
89 statusCodeExpected: 400
93 it('Should fail with a bad start pagination', async function () {
94 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
97 it('Should fail with a bad count pagination', async function () {
98 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
101 it('Should fail with an incorrect sort', async function () {
102 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
105 it('Should success with the correct parameters', async function () {
106 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
110 describe('When listing my videos', function () {
111 const path = '/api/v1/users/me/videos'
113 it('Should fail with a bad start pagination', async function () {
114 await checkBadStartPagination(server.url, path, server.accessToken)
117 it('Should fail with a bad count pagination', async function () {
118 await checkBadCountPagination(server.url, path, server.accessToken)
121 it('Should fail with an incorrect sort', async function () {
122 await checkBadSortPagination(server.url, path, server.accessToken)
125 it('Should success with the correct parameters', async function () {
126 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 })
130 describe('When listing account videos', function () {
133 before(async function () {
134 path = '/api/v1/accounts/' + accountName + '/videos'
137 it('Should fail with a bad start pagination', async function () {
138 await checkBadStartPagination(server.url, path, server.accessToken)
141 it('Should fail with a bad count pagination', async function () {
142 await checkBadCountPagination(server.url, path, server.accessToken)
145 it('Should fail with an incorrect sort', async function () {
146 await checkBadSortPagination(server.url, path, server.accessToken)
149 it('Should success with the correct parameters', async function () {
150 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
154 describe('When listing video channel videos', function () {
157 before(async function () {
158 path = '/api/v1/video-channels/' + channelName + '/videos'
161 it('Should fail with a bad start pagination', async function () {
162 await checkBadStartPagination(server.url, path, server.accessToken)
165 it('Should fail with a bad count pagination', async function () {
166 await checkBadCountPagination(server.url, path, server.accessToken)
169 it('Should fail with an incorrect sort', async function () {
170 await checkBadSortPagination(server.url, path, server.accessToken)
173 it('Should success with the correct parameters', async function () {
174 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
178 describe('When adding a video', function () {
179 let baseCorrectParams
180 const baseCorrectAttaches = {
181 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.webm')
185 // Put in before to have channelId
186 baseCorrectParams = {
187 name: 'my super name',
192 commentsEnabled: true,
193 downloadEnabled: true,
194 waitTranscoding: true,
195 description: 'my super description',
196 support: 'my super support text',
197 tags: [ 'tag1', 'tag2' ],
198 privacy: VideoPrivacy.PUBLIC,
199 channelId: channelId,
200 originallyPublishedAt: new Date().toISOString()
204 it('Should fail with nothing', async function () {
207 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
210 it('Should fail without name', async function () {
211 const fields = omit(baseCorrectParams, 'name')
212 const attaches = baseCorrectAttaches
214 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
217 it('Should fail with a long name', async function () {
218 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
219 const attaches = baseCorrectAttaches
221 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
224 it('Should fail with a bad category', async function () {
225 const fields = immutableAssign(baseCorrectParams, { category: 125 })
226 const attaches = baseCorrectAttaches
228 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
231 it('Should fail with a bad licence', async function () {
232 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
233 const attaches = baseCorrectAttaches
235 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
238 it('Should fail with a bad language', async function () {
239 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
240 const attaches = baseCorrectAttaches
242 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
245 it('Should fail with a long description', async function () {
246 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
247 const attaches = baseCorrectAttaches
249 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
252 it('Should fail with a long support text', async function () {
253 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
254 const attaches = baseCorrectAttaches
256 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
259 it('Should fail without a channel', async function () {
260 const fields = omit(baseCorrectParams, 'channelId')
261 const attaches = baseCorrectAttaches
263 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
266 it('Should fail with a bad channel', async function () {
267 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
268 const attaches = baseCorrectAttaches
270 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
273 it('Should fail with another user channel', async function () {
276 password: 'fake_password'
278 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
280 const accessTokenUser = await userLogin(server, user)
281 const res = await getMyUserInformation(server.url, accessTokenUser)
282 const customChannelId = res.body.videoChannels[0].id
284 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
285 const attaches = baseCorrectAttaches
287 await makeUploadRequest({ url: server.url, path: path + '/upload', token: userAccessToken, fields, attaches })
290 it('Should fail with too many tags', async function () {
291 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
292 const attaches = baseCorrectAttaches
294 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
297 it('Should fail with a tag length too low', async function () {
298 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
299 const attaches = baseCorrectAttaches
301 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
304 it('Should fail with a tag length too big', async function () {
305 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
306 const attaches = baseCorrectAttaches
308 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
311 it('Should fail with a bad schedule update (miss updateAt)', async function () {
312 const fields = immutableAssign(baseCorrectParams, { 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC })
313 const attaches = baseCorrectAttaches
315 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
318 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
319 const fields = immutableAssign(baseCorrectParams, {
320 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC,
321 'scheduleUpdate[updateAt]': 'toto'
323 const attaches = baseCorrectAttaches
325 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
328 it('Should fail with a bad originally published at attribute', async function () {
329 const fields = immutableAssign(baseCorrectParams, { 'originallyPublishedAt': 'toto' })
330 const attaches = baseCorrectAttaches
332 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
335 it('Should fail without an input file', async function () {
336 const fields = baseCorrectParams
338 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
341 it('Should fail with an incorrect input file', async function () {
342 const fields = baseCorrectParams
344 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm')
346 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
349 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv')
351 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
354 it('Should fail with an incorrect thumbnail file', async function () {
355 const fields = baseCorrectParams
357 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png'),
358 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
361 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
364 it('Should fail with a big thumbnail file', async function () {
365 const fields = baseCorrectParams
367 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'),
368 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
371 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
374 it('Should fail with an incorrect preview file', async function () {
375 const fields = baseCorrectParams
377 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png'),
378 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
381 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
384 it('Should fail with a big preview file', async function () {
385 const fields = baseCorrectParams
387 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png'),
388 'videofile': join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
391 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
394 it('Should succeed with the correct parameters', async function () {
397 const fields = baseCorrectParams
400 const attaches = baseCorrectAttaches
401 await makeUploadRequest({
403 path: path + '/upload',
404 token: server.accessToken,
407 statusCodeExpected: 200
412 const attaches = immutableAssign(baseCorrectAttaches, {
413 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
416 await makeUploadRequest({
418 path: path + '/upload',
419 token: server.accessToken,
422 statusCodeExpected: 200
427 const attaches = immutableAssign(baseCorrectAttaches, {
428 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
431 await makeUploadRequest({
433 path: path + '/upload',
434 token: server.accessToken,
437 statusCodeExpected: 200
443 describe('When updating a video', function () {
444 const baseCorrectParams = {
445 name: 'my super name',
450 commentsEnabled: false,
451 downloadEnabled: false,
452 description: 'my super description',
453 privacy: VideoPrivacy.PUBLIC,
454 tags: [ 'tag1', 'tag2' ]
457 before(async function () {
458 const res = await getVideosList(server.url)
459 videoId = res.body.data[0].uuid
462 it('Should fail with nothing', async function () {
464 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
467 it('Should fail without a valid uuid', async function () {
468 const fields = baseCorrectParams
469 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
472 it('Should fail with an unknown id', async function () {
473 const fields = baseCorrectParams
475 await makePutBodyRequest({
477 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
478 token: server.accessToken,
480 statusCodeExpected: 404
484 it('Should fail with a long name', async function () {
485 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
487 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
490 it('Should fail with a bad category', async function () {
491 const fields = immutableAssign(baseCorrectParams, { category: 125 })
493 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
496 it('Should fail with a bad licence', async function () {
497 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
499 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
502 it('Should fail with a bad language', async function () {
503 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
505 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
508 it('Should fail with a long description', async function () {
509 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
511 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
514 it('Should fail with a long support text', async function () {
515 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
517 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
520 it('Should fail with a bad channel', async function () {
521 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
523 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
526 it('Should fail with too many tags', async function () {
527 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
529 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
532 it('Should fail with a tag length too low', async function () {
533 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
535 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
538 it('Should fail with a tag length too big', async function () {
539 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
541 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
544 it('Should fail with a bad schedule update (miss updateAt)', async function () {
545 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
547 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
550 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
551 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
553 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
556 it('Should fail with a bad originally published at param', async function () {
557 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
559 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
562 it('Should fail with an incorrect thumbnail file', async function () {
563 const fields = baseCorrectParams
565 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png')
568 await makeUploadRequest({
571 path: path + videoId,
572 token: server.accessToken,
578 it('Should fail with a big thumbnail file', async function () {
579 const fields = baseCorrectParams
581 'thumbnailfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png')
584 await makeUploadRequest({
587 path: path + videoId,
588 token: server.accessToken,
594 it('Should fail with an incorrect preview file', async function () {
595 const fields = baseCorrectParams
597 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar.png')
600 await makeUploadRequest({
603 path: path + videoId,
604 token: server.accessToken,
610 it('Should fail with a big preview file', async function () {
611 const fields = baseCorrectParams
613 'previewfile': join(root(), 'server', 'tests', 'fixtures', 'avatar-big.png')
616 await makeUploadRequest({
619 path: path + videoId,
620 token: server.accessToken,
626 it('Should fail with a video of another user without the appropriate right', async function () {
627 const fields = baseCorrectParams
629 await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 })
632 it('Should fail with a video of another server')
634 it('Should succeed with the correct parameters', async function () {
635 const fields = baseCorrectParams
637 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
641 describe('When getting a video', function () {
642 it('Should return the list of the videos with nothing', async function () {
643 const res = await makeGetRequest({
646 statusCodeExpected: 200
649 expect(res.body.data).to.be.an('array')
650 expect(res.body.data.length).to.equal(3)
653 it('Should fail without a correct uuid', async function () {
654 await getVideo(server.url, 'coucou', 400)
657 it('Should return 404 with an incorrect video', async function () {
658 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
661 it('Should succeed with the correct parameters', async function () {
662 await getVideo(server.url, videoId)
666 describe('When rating a video', function () {
669 before(async function () {
670 const res = await getVideosList(server.url)
671 videoId = res.body.data[0].id
674 it('Should fail without a valid uuid', async function () {
678 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
681 it('Should fail with an unknown id', async function () {
685 await makePutBodyRequest({
687 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
688 token: server.accessToken,
690 statusCodeExpected: 404
694 it('Should fail with a wrong rating', async function () {
698 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
701 it('Should succeed with the correct parameters', async function () {
705 await makePutBodyRequest({
707 path: path + videoId + '/rate',
708 token: server.accessToken,
710 statusCodeExpected: 204
715 describe('When removing a video', function () {
716 it('Should have 404 with nothing', async function () {
717 await makeDeleteRequest({
720 statusCodeExpected: 400
724 it('Should fail without a correct uuid', async function () {
725 await removeVideo(server.url, server.accessToken, 'hello', 400)
728 it('Should fail with a video which does not exist', async function () {
729 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
732 it('Should fail with a video of another user without the appropriate right', async function () {
733 await removeVideo(server.url, userAccessToken, videoId, 403)
736 it('Should fail with a video of another server')
738 it('Should succeed with the correct parameters', async function () {
739 await removeVideo(server.url, server.accessToken, videoId)
743 after(async function () {
744 await cleanupTests([ server ])