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 waitTranscoding: true,
179 description: 'my super description',
180 support: 'my super support text',
181 tags: [ 'tag1', 'tag2' ],
182 privacy: VideoPrivacy.PUBLIC,
187 it('Should fail with nothing', async function () {
190 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
193 it('Should fail without name', async function () {
194 const fields = omit(baseCorrectParams, 'name')
195 const attaches = baseCorrectAttaches
197 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
200 it('Should fail with a long name', async function () {
201 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
202 const attaches = baseCorrectAttaches
204 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
207 it('Should fail with a bad category', async function () {
208 const fields = immutableAssign(baseCorrectParams, { category: 125 })
209 const attaches = baseCorrectAttaches
211 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
214 it('Should fail with a bad licence', async function () {
215 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
216 const attaches = baseCorrectAttaches
218 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
221 it('Should fail with a bad language', async function () {
222 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
223 const attaches = baseCorrectAttaches
225 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
228 it('Should fail with a long description', async function () {
229 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
230 const attaches = baseCorrectAttaches
232 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
235 it('Should fail with a long support text', async function () {
236 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
237 const attaches = baseCorrectAttaches
239 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
242 it('Should fail without a channel', async function () {
243 const fields = omit(baseCorrectParams, 'channelId')
244 const attaches = baseCorrectAttaches
246 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
249 it('Should fail with a bad channel', async function () {
250 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
251 const attaches = baseCorrectAttaches
253 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
256 it('Should fail with another user channel', async function () {
259 password: 'fake_password'
261 await createUser(server.url, server.accessToken, user.username, user.password)
263 const accessTokenUser = await userLogin(server, user)
264 const res = await getMyUserInformation(server.url, accessTokenUser)
265 const customChannelId = res.body.videoChannels[0].id
267 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
268 const attaches = baseCorrectAttaches
270 await makeUploadRequest({ url: server.url, path: path + '/upload', token: userAccessToken, fields, attaches })
273 it('Should fail with too many tags', async function () {
274 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
275 const attaches = baseCorrectAttaches
277 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
280 it('Should fail with a tag length too low', async function () {
281 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
282 const attaches = baseCorrectAttaches
284 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
287 it('Should fail with a tag length too big', async function () {
288 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
289 const attaches = baseCorrectAttaches
291 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
294 it('Should fail with a bad schedule update (miss updateAt)', async function () {
295 const fields = immutableAssign(baseCorrectParams, { 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC })
296 const attaches = baseCorrectAttaches
298 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
301 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
302 const fields = immutableAssign(baseCorrectParams, {
303 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC,
304 'scheduleUpdate[updateAt]': 'toto'
306 const attaches = baseCorrectAttaches
308 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
311 it('Should fail without an input file', async function () {
312 const fields = baseCorrectParams
314 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
317 it('Should fail without an incorrect input file', async function () {
318 const fields = baseCorrectParams
320 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm')
322 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
325 it('Should fail with an incorrect thumbnail file', async function () {
326 const fields = baseCorrectParams
328 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'),
329 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
332 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
335 it('Should fail with a big thumbnail file', async function () {
336 const fields = baseCorrectParams
338 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
339 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
342 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
345 it('Should fail with an incorrect preview file', async function () {
346 const fields = baseCorrectParams
348 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'),
349 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
352 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
355 it('Should fail with a big preview file', async function () {
356 const fields = baseCorrectParams
358 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
359 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
362 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
365 it('Should succeed with the correct parameters', async function () {
368 const fields = baseCorrectParams
371 const attaches = baseCorrectAttaches
372 await makeUploadRequest({
374 path: path + '/upload',
375 token: server.accessToken,
378 statusCodeExpected: 200
383 const attaches = immutableAssign(baseCorrectAttaches, {
384 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
387 await makeUploadRequest({
389 path: path + '/upload',
390 token: server.accessToken,
393 statusCodeExpected: 200
398 const attaches = immutableAssign(baseCorrectAttaches, {
399 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.ogv')
402 await makeUploadRequest({
404 path: path + '/upload',
405 token: server.accessToken,
408 statusCodeExpected: 200
414 describe('When updating a video', function () {
415 const baseCorrectParams = {
416 name: 'my super name',
421 commentsEnabled: false,
422 description: 'my super description',
423 privacy: VideoPrivacy.PUBLIC,
424 tags: [ 'tag1', 'tag2' ]
427 before(async function () {
428 const res = await getVideosList(server.url)
429 videoId = res.body.data[0].uuid
432 it('Should fail with nothing', async function () {
434 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
437 it('Should fail without a valid uuid', async function () {
438 const fields = baseCorrectParams
439 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
442 it('Should fail with an unknown id', async function () {
443 const fields = baseCorrectParams
445 await makePutBodyRequest({
447 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
448 token: server.accessToken,
450 statusCodeExpected: 404
454 it('Should fail with a long name', async function () {
455 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
457 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
460 it('Should fail with a bad category', async function () {
461 const fields = immutableAssign(baseCorrectParams, { category: 125 })
463 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
466 it('Should fail with a bad licence', async function () {
467 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
469 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
472 it('Should fail with a bad language', async function () {
473 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
475 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
478 it('Should fail with a long description', async function () {
479 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
481 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
484 it('Should fail with a long support text', async function () {
485 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
487 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
490 it('Should fail with a bad channel', async function () {
491 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
493 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
496 it('Should fail with too many tags', async function () {
497 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
499 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
502 it('Should fail with a tag length too low', async function () {
503 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
505 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
508 it('Should fail with a tag length too big', async function () {
509 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
511 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
514 it('Should fail with a bad schedule update (miss updateAt)', async function () {
515 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
517 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
520 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
521 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
523 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
526 it('Should fail with an incorrect thumbnail file', async function () {
527 const fields = baseCorrectParams
529 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
532 await makeUploadRequest({
535 path: path + videoId,
536 token: server.accessToken,
542 it('Should fail with a big thumbnail file', async function () {
543 const fields = baseCorrectParams
545 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
548 await makeUploadRequest({
551 path: path + videoId,
552 token: server.accessToken,
558 it('Should fail with an incorrect preview file', async function () {
559 const fields = baseCorrectParams
561 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
564 await makeUploadRequest({
567 path: path + videoId,
568 token: server.accessToken,
574 it('Should fail with a big preview file', async function () {
575 const fields = baseCorrectParams
577 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
580 await makeUploadRequest({
583 path: path + videoId,
584 token: server.accessToken,
590 it('Should fail with a video of another user without the appropriate right', async function () {
591 const fields = baseCorrectParams
593 await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 })
596 it('Should fail with a video of another server')
598 it('Should succeed with the correct parameters', async function () {
599 const fields = baseCorrectParams
601 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
605 describe('When getting a video', function () {
606 it('Should return the list of the videos with nothing', async function () {
607 const res = await makeGetRequest({
610 statusCodeExpected: 200
613 expect(res.body.data).to.be.an('array')
614 expect(res.body.data.length).to.equal(3)
617 it('Should fail without a correct uuid', async function () {
618 await getVideo(server.url, 'coucou', 400)
621 it('Should return 404 with an incorrect video', async function () {
622 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
625 it('Should succeed with the correct parameters', async function () {
626 await getVideo(server.url, videoId)
630 describe('When rating a video', function () {
633 before(async function () {
634 const res = await getVideosList(server.url)
635 videoId = res.body.data[0].id
638 it('Should fail without a valid uuid', async function () {
642 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
645 it('Should fail with an unknown id', async function () {
649 await makePutBodyRequest({
651 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
652 token: server.accessToken,
654 statusCodeExpected: 404
658 it('Should fail with a wrong rating', async function () {
662 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
665 it('Should succeed with the correct parameters', async function () {
669 await makePutBodyRequest({
671 path: path + videoId + '/rate',
672 token: server.accessToken,
674 statusCodeExpected: 204
679 describe('When removing a video', function () {
680 it('Should have 404 with nothing', async function () {
681 await makeDeleteRequest({
684 statusCodeExpected: 400
688 it('Should fail without a correct uuid', async function () {
689 await removeVideo(server.url, server.accessToken, 'hello', 400)
692 it('Should fail with a video which does not exist', async function () {
693 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
696 it('Should fail with a video of another user without the appropriate right', async function () {
697 await removeVideo(server.url, userAccessToken, videoId, 403)
700 it('Should fail with a video of another server')
702 it('Should succeed with the correct parameters', async function () {
703 await removeVideo(server.url, server.accessToken, videoId)
707 after(async function () {
708 killallServers([ server ])
710 // Keep the logs if the test failed