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
19 let userAccessToken = ''
23 // ---------------------------------------------------------------
25 before(async function () {
30 server = await runServer(1)
32 await setAccessTokensToServers([ server ])
34 const username = 'user1'
35 const password = 'my super password'
36 await createUser(server.url, server.accessToken, username, password)
37 userAccessToken = await userLogin(server, { username, password })
39 const res = await getMyUserInformation(server.url, server.accessToken)
40 channelId = res.body.videoChannels[0].id
43 describe('When listing a video', function () {
44 it('Should fail with a bad start pagination', async function () {
45 await checkBadStartPagination(server.url, path)
48 it('Should fail with a bad count pagination', async function () {
49 await checkBadCountPagination(server.url, path)
52 it('Should fail with an incorrect sort', async function () {
53 await checkBadSortPagination(server.url, path)
57 describe('When searching a video', function () {
59 it('Should fail with nothing', async function () {
60 await makeGetRequest({
62 path: join(path, 'search'),
63 statusCodeExpected: 400
67 it('Should fail with a bad start pagination', async function () {
68 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
71 it('Should fail with a bad count pagination', async function () {
72 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
75 it('Should fail with an incorrect sort', async function () {
76 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
80 describe('When listing my videos', function () {
81 const path = '/api/v1/users/me/videos'
83 it('Should fail with a bad start pagination', async function () {
84 await checkBadStartPagination(server.url, path, server.accessToken)
87 it('Should fail with a bad count pagination', async function () {
88 await checkBadCountPagination(server.url, path, server.accessToken)
91 it('Should fail with an incorrect sort', async function () {
92 await checkBadSortPagination(server.url, path, server.accessToken)
96 describe('When adding a video', function () {
98 const baseCorrectAttaches = {
99 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
103 // Put in before to have channelId
104 baseCorrectParams = {
105 name: 'my super name',
110 commentsEnabled: true,
111 description: 'my super description',
112 support: 'my super support text',
113 tags: [ 'tag1', 'tag2' ],
114 privacy: VideoPrivacy.PUBLIC,
119 it('Should fail with nothing', async function () {
122 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
125 it('Should fail without name', async function () {
126 const fields = omit(baseCorrectParams, 'name')
127 const attaches = baseCorrectAttaches
129 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
132 it('Should fail with a long name', async function () {
133 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
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 category', async function () {
140 const fields = immutableAssign(baseCorrectParams, { category: 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 licence', async function () {
147 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
148 const attaches = baseCorrectAttaches
150 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
153 it('Should fail with a bad language', async function () {
154 const fields = immutableAssign(baseCorrectParams, { language: 125 })
155 const attaches = baseCorrectAttaches
157 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
160 it('Should fail without nsfw attribute', async function () {
161 const fields = omit(baseCorrectParams, 'nsfw')
162 const attaches = baseCorrectAttaches
164 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
167 it('Should fail with a bad nsfw attribute', async function () {
168 const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
169 const attaches = baseCorrectAttaches
171 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
174 it('Should fail without commentsEnabled attribute', async function () {
175 const fields = omit(baseCorrectParams, 'commentsEnabled')
176 const attaches = baseCorrectAttaches
178 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
181 it('Should fail with a bad commentsEnabled attribute', async function () {
182 const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 })
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 description', async function () {
189 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
190 const attaches = baseCorrectAttaches
192 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
195 it('Should fail with a long support text', async function () {
196 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) })
197 const attaches = baseCorrectAttaches
199 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
202 it('Should fail without a channel', async function () {
203 const fields = omit(baseCorrectParams, 'channelId')
204 const attaches = baseCorrectAttaches
206 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
209 it('Should fail with a bad channel', async function () {
210 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
211 const attaches = baseCorrectAttaches
213 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
216 it('Should fail with another user channel', async function () {
219 password: 'fake_password'
221 await createUser(server.url, server.accessToken, user.username, user.password)
223 const accessTokenUser = await userLogin(server, user)
224 const res = await getMyUserInformation(server.url, accessTokenUser)
225 const customChannelId = res.body.videoChannels[0].id
227 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
228 const attaches = baseCorrectAttaches
230 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
233 it('Should fail with too many tags', async function () {
234 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
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 low', async function () {
241 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
242 const attaches = baseCorrectAttaches
244 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
247 it('Should fail with a tag length too big', async function () {
248 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
249 const attaches = baseCorrectAttaches
251 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
254 it('Should fail without an input file', async function () {
255 const fields = baseCorrectParams
257 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
260 it('Should fail without an incorrect input file', async function () {
261 const fields = baseCorrectParams
263 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
265 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
268 it('Should fail with an incorrect thumbnail file', async function () {
269 const fields = baseCorrectParams
271 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar.png'),
272 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
275 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
278 it('Should fail with a big thumbnail file', async function () {
279 const fields = baseCorrectParams
281 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar-big.png'),
282 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
285 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
288 it('Should fail with an incorrect preview file', async function () {
289 const fields = baseCorrectParams
291 'previewfile': join(__dirname, '..', 'fixtures', 'avatar.png'),
292 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
295 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
298 it('Should fail with a big preview file', async function () {
299 const fields = baseCorrectParams
301 'previewfile': join(__dirname, '..', 'fixtures', 'avatar-big.png'),
302 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
305 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
308 it('Should succeed with the correct parameters', async function () {
311 const fields = baseCorrectParams
314 const attaches = baseCorrectAttaches
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.mp4')
330 await makeUploadRequest({
332 path: path + '/upload',
333 token: server.accessToken,
336 statusCodeExpected: 200
341 const attaches = immutableAssign(baseCorrectAttaches, {
342 videofile: join(__dirname, '..', 'fixtures', 'video_short.ogv')
345 await makeUploadRequest({
347 path: path + '/upload',
348 token: server.accessToken,
351 statusCodeExpected: 200
357 describe('When updating a video', function () {
358 const baseCorrectParams = {
359 name: 'my super name',
364 commentsEnabled: false,
365 description: 'my super description',
366 privacy: VideoPrivacy.PUBLIC,
367 tags: [ 'tag1', 'tag2' ]
370 before(async function () {
371 const res = await getVideosList(server.url)
372 videoId = res.body.data[0].uuid
375 it('Should fail with nothing', async function () {
377 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
380 it('Should fail without a valid uuid', async function () {
381 const fields = baseCorrectParams
382 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
385 it('Should fail with an unknown id', async function () {
386 const fields = baseCorrectParams
388 await makePutBodyRequest({
390 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
391 token: server.accessToken,
393 statusCodeExpected: 404
397 it('Should fail with a long name', async function () {
398 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
400 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
403 it('Should fail with a bad category', async function () {
404 const fields = immutableAssign(baseCorrectParams, { category: 125 })
406 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
409 it('Should fail with a bad licence', async function () {
410 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
412 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
415 it('Should fail with a bad language', async function () {
416 const fields = immutableAssign(baseCorrectParams, { language: 125 })
418 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
421 it('Should fail with a bad nsfw attribute', async function () {
422 const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
424 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
427 it('Should fail with a bad commentsEnabled attribute', async function () {
428 const fields = immutableAssign(baseCorrectParams, { commentsEnabled: 2 })
430 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
433 it('Should fail with a long description', async function () {
434 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
436 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
439 it('Should fail with a long support text', async function () {
440 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(70) })
442 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
445 it('Should fail with too many tags', async function () {
446 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
448 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
451 it('Should fail with a tag length too low', async function () {
452 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
454 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
457 it('Should fail with a tag length too big', async function () {
458 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
460 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
463 it('Should fail with an incorrect thumbnail file', async function () {
464 const fields = baseCorrectParams
466 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar.png')
469 await makeUploadRequest({
472 path: path + videoId,
473 token: server.accessToken,
479 it('Should fail with a big thumbnail file', async function () {
480 const fields = baseCorrectParams
482 'thumbnailfile': join(__dirname, '..', 'fixtures', 'avatar-big.png')
485 await makeUploadRequest({
488 path: path + videoId,
489 token: server.accessToken,
495 it('Should fail with an incorrect preview file', async function () {
496 const fields = baseCorrectParams
498 'previewfile': join(__dirname, '..', 'fixtures', 'avatar.png')
501 await makeUploadRequest({
504 path: path + videoId,
505 token: server.accessToken,
511 it('Should fail with a big preview file', async function () {
512 const fields = baseCorrectParams
514 'previewfile': join(__dirname, '..', 'fixtures', 'avatar-big.png')
517 await makeUploadRequest({
520 path: path + videoId,
521 token: server.accessToken,
527 it('Should fail with a video of another user without the appropriate right', async function () {
528 const fields = baseCorrectParams
530 await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 })
533 it('Should fail with a video of another server')
535 it('Should succeed with the correct parameters', async function () {
536 const fields = baseCorrectParams
538 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
542 describe('When getting a video', function () {
543 it('Should return the list of the videos with nothing', async function () {
544 const res = await makeGetRequest({
547 statusCodeExpected: 200
550 expect(res.body.data).to.be.an('array')
551 expect(res.body.data.length).to.equal(3)
554 it('Should fail without a correct uuid', async function () {
555 await getVideo(server.url, 'coucou', 400)
558 it('Should return 404 with an incorrect video', async function () {
559 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
562 it('Should succeed with the correct parameters', async function () {
563 await getVideo(server.url, videoId)
567 describe('When rating a video', function () {
570 before(async function () {
571 const res = await getVideosList(server.url)
572 videoId = res.body.data[0].id
575 it('Should fail without a valid uuid', async function () {
579 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
582 it('Should fail with an unknown id', async function () {
586 await makePutBodyRequest({
588 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
589 token: server.accessToken,
591 statusCodeExpected: 404
595 it('Should fail with a wrong rating', async function () {
599 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
602 it('Should succeed with the correct parameters', async function () {
606 await makePutBodyRequest({
608 path: path + videoId + '/rate',
609 token: server.accessToken,
611 statusCodeExpected: 204
616 describe('When removing a video', function () {
617 it('Should have 404 with nothing', async function () {
618 await makeDeleteRequest({
621 statusCodeExpected: 400
625 it('Should fail without a correct uuid', async function () {
626 await removeVideo(server.url, server.accessToken, 'hello', 400)
629 it('Should fail with a video which does not exist', async function () {
630 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
633 it('Should fail with a video of another user without the appropriate right', async function () {
634 await removeVideo(server.url, userAccessToken, videoId, 403)
637 it('Should fail with a video of another server')
639 it('Should succeed with the correct parameters', async function () {
640 await removeVideo(server.url, server.accessToken, videoId)
644 after(async function () {
645 killallServers([ server ])
647 // Keep the logs if the test failed