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'
14 const expect = chai.expect
16 describe('Test videos API validator', function () {
17 const path = '/api/v1/videos/'
18 let server: ServerInfo
21 // ---------------------------------------------------------------
23 before(async function () {
28 server = await runServer(1)
30 await setAccessTokensToServers([ server ])
32 const res = await getMyUserInformation(server.url, server.accessToken)
33 channelId = res.body.videoChannels[0].id
36 describe('When listing a video', function () {
37 it('Should fail with a bad start pagination', async function () {
38 await checkBadStartPagination(server.url, path)
41 it('Should fail with a bad count pagination', async function () {
42 await checkBadCountPagination(server.url, path)
45 it('Should fail with an incorrect sort', async function () {
46 await checkBadSortPagination(server.url, path)
50 describe('When searching a video', function () {
52 it('Should fail with nothing', async function () {
53 await makeGetRequest({
55 path: join(path, 'search'),
56 statusCodeExpected: 400
60 it('Should fail with a bad start pagination', async function () {
61 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
64 it('Should fail with a bad count pagination', async function () {
65 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
68 it('Should fail with an incorrect sort', async function () {
69 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
73 describe('When listing my videos', function () {
74 const path = '/api/v1/users/me/videos'
76 it('Should fail with a bad start pagination', async function () {
77 await checkBadStartPagination(server.url, path, server.accessToken)
80 it('Should fail with a bad count pagination', async function () {
81 await checkBadCountPagination(server.url, path, server.accessToken)
84 it('Should fail with an incorrect sort', async function () {
85 await checkBadSortPagination(server.url, path, server.accessToken)
89 describe('When adding a video', function () {
91 const baseCorrectAttaches = {
92 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
96 // Put in before to have channelId
98 name: 'my super name',
103 commentsEnabled: true,
104 description: 'my super description',
105 tags: [ 'tag1', 'tag2' ],
106 privacy: VideoPrivacy.PUBLIC,
111 it('Should fail with nothing', async function () {
114 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
117 it('Should fail without name', async function () {
118 const fields = omit(baseCorrectParams, 'name')
119 const attaches = baseCorrectAttaches
121 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
124 it('Should fail with a long name', async function () {
125 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
126 const attaches = baseCorrectAttaches
128 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
131 it('Should fail with a bad category', async function () {
132 const fields = immutableAssign(baseCorrectParams, { category: 125 })
133 const attaches = baseCorrectAttaches
135 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
138 it('Should fail with a bad licence', async function () {
139 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
140 const attaches = baseCorrectAttaches
142 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
145 it('Should fail with a bad language', async function () {
146 const fields = immutableAssign(baseCorrectParams, { language: 125 })
147 const attaches = baseCorrectAttaches
149 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
152 it('Should fail without nsfw attribute', async function () {
153 const fields = omit(baseCorrectParams, 'nsfw')
154 const attaches = baseCorrectAttaches
156 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
159 it('Should fail with a bad nsfw attribute', async function () {
160 const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
161 const attaches = baseCorrectAttaches
163 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
166 it('Should fail without commentsEnabled attribute', async function () {
167 const fields = omit(baseCorrectParams, 'commentsEnabled')
168 const attaches = baseCorrectAttaches
170 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
173 it('Should fail with a bad commentsEnabled attribute', async function () {
174 const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 })
175 const attaches = baseCorrectAttaches
177 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
180 it('Should fail with a long description', async function () {
181 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) })
182 const attaches = baseCorrectAttaches
184 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
187 it('Should fail without a channel', async function () {
188 const fields = omit(baseCorrectParams, 'channelId')
189 const attaches = baseCorrectAttaches
191 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
194 it('Should fail with a bad channel', async function () {
195 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
196 const attaches = baseCorrectAttaches
198 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
201 it('Should fail with another user channel', async function () {
204 password: 'fake_password'
206 await createUser(server.url, server.accessToken, user.username, user.password)
208 const accessTokenUser = await userLogin(server, user)
209 const res = await getMyUserInformation(server.url, accessTokenUser)
210 const customChannelId = res.body.videoChannels[0].id
212 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
213 const attaches = baseCorrectAttaches
215 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
218 it('Should fail with too many tags', async function () {
219 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
220 const attaches = baseCorrectAttaches
222 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
225 it('Should fail with a tag length too low', async function () {
226 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
227 const attaches = baseCorrectAttaches
229 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
232 it('Should fail with a tag length too big', async function () {
233 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
234 const attaches = baseCorrectAttaches
236 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
239 it('Should fail without an input file', async function () {
240 const fields = baseCorrectParams
242 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
245 it('Should fail without an incorrect input file', async function () {
246 const fields = baseCorrectParams
248 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
250 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
253 it('Should fail with an incorrect thumbnail file', async function () {
254 const fields = baseCorrectParams
256 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar.png'),
257 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
260 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
263 it('Should fail with a big thumbnail file', async function () {
264 const fields = baseCorrectParams
266 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar-big.png'),
267 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
270 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
273 it('Should fail with an incorrect preview file', async function () {
274 const fields = baseCorrectParams
276 'previewfile': join(__dirname, '..', 'fixtures', 'avatar.png'),
277 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
280 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
283 it('Should fail with a big preview file', async function () {
284 const fields = baseCorrectParams
286 'previewfile': join(__dirname, '..', 'fixtures', 'avatar-big.png'),
287 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
290 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
293 it('Should succeed with the correct parameters', async function () {
296 const fields = baseCorrectParams
299 const attaches = baseCorrectAttaches
300 await makeUploadRequest({
302 path: path + '/upload',
303 token: server.accessToken,
306 statusCodeExpected: 200
311 const attaches = immutableAssign(baseCorrectAttaches, {
312 videofile: join(__dirname, '..', 'fixtures', 'video_short.mp4')
315 await makeUploadRequest({
317 path: path + '/upload',
318 token: server.accessToken,
321 statusCodeExpected: 200
326 const attaches = immutableAssign(baseCorrectAttaches, {
327 videofile: join(__dirname, '..', 'fixtures', 'video_short.ogv')
330 await makeUploadRequest({
332 path: path + '/upload',
333 token: server.accessToken,
336 statusCodeExpected: 200
342 describe('When updating a video', function () {
343 const baseCorrectParams = {
344 name: 'my super name',
349 commentsEnabled: false,
350 description: 'my super description',
351 privacy: VideoPrivacy.PUBLIC,
352 tags: [ 'tag1', 'tag2' ]
356 before(async function () {
357 const res = await getVideosList(server.url)
358 videoId = res.body.data[0].id
361 it('Should fail with nothing', async function () {
363 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
366 it('Should fail without a valid uuid', async function () {
367 const fields = baseCorrectParams
368 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
371 it('Should fail with an unknown id', async function () {
372 const fields = baseCorrectParams
374 await makePutBodyRequest({
376 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
377 token: server.accessToken,
379 statusCodeExpected: 404
383 it('Should fail with a long name', async function () {
384 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
386 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
389 it('Should fail with a bad category', async function () {
390 const fields = immutableAssign(baseCorrectParams, { category: 125 })
392 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
395 it('Should fail with a bad licence', async function () {
396 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
398 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
401 it('Should fail with a bad language', async function () {
402 const fields = immutableAssign(baseCorrectParams, { language: 125 })
404 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
407 it('Should fail with a bad nsfw attribute', async function () {
408 const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
410 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
413 it('Should fail with a bad commentsEnabled attribute', async function () {
414 const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 })
416 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
419 it('Should fail with a long description', async function () {
420 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) })
422 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
425 it('Should fail with too many tags', async function () {
426 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
428 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
431 it('Should fail with a tag length too low', async function () {
432 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
434 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
437 it('Should fail with a tag length too big', async function () {
438 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
440 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
443 it('Should fail with an incorrect thumbnail file', async function () {
444 const fields = baseCorrectParams
446 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar.png')
449 await makeUploadRequest({
452 path: path + videoId,
453 token: server.accessToken,
459 it('Should fail with a big thumbnail file', async function () {
460 const fields = baseCorrectParams
462 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar-big.png')
465 await makeUploadRequest({
468 path: path + videoId,
469 token: server.accessToken,
475 it('Should fail with an incorrect preview file', async function () {
476 const fields = baseCorrectParams
478 'previewfile': join(__dirname, '..', 'fixtures', 'avatar.png')
481 await makeUploadRequest({
484 path: path + videoId,
485 token: server.accessToken,
491 it('Should fail with a big preview file', async function () {
492 const fields = baseCorrectParams
494 'previewfile': join(__dirname, '..', 'fixtures', 'avatar-big.png')
497 await makeUploadRequest({
500 path: path + videoId,
501 token: server.accessToken,
507 it('Should fail with a video of another user')
509 it('Should fail with a video of another server')
511 it('Should succeed with the correct parameters', async function () {
512 const fields = baseCorrectParams
514 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
518 describe('When getting a video', function () {
519 it('Should return the list of the videos with nothing', async function () {
520 const res = await makeGetRequest({
523 statusCodeExpected: 200
526 expect(res.body.data).to.be.an('array')
527 expect(res.body.data.length).to.equal(3)
530 it('Should fail without a correct uuid', async function () {
531 await getVideo(server.url, 'coucou', 400)
534 it('Should return 404 with an incorrect video', async function () {
535 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
538 it('Should succeed with the correct parameters')
541 describe('When rating a video', function () {
544 before(async function () {
545 const res = await getVideosList(server.url)
546 videoId = res.body.data[0].id
549 it('Should fail without a valid uuid', async function () {
553 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
556 it('Should fail with an unknown id', async function () {
560 await makePutBodyRequest({
562 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
563 token: server.accessToken,
565 statusCodeExpected: 404
569 it('Should fail with a wrong rating', async function () {
573 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
576 it('Should succeed with the correct parameters', async function () {
580 await makePutBodyRequest({
582 path: path + videoId + '/rate',
583 token: server.accessToken,
585 statusCodeExpected: 204
590 describe('When removing a video', function () {
591 it('Should have 404 with nothing', async function () {
592 await makeDeleteRequest({
595 statusCodeExpected: 400
599 it('Should fail without a correct uuid', async function () {
600 await removeVideo(server.url, server.accessToken, 'hello', 400)
603 it('Should fail with a video which does not exist', async function () {
604 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
607 it('Should fail with a video of another user')
609 it('Should fail with a video of another server')
611 it('Should succeed with the correct parameters')
614 after(async function () {
615 killallServers([ server ])
617 // Keep the logs if the test failed