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
12 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
13 import { getAccountsList } from '../../utils/users/accounts'
15 const expect = chai.expect
17 describe('Test videos API validator', function () {
18 const path = '/api/v1/videos/'
19 let server: ServerInfo
20 let userAccessToken = ''
21 let accountName: string
23 let channelName: string
26 // ---------------------------------------------------------------
28 before(async function () {
33 server = await runServer(1)
35 await setAccessTokensToServers([ server ])
37 const username = 'user1'
38 const password = 'my super password'
39 await createUser(server.url, server.accessToken, username, password)
40 userAccessToken = await userLogin(server, { username, password })
43 const res = await getMyUserInformation(server.url, server.accessToken)
44 channelId = res.body.videoChannels[ 0 ].id
45 channelName = res.body.videoChannels[ 0 ].name
46 accountName = res.body.account.name + '@' + res.body.account.host
50 describe('When listing a video', function () {
51 it('Should fail with a bad start pagination', async function () {
52 await checkBadStartPagination(server.url, path)
55 it('Should fail with a bad count pagination', async function () {
56 await checkBadCountPagination(server.url, path)
59 it('Should fail with an incorrect sort', async function () {
60 await checkBadSortPagination(server.url, path)
63 it('Should success with the correct parameters', async function () {
64 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
68 describe('When searching a video', function () {
70 it('Should fail with nothing', async function () {
71 await makeGetRequest({
73 path: join(path, 'search'),
74 statusCodeExpected: 400
78 it('Should fail with a bad start pagination', async function () {
79 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
82 it('Should fail with a bad count pagination', async function () {
83 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
86 it('Should fail with an incorrect sort', async function () {
87 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
90 it('Should success with the correct parameters', async function () {
91 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
95 describe('When listing my videos', function () {
96 const path = '/api/v1/users/me/videos'
98 it('Should fail with a bad start pagination', async function () {
99 await checkBadStartPagination(server.url, path, server.accessToken)
102 it('Should fail with a bad count pagination', async function () {
103 await checkBadCountPagination(server.url, path, server.accessToken)
106 it('Should fail with an incorrect sort', async function () {
107 await checkBadSortPagination(server.url, path, server.accessToken)
110 it('Should success with the correct parameters', async function () {
111 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 })
115 describe('When listing account videos', function () {
118 before(async function () {
119 path = '/api/v1/accounts/' + accountName + '/videos'
122 it('Should fail with a bad start pagination', async function () {
123 await checkBadStartPagination(server.url, path, server.accessToken)
126 it('Should fail with a bad count pagination', async function () {
127 await checkBadCountPagination(server.url, path, server.accessToken)
130 it('Should fail with an incorrect sort', async function () {
131 await checkBadSortPagination(server.url, path, server.accessToken)
134 it('Should success with the correct parameters', async function () {
135 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
139 describe('When listing video channel videos', function () {
142 before(async function () {
143 path = '/api/v1/video-channels/' + channelName + '/videos'
146 it('Should fail with a bad start pagination', async function () {
147 await checkBadStartPagination(server.url, path, server.accessToken)
150 it('Should fail with a bad count pagination', async function () {
151 await checkBadCountPagination(server.url, path, server.accessToken)
154 it('Should fail with an incorrect sort', async function () {
155 await checkBadSortPagination(server.url, path, server.accessToken)
158 it('Should success with the correct parameters', async function () {
159 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
163 describe('When adding a video', function () {
164 let baseCorrectParams
165 const baseCorrectAttaches = {
166 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.webm')
170 // Put in before to have channelId
171 baseCorrectParams = {
172 name: 'my super name',
177 commentsEnabled: true,
178 downloadEnabled: true,
179 waitTranscoding: true,
180 description: 'my super description',
181 support: 'my super support text',
182 tags: [ 'tag1', 'tag2' ],
183 privacy: VideoPrivacy.PUBLIC,
188 it('Should fail with nothing', async function () {
191 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
194 it('Should fail without name', async function () {
195 const fields = omit(baseCorrectParams, 'name')
196 const attaches = baseCorrectAttaches
198 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
201 it('Should fail with a long name', async function () {
202 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
203 const attaches = baseCorrectAttaches
205 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
208 it('Should fail with a bad category', async function () {
209 const fields = immutableAssign(baseCorrectParams, { category: 125 })
210 const attaches = baseCorrectAttaches
212 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
215 it('Should fail with a bad licence', async function () {
216 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
217 const attaches = baseCorrectAttaches
219 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
222 it('Should fail with a bad language', async function () {
223 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
224 const attaches = baseCorrectAttaches
226 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
229 it('Should fail with a long description', async function () {
230 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
231 const attaches = baseCorrectAttaches
233 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
236 it('Should fail with a long support text', async function () {
237 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
238 const attaches = baseCorrectAttaches
240 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
243 it('Should fail without a channel', async function () {
244 const fields = omit(baseCorrectParams, 'channelId')
245 const attaches = baseCorrectAttaches
247 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
250 it('Should fail with a bad channel', async function () {
251 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
252 const attaches = baseCorrectAttaches
254 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
257 it('Should fail with another user channel', async function () {
260 password: 'fake_password'
262 await createUser(server.url, server.accessToken, user.username, user.password)
264 const accessTokenUser = await userLogin(server, user)
265 const res = await getMyUserInformation(server.url, accessTokenUser)
266 const customChannelId = res.body.videoChannels[0].id
268 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
269 const attaches = baseCorrectAttaches
271 await makeUploadRequest({ url: server.url, path: path + '/upload', token: userAccessToken, fields, attaches })
274 it('Should fail with too many tags', async function () {
275 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
276 const attaches = baseCorrectAttaches
278 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
281 it('Should fail with a tag length too low', async function () {
282 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
283 const attaches = baseCorrectAttaches
285 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
288 it('Should fail with a tag length too big', async function () {
289 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
290 const attaches = baseCorrectAttaches
292 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
295 it('Should fail with a bad schedule update (miss updateAt)', async function () {
296 const fields = immutableAssign(baseCorrectParams, { 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC })
297 const attaches = baseCorrectAttaches
299 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
302 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
303 const fields = immutableAssign(baseCorrectParams, {
304 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC,
305 'scheduleUpdate[updateAt]': 'toto'
307 const attaches = baseCorrectAttaches
309 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
312 it('Should fail without an input file', async function () {
313 const fields = baseCorrectParams
315 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
318 it('Should fail without an incorrect input file', async function () {
319 const fields = baseCorrectParams
321 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm')
323 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
326 it('Should fail with an incorrect thumbnail file', async function () {
327 const fields = baseCorrectParams
329 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'),
330 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
333 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
336 it('Should fail with a big thumbnail file', async function () {
337 const fields = baseCorrectParams
339 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
340 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
343 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
346 it('Should fail with an incorrect preview file', async function () {
347 const fields = baseCorrectParams
349 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'),
350 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
353 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
356 it('Should fail with a big preview file', async function () {
357 const fields = baseCorrectParams
359 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
360 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
363 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
366 it('Should succeed with the correct parameters', async function () {
369 const fields = baseCorrectParams
372 const attaches = baseCorrectAttaches
373 await makeUploadRequest({
375 path: path + '/upload',
376 token: server.accessToken,
379 statusCodeExpected: 200
384 const attaches = immutableAssign(baseCorrectAttaches, {
385 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
388 await makeUploadRequest({
390 path: path + '/upload',
391 token: server.accessToken,
394 statusCodeExpected: 200
399 const attaches = immutableAssign(baseCorrectAttaches, {
400 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.ogv')
403 await makeUploadRequest({
405 path: path + '/upload',
406 token: server.accessToken,
409 statusCodeExpected: 200
415 describe('When updating a video', function () {
416 const baseCorrectParams = {
417 name: 'my super name',
422 commentsEnabled: false,
423 downloadEnabled: false,
424 description: 'my super description',
425 privacy: VideoPrivacy.PUBLIC,
426 tags: [ 'tag1', 'tag2' ]
429 before(async function () {
430 const res = await getVideosList(server.url)
431 videoId = res.body.data[0].uuid
434 it('Should fail with nothing', async function () {
436 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
439 it('Should fail without a valid uuid', async function () {
440 const fields = baseCorrectParams
441 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
444 it('Should fail with an unknown id', async function () {
445 const fields = baseCorrectParams
447 await makePutBodyRequest({
449 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
450 token: server.accessToken,
452 statusCodeExpected: 404
456 it('Should fail with a long name', async function () {
457 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
459 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
462 it('Should fail with a bad category', async function () {
463 const fields = immutableAssign(baseCorrectParams, { category: 125 })
465 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
468 it('Should fail with a bad licence', async function () {
469 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
471 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
474 it('Should fail with a bad language', async function () {
475 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
477 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
480 it('Should fail with a long description', async function () {
481 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
483 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
486 it('Should fail with a long support text', async function () {
487 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
489 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
492 it('Should fail with a bad channel', async function () {
493 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
495 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
498 it('Should fail with too many tags', async function () {
499 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
501 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
504 it('Should fail with a tag length too low', async function () {
505 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
507 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
510 it('Should fail with a tag length too big', async function () {
511 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
513 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
516 it('Should fail with a bad schedule update (miss updateAt)', async function () {
517 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
519 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
522 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
523 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
525 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
528 it('Should fail with an incorrect thumbnail file', async function () {
529 const fields = baseCorrectParams
531 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
534 await makeUploadRequest({
537 path: path + videoId,
538 token: server.accessToken,
544 it('Should fail with a big thumbnail file', async function () {
545 const fields = baseCorrectParams
547 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
550 await makeUploadRequest({
553 path: path + videoId,
554 token: server.accessToken,
560 it('Should fail with an incorrect preview file', async function () {
561 const fields = baseCorrectParams
563 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
566 await makeUploadRequest({
569 path: path + videoId,
570 token: server.accessToken,
576 it('Should fail with a big preview file', async function () {
577 const fields = baseCorrectParams
579 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
582 await makeUploadRequest({
585 path: path + videoId,
586 token: server.accessToken,
592 it('Should fail with a video of another user without the appropriate right', async function () {
593 const fields = baseCorrectParams
595 await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 })
598 it('Should fail with a video of another server')
600 it('Should succeed with the correct parameters', async function () {
601 const fields = baseCorrectParams
603 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
607 describe('When getting a video', function () {
608 it('Should return the list of the videos with nothing', async function () {
609 const res = await makeGetRequest({
612 statusCodeExpected: 200
615 expect(res.body.data).to.be.an('array')
616 expect(res.body.data.length).to.equal(3)
619 it('Should fail without a correct uuid', async function () {
620 await getVideo(server.url, 'coucou', 400)
623 it('Should return 404 with an incorrect video', async function () {
624 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
627 it('Should succeed with the correct parameters', async function () {
628 await getVideo(server.url, videoId)
632 describe('When rating a video', function () {
635 before(async function () {
636 const res = await getVideosList(server.url)
637 videoId = res.body.data[0].id
640 it('Should fail without a valid uuid', async function () {
644 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
647 it('Should fail with an unknown id', async function () {
651 await makePutBodyRequest({
653 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
654 token: server.accessToken,
656 statusCodeExpected: 404
660 it('Should fail with a wrong rating', async function () {
664 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
667 it('Should succeed with the correct parameters', async function () {
671 await makePutBodyRequest({
673 path: path + videoId + '/rate',
674 token: server.accessToken,
676 statusCodeExpected: 204
681 describe('When removing a video', function () {
682 it('Should have 404 with nothing', async function () {
683 await makeDeleteRequest({
686 statusCodeExpected: 400
690 it('Should fail without a correct uuid', async function () {
691 await removeVideo(server.url, server.accessToken, 'hello', 400)
694 it('Should fail with a video which does not exist', async function () {
695 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
698 it('Should fail with a video of another user without the appropriate right', async function () {
699 await removeVideo(server.url, userAccessToken, videoId, 403)
702 it('Should fail with a video of another server')
704 it('Should succeed with the correct parameters', async function () {
705 await removeVideo(server.url, server.accessToken, videoId)
709 after(async function () {
710 killallServers([ server ])
712 // Keep the logs if the test failed