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'
9 createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest,
10 makeGetRequest, makeUploadRequest, makePutBodyRequest, removeVideo, uploadVideo,
11 flushAndRunServer, ServerInfo, setAccessTokensToServers, userLogin, updateCustomSubConfig
12 } from '../../../../shared/extra-utils'
14 checkBadCountPagination,
15 checkBadSortPagination,
16 checkBadStartPagination
17 } from '../../../../shared/extra-utils/requests/check-api-params'
18 import { getAccountsList } from '../../../../shared/extra-utils/users/accounts'
20 const expect = chai.expect
22 describe('Test videos API validator', function () {
23 const path = '/api/v1/videos/'
24 let server: ServerInfo
25 let userAccessToken = ''
26 let accountName: string
28 let channelName: string
31 // ---------------------------------------------------------------
33 before(async function () {
36 server = await flushAndRunServer(1)
38 await setAccessTokensToServers([ server ])
40 const username = 'user1'
41 const password = 'my super password'
42 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
43 userAccessToken = await userLogin(server, { username, password })
46 const res = await getMyUserInformation(server.url, server.accessToken)
47 channelId = res.body.videoChannels[ 0 ].id
48 channelName = res.body.videoChannels[ 0 ].name
49 accountName = res.body.account.name + '@' + res.body.account.host
53 describe('When listing a video', function () {
54 it('Should fail with a bad start pagination', async function () {
55 await checkBadStartPagination(server.url, path)
58 it('Should fail with a bad count pagination', async function () {
59 await checkBadCountPagination(server.url, path)
62 it('Should fail with an incorrect sort', async function () {
63 await checkBadSortPagination(server.url, path)
66 it('Should success with the correct parameters', async function () {
67 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
71 describe('When searching a video', function () {
73 it('Should fail with nothing', async function () {
74 await makeGetRequest({
76 path: join(path, 'search'),
77 statusCodeExpected: 400
81 it('Should fail with a bad start pagination', async function () {
82 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
85 it('Should fail with a bad count pagination', async function () {
86 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
89 it('Should fail with an incorrect sort', async function () {
90 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
93 it('Should success with the correct parameters', async function () {
94 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
98 describe('When listing my videos', function () {
99 const path = '/api/v1/users/me/videos'
101 it('Should fail with a bad start pagination', async function () {
102 await checkBadStartPagination(server.url, path, server.accessToken)
105 it('Should fail with a bad count pagination', async function () {
106 await checkBadCountPagination(server.url, path, server.accessToken)
109 it('Should fail with an incorrect sort', async function () {
110 await checkBadSortPagination(server.url, path, server.accessToken)
113 it('Should success with the correct parameters', async function () {
114 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 })
118 describe('When listing account videos', function () {
121 before(async function () {
122 path = '/api/v1/accounts/' + accountName + '/videos'
125 it('Should fail with a bad start pagination', async function () {
126 await checkBadStartPagination(server.url, path, server.accessToken)
129 it('Should fail with a bad count pagination', async function () {
130 await checkBadCountPagination(server.url, path, server.accessToken)
133 it('Should fail with an incorrect sort', async function () {
134 await checkBadSortPagination(server.url, path, server.accessToken)
137 it('Should success with the correct parameters', async function () {
138 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
142 describe('When listing video channel videos', function () {
145 before(async function () {
146 path = '/api/v1/video-channels/' + channelName + '/videos'
149 it('Should fail with a bad start pagination', async function () {
150 await checkBadStartPagination(server.url, path, server.accessToken)
153 it('Should fail with a bad count pagination', async function () {
154 await checkBadCountPagination(server.url, path, server.accessToken)
157 it('Should fail with an incorrect sort', async function () {
158 await checkBadSortPagination(server.url, path, server.accessToken)
161 it('Should success with the correct parameters', async function () {
162 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
166 describe('When adding a video', function () {
167 let baseCorrectParams
168 const baseCorrectAttaches = {
169 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.webm')
173 // Put in before to have channelId
174 baseCorrectParams = {
175 name: 'my super name',
180 commentsEnabled: true,
181 downloadEnabled: true,
182 waitTranscoding: true,
183 description: 'my super description',
184 support: 'my super support text',
185 tags: [ 'tag1', 'tag2' ],
186 privacy: VideoPrivacy.PUBLIC,
187 channelId: channelId,
188 originallyPublishedAt: new Date().toISOString()
192 it('Should fail with nothing', async function () {
195 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
198 it('Should fail without name', async function () {
199 const fields = omit(baseCorrectParams, 'name')
200 const attaches = baseCorrectAttaches
202 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
205 it('Should fail with a long name', async function () {
206 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
207 const attaches = baseCorrectAttaches
209 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
212 it('Should fail with a bad category', async function () {
213 const fields = immutableAssign(baseCorrectParams, { category: 125 })
214 const attaches = baseCorrectAttaches
216 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
219 it('Should fail with a bad licence', async function () {
220 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
221 const attaches = baseCorrectAttaches
223 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
226 it('Should fail with a bad language', async function () {
227 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
228 const attaches = baseCorrectAttaches
230 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
233 it('Should fail with a long description', async function () {
234 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
235 const attaches = baseCorrectAttaches
237 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
240 it('Should fail with a long support text', async function () {
241 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
242 const attaches = baseCorrectAttaches
244 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
247 it('Should fail without a channel', async function () {
248 const fields = omit(baseCorrectParams, 'channelId')
249 const attaches = baseCorrectAttaches
251 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
254 it('Should fail with a bad channel', async function () {
255 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
256 const attaches = baseCorrectAttaches
258 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
261 it('Should fail with another user channel', async function () {
264 password: 'fake_password'
266 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
268 const accessTokenUser = await userLogin(server, user)
269 const res = await getMyUserInformation(server.url, accessTokenUser)
270 const customChannelId = res.body.videoChannels[0].id
272 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
273 const attaches = baseCorrectAttaches
275 await makeUploadRequest({ url: server.url, path: path + '/upload', token: userAccessToken, fields, attaches })
278 it('Should fail with too many tags', async function () {
279 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
280 const attaches = baseCorrectAttaches
282 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
285 it('Should fail with a tag length too low', async function () {
286 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
287 const attaches = baseCorrectAttaches
289 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
292 it('Should fail with a tag length too big', async function () {
293 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
294 const attaches = baseCorrectAttaches
296 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
299 it('Should fail with a bad schedule update (miss updateAt)', async function () {
300 const fields = immutableAssign(baseCorrectParams, { 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC })
301 const attaches = baseCorrectAttaches
303 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
306 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
307 const fields = immutableAssign(baseCorrectParams, {
308 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC,
309 'scheduleUpdate[updateAt]': 'toto'
311 const attaches = baseCorrectAttaches
313 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
316 it('Should fail with a bad originally published at attribute', async function () {
317 const fields = immutableAssign(baseCorrectParams, { 'originallyPublishedAt': 'toto' })
318 const attaches = baseCorrectAttaches
320 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
323 it('Should fail without an input file', async function () {
324 const fields = baseCorrectParams
326 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
329 it('Should fail without an incorrect input file', async function () {
330 const fields = baseCorrectParams
332 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm')
334 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
337 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mkv')
339 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
342 it('Should fail with an incorrect thumbnail file', async function () {
343 const fields = baseCorrectParams
345 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'),
346 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
349 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
352 it('Should fail with a big thumbnail file', async function () {
353 const fields = baseCorrectParams
355 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
356 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
359 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
362 it('Should fail with an incorrect preview file', async function () {
363 const fields = baseCorrectParams
365 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'),
366 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
369 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
372 it('Should fail with a big preview file', async function () {
373 const fields = baseCorrectParams
375 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
376 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
379 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
382 it('Should succeed with the correct parameters', async function () {
385 const fields = baseCorrectParams
388 const attaches = baseCorrectAttaches
389 await makeUploadRequest({
391 path: path + '/upload',
392 token: server.accessToken,
395 statusCodeExpected: 200
400 const attaches = immutableAssign(baseCorrectAttaches, {
401 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
404 await makeUploadRequest({
406 path: path + '/upload',
407 token: server.accessToken,
410 statusCodeExpected: 200
415 const attaches = immutableAssign(baseCorrectAttaches, {
416 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.ogv')
419 await makeUploadRequest({
421 path: path + '/upload',
422 token: server.accessToken,
425 statusCodeExpected: 200
431 describe('When updating a video', function () {
432 const baseCorrectParams = {
433 name: 'my super name',
438 commentsEnabled: false,
439 downloadEnabled: false,
440 description: 'my super description',
441 privacy: VideoPrivacy.PUBLIC,
442 tags: [ 'tag1', 'tag2' ]
445 before(async function () {
446 const res = await getVideosList(server.url)
447 videoId = res.body.data[0].uuid
450 it('Should fail with nothing', async function () {
452 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
455 it('Should fail without a valid uuid', async function () {
456 const fields = baseCorrectParams
457 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
460 it('Should fail with an unknown id', async function () {
461 const fields = baseCorrectParams
463 await makePutBodyRequest({
465 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
466 token: server.accessToken,
468 statusCodeExpected: 404
472 it('Should fail with a long name', async function () {
473 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
475 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
478 it('Should fail with a bad category', async function () {
479 const fields = immutableAssign(baseCorrectParams, { category: 125 })
481 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
484 it('Should fail with a bad licence', async function () {
485 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
487 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
490 it('Should fail with a bad language', async function () {
491 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
493 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
496 it('Should fail with a long description', async function () {
497 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
499 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
502 it('Should fail with a long support text', async function () {
503 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
505 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
508 it('Should fail with a bad channel', async function () {
509 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
511 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
514 it('Should fail with too many tags', async function () {
515 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
517 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
520 it('Should fail with a tag length too low', async function () {
521 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
523 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
526 it('Should fail with a tag length too big', async function () {
527 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
529 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
532 it('Should fail with a bad schedule update (miss updateAt)', async function () {
533 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
535 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
538 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
539 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
541 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
544 it('Should fail with a bad originally published at param', async function () {
545 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
547 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
550 it('Should fail with an incorrect thumbnail file', async function () {
551 const fields = baseCorrectParams
553 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
556 await makeUploadRequest({
559 path: path + videoId,
560 token: server.accessToken,
566 it('Should fail with a big thumbnail file', async function () {
567 const fields = baseCorrectParams
569 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
572 await makeUploadRequest({
575 path: path + videoId,
576 token: server.accessToken,
582 it('Should fail with an incorrect preview file', async function () {
583 const fields = baseCorrectParams
585 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
588 await makeUploadRequest({
591 path: path + videoId,
592 token: server.accessToken,
598 it('Should fail with a big preview file', async function () {
599 const fields = baseCorrectParams
601 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
604 await makeUploadRequest({
607 path: path + videoId,
608 token: server.accessToken,
614 it('Should fail with a video of another user without the appropriate right', async function () {
615 const fields = baseCorrectParams
617 await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 })
620 it('Should fail with a video of another server')
622 it('Should succeed with the correct parameters', async function () {
623 const fields = baseCorrectParams
625 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
629 describe('When getting a video', function () {
630 it('Should return the list of the videos with nothing', async function () {
631 const res = await makeGetRequest({
634 statusCodeExpected: 200
637 expect(res.body.data).to.be.an('array')
638 expect(res.body.data.length).to.equal(3)
641 it('Should fail without a correct uuid', async function () {
642 await getVideo(server.url, 'coucou', 400)
645 it('Should return 404 with an incorrect video', async function () {
646 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
649 it('Should succeed with the correct parameters', async function () {
650 await getVideo(server.url, videoId)
654 describe('When rating a video', function () {
657 before(async function () {
658 const res = await getVideosList(server.url)
659 videoId = res.body.data[0].id
662 it('Should fail without a valid uuid', async function () {
666 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
669 it('Should fail with an unknown id', async function () {
673 await makePutBodyRequest({
675 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
676 token: server.accessToken,
678 statusCodeExpected: 404
682 it('Should fail with a wrong rating', async function () {
686 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
689 it('Should succeed with the correct parameters', async function () {
693 await makePutBodyRequest({
695 path: path + videoId + '/rate',
696 token: server.accessToken,
698 statusCodeExpected: 204
703 describe('When removing a video', function () {
704 it('Should have 404 with nothing', async function () {
705 await makeDeleteRequest({
708 statusCodeExpected: 400
712 it('Should fail without a correct uuid', async function () {
713 await removeVideo(server.url, server.accessToken, 'hello', 400)
716 it('Should fail with a video which does not exist', async function () {
717 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
720 it('Should fail with a video of another user without the appropriate right', async function () {
721 await removeVideo(server.url, userAccessToken, videoId, 403)
724 it('Should fail with a video of another server')
726 it('Should succeed with the correct parameters', async function () {
727 await removeVideo(server.url, server.accessToken, videoId)
732 killallServers([ server ])