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 accountUUID: string
23 let channelUUID: 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 channelUUID = res.body.videoChannels[ 0 ].uuid
46 accountUUID = res.body.account.uuid
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/' + accountUUID + '/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/' + channelUUID + '/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 description: 'my super description',
179 support: 'my super support text',
180 tags: [ 'tag1', 'tag2' ],
181 privacy: VideoPrivacy.PUBLIC,
186 it('Should fail with nothing', async function () {
189 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
192 it('Should fail without name', async function () {
193 const fields = omit(baseCorrectParams, 'name')
194 const attaches = baseCorrectAttaches
196 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
199 it('Should fail with a long name', async function () {
200 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
201 const attaches = baseCorrectAttaches
203 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
206 it('Should fail with a bad category', async function () {
207 const fields = immutableAssign(baseCorrectParams, { category: 125 })
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 licence', async function () {
214 const fields = immutableAssign(baseCorrectParams, { licence: 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 language', async function () {
221 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
222 const attaches = baseCorrectAttaches
224 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
227 it('Should fail without nsfw attribute', async function () {
228 const fields = omit(baseCorrectParams, 'nsfw')
229 const attaches = baseCorrectAttaches
231 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
234 it('Should fail with a bad nsfw attribute', async function () {
235 const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
236 const attaches = baseCorrectAttaches
238 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
241 it('Should fail without commentsEnabled attribute', async function () {
242 const fields = omit(baseCorrectParams, 'commentsEnabled')
243 const attaches = baseCorrectAttaches
245 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
248 it('Should fail with a bad commentsEnabled attribute', async function () {
249 const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 })
250 const attaches = baseCorrectAttaches
252 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
255 it('Should fail with a long description', async function () {
256 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
257 const attaches = baseCorrectAttaches
259 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
262 it('Should fail with a long support text', async function () {
263 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) })
264 const attaches = baseCorrectAttaches
266 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
269 it('Should fail without a channel', async function () {
270 const fields = omit(baseCorrectParams, 'channelId')
271 const attaches = baseCorrectAttaches
273 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
276 it('Should fail with a bad channel', async function () {
277 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
278 const attaches = baseCorrectAttaches
280 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
283 it('Should fail with another user channel', async function () {
286 password: 'fake_password'
288 await createUser(server.url, server.accessToken, user.username, user.password)
290 const accessTokenUser = await userLogin(server, user)
291 const res = await getMyUserInformation(server.url, accessTokenUser)
292 const customChannelId = res.body.videoChannels[0].id
294 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
295 const attaches = baseCorrectAttaches
297 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
300 it('Should fail with too many tags', async function () {
301 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
302 const attaches = baseCorrectAttaches
304 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
307 it('Should fail with a tag length too low', async function () {
308 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
309 const attaches = baseCorrectAttaches
311 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
314 it('Should fail with a tag length too big', async function () {
315 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
316 const attaches = baseCorrectAttaches
318 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
321 it('Should fail without an input file', async function () {
322 const fields = baseCorrectParams
324 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
327 it('Should fail without an incorrect input file', async function () {
328 const fields = baseCorrectParams
330 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
332 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
335 it('Should fail with an incorrect thumbnail file', async function () {
336 const fields = baseCorrectParams
338 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar.png'),
339 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
342 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
345 it('Should fail with a big thumbnail file', async function () {
346 const fields = baseCorrectParams
348 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar-big.png'),
349 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
352 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
355 it('Should fail with an incorrect preview file', async function () {
356 const fields = baseCorrectParams
358 'previewfile': join(__dirname, '..', 'fixtures', 'avatar.png'),
359 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
362 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
365 it('Should fail with a big preview file', async function () {
366 const fields = baseCorrectParams
368 'previewfile': join(__dirname, '..', 'fixtures', 'avatar-big.png'),
369 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
372 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
375 it('Should succeed with the correct parameters', async function () {
378 const fields = baseCorrectParams
381 const attaches = baseCorrectAttaches
382 await makeUploadRequest({
384 path: path + '/upload',
385 token: server.accessToken,
388 statusCodeExpected: 200
393 const attaches = immutableAssign(baseCorrectAttaches, {
394 videofile: join(__dirname, '..', 'fixtures', 'video_short.mp4')
397 await makeUploadRequest({
399 path: path + '/upload',
400 token: server.accessToken,
403 statusCodeExpected: 200
408 const attaches = immutableAssign(baseCorrectAttaches, {
409 videofile: join(__dirname, '..', 'fixtures', 'video_short.ogv')
412 await makeUploadRequest({
414 path: path + '/upload',
415 token: server.accessToken,
418 statusCodeExpected: 200
424 describe('When updating a video', function () {
425 const baseCorrectParams = {
426 name: 'my super name',
431 commentsEnabled: false,
432 description: 'my super description',
433 privacy: VideoPrivacy.PUBLIC,
434 tags: [ 'tag1', 'tag2' ]
437 before(async function () {
438 const res = await getVideosList(server.url)
439 videoId = res.body.data[0].uuid
442 it('Should fail with nothing', async function () {
444 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
447 it('Should fail without a valid uuid', async function () {
448 const fields = baseCorrectParams
449 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
452 it('Should fail with an unknown id', async function () {
453 const fields = baseCorrectParams
455 await makePutBodyRequest({
457 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
458 token: server.accessToken,
460 statusCodeExpected: 404
464 it('Should fail with a long name', async function () {
465 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
467 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
470 it('Should fail with a bad category', async function () {
471 const fields = immutableAssign(baseCorrectParams, { category: 125 })
473 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
476 it('Should fail with a bad licence', async function () {
477 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
479 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
482 it('Should fail with a bad language', async function () {
483 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
485 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
488 it('Should fail with a bad nsfw attribute', async function () {
489 const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
491 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
494 it('Should fail with a bad commentsEnabled attribute', async function () {
495 const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 })
497 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
500 it('Should fail with a long description', async function () {
501 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
503 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
506 it('Should fail with a long support text', async function () {
507 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) })
509 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
512 it('Should fail with too many tags', async function () {
513 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
515 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
518 it('Should fail with a tag length too low', async function () {
519 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
521 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
524 it('Should fail with a tag length too big', async function () {
525 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
527 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
530 it('Should fail with an incorrect thumbnail file', async function () {
531 const fields = baseCorrectParams
533 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar.png')
536 await makeUploadRequest({
539 path: path + videoId,
540 token: server.accessToken,
546 it('Should fail with a big thumbnail file', async function () {
547 const fields = baseCorrectParams
549 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar-big.png')
552 await makeUploadRequest({
555 path: path + videoId,
556 token: server.accessToken,
562 it('Should fail with an incorrect preview file', async function () {
563 const fields = baseCorrectParams
565 'previewfile': join(__dirname, '..', 'fixtures', 'avatar.png')
568 await makeUploadRequest({
571 path: path + videoId,
572 token: server.accessToken,
578 it('Should fail with a big preview file', async function () {
579 const fields = baseCorrectParams
581 'previewfile': join(__dirname, '..', 'fixtures', 'avatar-big.png')
584 await makeUploadRequest({
587 path: path + videoId,
588 token: server.accessToken,
594 it('Should fail with a video of another user without the appropriate right', async function () {
595 const fields = baseCorrectParams
597 await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 })
600 it('Should fail with a video of another server')
602 it('Should succeed with the correct parameters', async function () {
603 const fields = baseCorrectParams
605 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
609 describe('When getting a video', function () {
610 it('Should return the list of the videos with nothing', async function () {
611 const res = await makeGetRequest({
614 statusCodeExpected: 200
617 expect(res.body.data).to.be.an('array')
618 expect(res.body.data.length).to.equal(3)
621 it('Should fail without a correct uuid', async function () {
622 await getVideo(server.url, 'coucou', 400)
625 it('Should return 404 with an incorrect video', async function () {
626 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
629 it('Should succeed with the correct parameters', async function () {
630 await getVideo(server.url, videoId)
634 describe('When rating a video', function () {
637 before(async function () {
638 const res = await getVideosList(server.url)
639 videoId = res.body.data[0].id
642 it('Should fail without a valid uuid', async function () {
646 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
649 it('Should fail with an unknown id', async function () {
653 await makePutBodyRequest({
655 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
656 token: server.accessToken,
658 statusCodeExpected: 404
662 it('Should fail with a wrong rating', async function () {
666 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
669 it('Should succeed with the correct parameters', async function () {
673 await makePutBodyRequest({
675 path: path + videoId + '/rate',
676 token: server.accessToken,
678 statusCodeExpected: 204
683 describe('When removing a video', function () {
684 it('Should have 404 with nothing', async function () {
685 await makeDeleteRequest({
688 statusCodeExpected: 400
692 it('Should fail without a correct uuid', async function () {
693 await removeVideo(server.url, server.accessToken, 'hello', 400)
696 it('Should fail with a video which does not exist', async function () {
697 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
700 it('Should fail with a video of another user without the appropriate right', async function () {
701 await removeVideo(server.url, userAccessToken, videoId, 403)
704 it('Should fail with a video of another server')
706 it('Should succeed with the correct parameters', async function () {
707 await removeVideo(server.url, server.accessToken, videoId)
711 after(async function () {
712 killallServers([ server ])
714 // Keep the logs if the test failed