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, runServer, ServerInfo, setAccessTokensToServers, userLogin
11 } from '../../../../shared/utils'
13 checkBadCountPagination,
14 checkBadSortPagination,
15 checkBadStartPagination
16 } from '../../../../shared/utils/requests/check-api-params'
17 import { getAccountsList } from '../../../../shared/utils/users/accounts'
19 const expect = chai.expect
21 describe('Test videos API validator', function () {
22 const path = '/api/v1/videos/'
23 let server: ServerInfo
24 let userAccessToken = ''
25 let accountName: string
27 let channelName: string
30 // ---------------------------------------------------------------
32 before(async function () {
37 server = await runServer(1)
39 await setAccessTokensToServers([ server ])
41 const username = 'user1'
42 const password = 'my super password'
43 await createUser(server.url, server.accessToken, username, password)
44 userAccessToken = await userLogin(server, { username, password })
47 const res = await getMyUserInformation(server.url, server.accessToken)
48 channelId = res.body.videoChannels[ 0 ].id
49 channelName = res.body.videoChannels[ 0 ].name
50 accountName = res.body.account.name + '@' + res.body.account.host
54 describe('When listing a video', function () {
55 it('Should fail with a bad start pagination', async function () {
56 await checkBadStartPagination(server.url, path)
59 it('Should fail with a bad count pagination', async function () {
60 await checkBadCountPagination(server.url, path)
63 it('Should fail with an incorrect sort', async function () {
64 await checkBadSortPagination(server.url, path)
67 it('Should success with the correct parameters', async function () {
68 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
72 describe('When searching a video', function () {
74 it('Should fail with nothing', async function () {
75 await makeGetRequest({
77 path: join(path, 'search'),
78 statusCodeExpected: 400
82 it('Should fail with a bad start pagination', async function () {
83 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
86 it('Should fail with a bad count pagination', async function () {
87 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
90 it('Should fail with an incorrect sort', async function () {
91 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
94 it('Should success with the correct parameters', async function () {
95 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
99 describe('When listing my videos', function () {
100 const path = '/api/v1/users/me/videos'
102 it('Should fail with a bad start pagination', async function () {
103 await checkBadStartPagination(server.url, path, server.accessToken)
106 it('Should fail with a bad count pagination', async function () {
107 await checkBadCountPagination(server.url, path, server.accessToken)
110 it('Should fail with an incorrect sort', async function () {
111 await checkBadSortPagination(server.url, path, server.accessToken)
114 it('Should success with the correct parameters', async function () {
115 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 })
119 describe('When listing account videos', function () {
122 before(async function () {
123 path = '/api/v1/accounts/' + accountName + '/videos'
126 it('Should fail with a bad start pagination', async function () {
127 await checkBadStartPagination(server.url, path, server.accessToken)
130 it('Should fail with a bad count pagination', async function () {
131 await checkBadCountPagination(server.url, path, server.accessToken)
134 it('Should fail with an incorrect sort', async function () {
135 await checkBadSortPagination(server.url, path, server.accessToken)
138 it('Should success with the correct parameters', async function () {
139 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
143 describe('When listing video channel videos', function () {
146 before(async function () {
147 path = '/api/v1/video-channels/' + channelName + '/videos'
150 it('Should fail with a bad start pagination', async function () {
151 await checkBadStartPagination(server.url, path, server.accessToken)
154 it('Should fail with a bad count pagination', async function () {
155 await checkBadCountPagination(server.url, path, server.accessToken)
158 it('Should fail with an incorrect sort', async function () {
159 await checkBadSortPagination(server.url, path, server.accessToken)
162 it('Should success with the correct parameters', async function () {
163 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
167 describe('When adding a video', function () {
168 let baseCorrectParams
169 const baseCorrectAttaches = {
170 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.webm')
174 // Put in before to have channelId
175 baseCorrectParams = {
176 name: 'my super name',
181 commentsEnabled: true,
182 downloadEnabled: true,
183 waitTranscoding: true,
184 description: 'my super description',
185 support: 'my super support text',
186 tags: [ 'tag1', 'tag2' ],
187 privacy: VideoPrivacy.PUBLIC,
188 channelId: channelId,
189 originallyPublishedAt: new Date().toISOString()
193 it('Should fail with nothing', async function () {
196 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
199 it('Should fail without name', async function () {
200 const fields = omit(baseCorrectParams, 'name')
201 const attaches = baseCorrectAttaches
203 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
206 it('Should fail with a long name', async function () {
207 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
208 const attaches = baseCorrectAttaches
210 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
213 it('Should fail with a bad category', async function () {
214 const fields = immutableAssign(baseCorrectParams, { category: 125 })
215 const attaches = baseCorrectAttaches
217 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
220 it('Should fail with a bad licence', async function () {
221 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
222 const attaches = baseCorrectAttaches
224 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
227 it('Should fail with a bad language', async function () {
228 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
229 const attaches = baseCorrectAttaches
231 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
234 it('Should fail with a long description', async function () {
235 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
236 const attaches = baseCorrectAttaches
238 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
241 it('Should fail with a long support text', async function () {
242 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
243 const attaches = baseCorrectAttaches
245 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
248 it('Should fail without a channel', async function () {
249 const fields = omit(baseCorrectParams, 'channelId')
250 const attaches = baseCorrectAttaches
252 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
255 it('Should fail with a bad channel', async function () {
256 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
257 const attaches = baseCorrectAttaches
259 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
262 it('Should fail with another user channel', async function () {
265 password: 'fake_password'
267 await createUser(server.url, server.accessToken, user.username, user.password)
269 const accessTokenUser = await userLogin(server, user)
270 const res = await getMyUserInformation(server.url, accessTokenUser)
271 const customChannelId = res.body.videoChannels[0].id
273 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
274 const attaches = baseCorrectAttaches
276 await makeUploadRequest({ url: server.url, path: path + '/upload', token: userAccessToken, fields, attaches })
279 it('Should fail with too many tags', async function () {
280 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
281 const attaches = baseCorrectAttaches
283 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
286 it('Should fail with a tag length too low', async function () {
287 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
288 const attaches = baseCorrectAttaches
290 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
293 it('Should fail with a tag length too big', async function () {
294 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
295 const attaches = baseCorrectAttaches
297 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
300 it('Should fail with a bad schedule update (miss updateAt)', async function () {
301 const fields = immutableAssign(baseCorrectParams, { 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC })
302 const attaches = baseCorrectAttaches
304 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
307 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
308 const fields = immutableAssign(baseCorrectParams, {
309 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC,
310 'scheduleUpdate[updateAt]': 'toto'
312 const attaches = baseCorrectAttaches
314 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
317 it('Should fail with a bad originally published at attribute', async function () {
318 const fields = immutableAssign(baseCorrectParams, { 'originallyPublishedAt': 'toto' })
319 const attaches = baseCorrectAttaches
321 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
324 it('Should fail without an input file', async function () {
325 const fields = baseCorrectParams
327 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
330 it('Should fail without an incorrect input file', async function () {
331 const fields = baseCorrectParams
333 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm')
335 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
338 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mkv')
340 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
343 it('Should fail with an incorrect thumbnail file', async function () {
344 const fields = baseCorrectParams
346 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'),
347 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
350 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
353 it('Should fail with a big thumbnail file', async function () {
354 const fields = baseCorrectParams
356 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
357 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
360 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
363 it('Should fail with an incorrect preview file', async function () {
364 const fields = baseCorrectParams
366 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'),
367 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
370 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
373 it('Should fail with a big preview file', async function () {
374 const fields = baseCorrectParams
376 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
377 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
380 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
383 it('Should succeed with the correct parameters', async function () {
386 const fields = baseCorrectParams
389 const attaches = baseCorrectAttaches
390 await makeUploadRequest({
392 path: path + '/upload',
393 token: server.accessToken,
396 statusCodeExpected: 200
401 const attaches = immutableAssign(baseCorrectAttaches, {
402 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
405 await makeUploadRequest({
407 path: path + '/upload',
408 token: server.accessToken,
411 statusCodeExpected: 200
416 const attaches = immutableAssign(baseCorrectAttaches, {
417 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.ogv')
420 await makeUploadRequest({
422 path: path + '/upload',
423 token: server.accessToken,
426 statusCodeExpected: 200
432 describe('When updating a video', function () {
433 const baseCorrectParams = {
434 name: 'my super name',
439 commentsEnabled: false,
440 downloadEnabled: false,
441 description: 'my super description',
442 privacy: VideoPrivacy.PUBLIC,
443 tags: [ 'tag1', 'tag2' ]
446 before(async function () {
447 const res = await getVideosList(server.url)
448 videoId = res.body.data[0].uuid
451 it('Should fail with nothing', async function () {
453 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
456 it('Should fail without a valid uuid', async function () {
457 const fields = baseCorrectParams
458 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
461 it('Should fail with an unknown id', async function () {
462 const fields = baseCorrectParams
464 await makePutBodyRequest({
466 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
467 token: server.accessToken,
469 statusCodeExpected: 404
473 it('Should fail with a long name', async function () {
474 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
476 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
479 it('Should fail with a bad category', async function () {
480 const fields = immutableAssign(baseCorrectParams, { category: 125 })
482 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
485 it('Should fail with a bad licence', async function () {
486 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
488 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
491 it('Should fail with a bad language', async function () {
492 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
494 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
497 it('Should fail with a long description', async function () {
498 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
500 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
503 it('Should fail with a long support text', async function () {
504 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
506 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
509 it('Should fail with a bad channel', async function () {
510 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
512 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
515 it('Should fail with too many tags', async function () {
516 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
518 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
521 it('Should fail with a tag length too low', async function () {
522 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
524 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
527 it('Should fail with a tag length too big', async function () {
528 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
530 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
533 it('Should fail with a bad schedule update (miss updateAt)', async function () {
534 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
536 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
539 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
540 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
542 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
545 it('Should fail with a bad originally published at param', async function () {
546 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
548 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
551 it('Should fail with an incorrect thumbnail file', async function () {
552 const fields = baseCorrectParams
554 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
557 await makeUploadRequest({
560 path: path + videoId,
561 token: server.accessToken,
567 it('Should fail with a big thumbnail file', async function () {
568 const fields = baseCorrectParams
570 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
573 await makeUploadRequest({
576 path: path + videoId,
577 token: server.accessToken,
583 it('Should fail with an incorrect preview file', async function () {
584 const fields = baseCorrectParams
586 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
589 await makeUploadRequest({
592 path: path + videoId,
593 token: server.accessToken,
599 it('Should fail with a big preview file', async function () {
600 const fields = baseCorrectParams
602 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
605 await makeUploadRequest({
608 path: path + videoId,
609 token: server.accessToken,
615 it('Should fail with a video of another user without the appropriate right', async function () {
616 const fields = baseCorrectParams
618 await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 })
621 it('Should fail with a video of another server')
623 it('Should succeed with the correct parameters', async function () {
624 const fields = baseCorrectParams
626 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
630 describe('When getting a video', function () {
631 it('Should return the list of the videos with nothing', async function () {
632 const res = await makeGetRequest({
635 statusCodeExpected: 200
638 expect(res.body.data).to.be.an('array')
639 expect(res.body.data.length).to.equal(3)
642 it('Should fail without a correct uuid', async function () {
643 await getVideo(server.url, 'coucou', 400)
646 it('Should return 404 with an incorrect video', async function () {
647 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
650 it('Should succeed with the correct parameters', async function () {
651 await getVideo(server.url, videoId)
655 describe('When rating a video', function () {
658 before(async function () {
659 const res = await getVideosList(server.url)
660 videoId = res.body.data[0].id
663 it('Should fail without a valid uuid', async function () {
667 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
670 it('Should fail with an unknown id', async function () {
674 await makePutBodyRequest({
676 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
677 token: server.accessToken,
679 statusCodeExpected: 404
683 it('Should fail with a wrong rating', async function () {
687 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
690 it('Should succeed with the correct parameters', async function () {
694 await makePutBodyRequest({
696 path: path + videoId + '/rate',
697 token: server.accessToken,
699 statusCodeExpected: 204
704 describe('When removing a video', function () {
705 it('Should have 404 with nothing', async function () {
706 await makeDeleteRequest({
709 statusCodeExpected: 400
713 it('Should fail without a correct uuid', async function () {
714 await removeVideo(server.url, server.accessToken, 'hello', 400)
717 it('Should fail with a video which does not exist', async function () {
718 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
721 it('Should fail with a video of another user without the appropriate right', async function () {
722 await removeVideo(server.url, userAccessToken, videoId, 403)
725 it('Should fail with a video of another server')
727 it('Should succeed with the correct parameters', async function () {
728 await removeVideo(server.url, server.accessToken, videoId)
732 after(async function () {
733 killallServers([ server ])
735 // Keep the logs if the test failed