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 support: 'my super support text',
106 tags: [ 'tag1', 'tag2' ],
107 privacy: VideoPrivacy.PUBLIC,
112 it('Should fail with nothing', async function () {
115 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
118 it('Should fail without name', async function () {
119 const fields = omit(baseCorrectParams, 'name')
120 const attaches = baseCorrectAttaches
122 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
125 it('Should fail with a long name', async function () {
126 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
127 const attaches = baseCorrectAttaches
129 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
132 it('Should fail with a bad category', async function () {
133 const fields = immutableAssign(baseCorrectParams, { category: 125 })
134 const attaches = baseCorrectAttaches
136 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
139 it('Should fail with a bad licence', async function () {
140 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
141 const attaches = baseCorrectAttaches
143 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
146 it('Should fail with a bad language', async function () {
147 const fields = immutableAssign(baseCorrectParams, { language: 125 })
148 const attaches = baseCorrectAttaches
150 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
153 it('Should fail without nsfw attribute', async function () {
154 const fields = omit(baseCorrectParams, 'nsfw')
155 const attaches = baseCorrectAttaches
157 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
160 it('Should fail with a bad nsfw attribute', async function () {
161 const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
162 const attaches = baseCorrectAttaches
164 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
167 it('Should fail without commentsEnabled attribute', async function () {
168 const fields = omit(baseCorrectParams, 'commentsEnabled')
169 const attaches = baseCorrectAttaches
171 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
174 it('Should fail with a bad commentsEnabled attribute', async function () {
175 const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 })
176 const attaches = baseCorrectAttaches
178 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
181 it('Should fail with a long description', async function () {
182 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
183 const attaches = baseCorrectAttaches
185 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
188 it('Should fail with a long support text', async function () {
189 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) })
190 const attaches = baseCorrectAttaches
192 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
195 it('Should fail without a channel', async function () {
196 const fields = omit(baseCorrectParams, 'channelId')
197 const attaches = baseCorrectAttaches
199 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
202 it('Should fail with a bad channel', async function () {
203 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
204 const attaches = baseCorrectAttaches
206 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
209 it('Should fail with another user channel', async function () {
212 password: 'fake_password'
214 await createUser(server.url, server.accessToken, user.username, user.password)
216 const accessTokenUser = await userLogin(server, user)
217 const res = await getMyUserInformation(server.url, accessTokenUser)
218 const customChannelId = res.body.videoChannels[0].id
220 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
221 const attaches = baseCorrectAttaches
223 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
226 it('Should fail with too many tags', async function () {
227 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
228 const attaches = baseCorrectAttaches
230 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
233 it('Should fail with a tag length too low', async function () {
234 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
235 const attaches = baseCorrectAttaches
237 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
240 it('Should fail with a tag length too big', async function () {
241 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
242 const attaches = baseCorrectAttaches
244 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
247 it('Should fail without an input file', async function () {
248 const fields = baseCorrectParams
250 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
253 it('Should fail without an incorrect input file', async function () {
254 const fields = baseCorrectParams
256 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
258 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
261 it('Should fail with an incorrect thumbnail file', async function () {
262 const fields = baseCorrectParams
264 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar.png'),
265 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
268 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
271 it('Should fail with a big thumbnail file', async function () {
272 const fields = baseCorrectParams
274 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar-big.png'),
275 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
278 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
281 it('Should fail with an incorrect preview file', async function () {
282 const fields = baseCorrectParams
284 'previewfile': join(__dirname, '..', 'fixtures', 'avatar.png'),
285 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
288 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
291 it('Should fail with a big preview file', async function () {
292 const fields = baseCorrectParams
294 'previewfile': join(__dirname, '..', 'fixtures', 'avatar-big.png'),
295 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
298 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
301 it('Should succeed with the correct parameters', async function () {
304 const fields = baseCorrectParams
307 const attaches = baseCorrectAttaches
308 await makeUploadRequest({
310 path: path + '/upload',
311 token: server.accessToken,
314 statusCodeExpected: 200
319 const attaches = immutableAssign(baseCorrectAttaches, {
320 videofile: join(__dirname, '..', 'fixtures', 'video_short.mp4')
323 await makeUploadRequest({
325 path: path + '/upload',
326 token: server.accessToken,
329 statusCodeExpected: 200
334 const attaches = immutableAssign(baseCorrectAttaches, {
335 videofile: join(__dirname, '..', 'fixtures', 'video_short.ogv')
338 await makeUploadRequest({
340 path: path + '/upload',
341 token: server.accessToken,
344 statusCodeExpected: 200
350 describe('When updating a video', function () {
351 const baseCorrectParams = {
352 name: 'my super name',
357 commentsEnabled: false,
358 description: 'my super description',
359 privacy: VideoPrivacy.PUBLIC,
360 tags: [ 'tag1', 'tag2' ]
364 before(async function () {
365 const res = await getVideosList(server.url)
366 videoId = res.body.data[0].id
369 it('Should fail with nothing', async function () {
371 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
374 it('Should fail without a valid uuid', async function () {
375 const fields = baseCorrectParams
376 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
379 it('Should fail with an unknown id', async function () {
380 const fields = baseCorrectParams
382 await makePutBodyRequest({
384 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
385 token: server.accessToken,
387 statusCodeExpected: 404
391 it('Should fail with a long name', async function () {
392 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
394 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
397 it('Should fail with a bad category', async function () {
398 const fields = immutableAssign(baseCorrectParams, { category: 125 })
400 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
403 it('Should fail with a bad licence', async function () {
404 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
406 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
409 it('Should fail with a bad language', async function () {
410 const fields = immutableAssign(baseCorrectParams, { language: 125 })
412 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
415 it('Should fail with a bad nsfw attribute', async function () {
416 const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
418 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
421 it('Should fail with a bad commentsEnabled attribute', async function () {
422 const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 })
424 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
427 it('Should fail with a long description', async function () {
428 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
430 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
433 it('Should fail with a long support text', async function () {
434 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) })
436 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
439 it('Should fail with too many tags', async function () {
440 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
442 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
445 it('Should fail with a tag length too low', async function () {
446 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
448 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
451 it('Should fail with a tag length too big', async function () {
452 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
454 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
457 it('Should fail with an incorrect thumbnail file', async function () {
458 const fields = baseCorrectParams
460 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar.png')
463 await makeUploadRequest({
466 path: path + videoId,
467 token: server.accessToken,
473 it('Should fail with a big thumbnail file', async function () {
474 const fields = baseCorrectParams
476 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar-big.png')
479 await makeUploadRequest({
482 path: path + videoId,
483 token: server.accessToken,
489 it('Should fail with an incorrect preview file', async function () {
490 const fields = baseCorrectParams
492 'previewfile': join(__dirname, '..', 'fixtures', 'avatar.png')
495 await makeUploadRequest({
498 path: path + videoId,
499 token: server.accessToken,
505 it('Should fail with a big preview file', async function () {
506 const fields = baseCorrectParams
508 'previewfile': join(__dirname, '..', 'fixtures', 'avatar-big.png')
511 await makeUploadRequest({
514 path: path + videoId,
515 token: server.accessToken,
521 it('Should fail with a video of another user')
523 it('Should fail with a video of another server')
525 it('Should succeed with the correct parameters', async function () {
526 const fields = baseCorrectParams
528 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
532 describe('When getting a video', function () {
533 it('Should return the list of the videos with nothing', async function () {
534 const res = await makeGetRequest({
537 statusCodeExpected: 200
540 expect(res.body.data).to.be.an('array')
541 expect(res.body.data.length).to.equal(3)
544 it('Should fail without a correct uuid', async function () {
545 await getVideo(server.url, 'coucou', 400)
548 it('Should return 404 with an incorrect video', async function () {
549 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
552 it('Should succeed with the correct parameters')
555 describe('When rating a video', function () {
558 before(async function () {
559 const res = await getVideosList(server.url)
560 videoId = res.body.data[0].id
563 it('Should fail without a valid uuid', async function () {
567 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
570 it('Should fail with an unknown id', async function () {
574 await makePutBodyRequest({
576 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
577 token: server.accessToken,
579 statusCodeExpected: 404
583 it('Should fail with a wrong rating', async function () {
587 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
590 it('Should succeed with the correct parameters', async function () {
594 await makePutBodyRequest({
596 path: path + videoId + '/rate',
597 token: server.accessToken,
599 statusCodeExpected: 204
604 describe('When removing a video', function () {
605 it('Should have 404 with nothing', async function () {
606 await makeDeleteRequest({
609 statusCodeExpected: 400
613 it('Should fail without a correct uuid', async function () {
614 await removeVideo(server.url, server.accessToken, 'hello', 400)
617 it('Should fail with a video which does not exist', async function () {
618 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
621 it('Should fail with a video of another user')
623 it('Should fail with a video of another server')
625 it('Should succeed with the correct parameters')
628 after(async function () {
629 killallServers([ server ])
631 // Keep the logs if the test failed