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
11 } from '../../../../shared/utils'
13 checkBadCountPagination,
14 checkBadSortPagination,
15 checkBadStartPagination
16 } from '../../../../shared/utils/requests/check-api-params'
17 import { getAccountsList } from '../../../../shared/utils/users/accounts'
19 const expect = chai.expect
21 describe('Test videos API validator', function () {
22 const path = '/api/v1/videos/'
23 let server: ServerInfo
24 let userAccessToken = ''
25 let accountName: string
27 let channelName: string
30 // ---------------------------------------------------------------
32 before(async function () {
37 server = await runServer(1)
39 await setAccessTokensToServers([ server ])
41 const username = 'user1'
42 const password = 'my super password'
43 await createUser(server.url, server.accessToken, username, password)
44 userAccessToken = await userLogin(server, { username, password })
47 const res = await getMyUserInformation(server.url, server.accessToken)
48 channelId = res.body.videoChannels[ 0 ].id
49 channelName = res.body.videoChannels[ 0 ].name
50 accountName = res.body.account.name + '@' + res.body.account.host
54 describe('When listing a video', function () {
55 it('Should fail with a bad start pagination', async function () {
56 await checkBadStartPagination(server.url, path)
59 it('Should fail with a bad count pagination', async function () {
60 await checkBadCountPagination(server.url, path)
63 it('Should fail with an incorrect sort', async function () {
64 await checkBadSortPagination(server.url, path)
67 it('Should success with the correct parameters', async function () {
68 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
72 describe('When searching a video', function () {
74 it('Should fail with nothing', async function () {
75 await makeGetRequest({
77 path: join(path, 'search'),
78 statusCodeExpected: 400
82 it('Should fail with a bad start pagination', async function () {
83 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
86 it('Should fail with a bad count pagination', async function () {
87 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
90 it('Should fail with an incorrect sort', async function () {
91 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
94 it('Should success with the correct parameters', async function () {
95 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
99 describe('When listing my videos', function () {
100 const path = '/api/v1/users/me/videos'
102 it('Should fail with a bad start pagination', async function () {
103 await checkBadStartPagination(server.url, path, server.accessToken)
106 it('Should fail with a bad count pagination', async function () {
107 await checkBadCountPagination(server.url, path, server.accessToken)
110 it('Should fail with an incorrect sort', async function () {
111 await checkBadSortPagination(server.url, path, server.accessToken)
114 it('Should success with the correct parameters', async function () {
115 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 })
119 describe('When listing account videos', function () {
122 before(async function () {
123 path = '/api/v1/accounts/' + accountName + '/videos'
126 it('Should fail with a bad start pagination', async function () {
127 await checkBadStartPagination(server.url, path, server.accessToken)
130 it('Should fail with a bad count pagination', async function () {
131 await checkBadCountPagination(server.url, path, server.accessToken)
134 it('Should fail with an incorrect sort', async function () {
135 await checkBadSortPagination(server.url, path, server.accessToken)
138 it('Should success with the correct parameters', async function () {
139 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
143 describe('When listing video channel videos', function () {
146 before(async function () {
147 path = '/api/v1/video-channels/' + channelName + '/videos'
150 it('Should fail with a bad start pagination', async function () {
151 await checkBadStartPagination(server.url, path, server.accessToken)
154 it('Should fail with a bad count pagination', async function () {
155 await checkBadCountPagination(server.url, path, server.accessToken)
158 it('Should fail with an incorrect sort', async function () {
159 await checkBadSortPagination(server.url, path, server.accessToken)
162 it('Should success with the correct parameters', async function () {
163 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
167 describe('When adding a video', function () {
168 let baseCorrectParams
169 const baseCorrectAttaches = {
170 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.webm')
174 // Put in before to have channelId
175 baseCorrectParams = {
176 name: 'my super name',
181 commentsEnabled: true,
182 waitTranscoding: true,
183 description: 'my super description',
184 support: 'my super support text',
185 tags: [ 'tag1', 'tag2' ],
186 privacy: VideoPrivacy.PUBLIC,
191 it('Should fail with nothing', async function () {
194 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
197 it('Should fail without name', async function () {
198 const fields = omit(baseCorrectParams, 'name')
199 const attaches = baseCorrectAttaches
201 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
204 it('Should fail with a long name', async function () {
205 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
206 const attaches = baseCorrectAttaches
208 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
211 it('Should fail with a bad category', async function () {
212 const fields = immutableAssign(baseCorrectParams, { category: 125 })
213 const attaches = baseCorrectAttaches
215 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
218 it('Should fail with a bad licence', async function () {
219 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
220 const attaches = baseCorrectAttaches
222 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
225 it('Should fail with a bad language', async function () {
226 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
227 const attaches = baseCorrectAttaches
229 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
232 it('Should fail with a long description', async function () {
233 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
234 const attaches = baseCorrectAttaches
236 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
239 it('Should fail with a long support text', async function () {
240 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
241 const attaches = baseCorrectAttaches
243 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
246 it('Should fail without a channel', async function () {
247 const fields = omit(baseCorrectParams, 'channelId')
248 const attaches = baseCorrectAttaches
250 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
253 it('Should fail with a bad channel', async function () {
254 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
255 const attaches = baseCorrectAttaches
257 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
260 it('Should fail with another user channel', async function () {
263 password: 'fake_password'
265 await createUser(server.url, server.accessToken, user.username, user.password)
267 const accessTokenUser = await userLogin(server, user)
268 const res = await getMyUserInformation(server.url, accessTokenUser)
269 const customChannelId = res.body.videoChannels[0].id
271 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
272 const attaches = baseCorrectAttaches
274 await makeUploadRequest({ url: server.url, path: path + '/upload', token: userAccessToken, fields, attaches })
277 it('Should fail with too many tags', async function () {
278 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
279 const attaches = baseCorrectAttaches
281 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
284 it('Should fail with a tag length too low', async function () {
285 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
286 const attaches = baseCorrectAttaches
288 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
291 it('Should fail with a tag length too big', async function () {
292 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
293 const attaches = baseCorrectAttaches
295 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
298 it('Should fail with a bad schedule update (miss updateAt)', async function () {
299 const fields = immutableAssign(baseCorrectParams, { 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC })
300 const attaches = baseCorrectAttaches
302 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
305 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
306 const fields = immutableAssign(baseCorrectParams, {
307 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC,
308 'scheduleUpdate[updateAt]': 'toto'
310 const attaches = baseCorrectAttaches
312 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
315 it('Should fail without an input file', async function () {
316 const fields = baseCorrectParams
318 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
321 it('Should fail without an incorrect input file', async function () {
322 const fields = baseCorrectParams
324 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm')
326 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
329 it('Should fail with an incorrect thumbnail file', async function () {
330 const fields = baseCorrectParams
332 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'),
333 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
336 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
339 it('Should fail with a big thumbnail file', async function () {
340 const fields = baseCorrectParams
342 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
343 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
346 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
349 it('Should fail with an incorrect preview file', async function () {
350 const fields = baseCorrectParams
352 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'),
353 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
356 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
359 it('Should fail with a big preview file', async function () {
360 const fields = baseCorrectParams
362 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
363 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
366 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
369 it('Should succeed with the correct parameters', async function () {
372 const fields = baseCorrectParams
375 const attaches = baseCorrectAttaches
376 await makeUploadRequest({
378 path: path + '/upload',
379 token: server.accessToken,
382 statusCodeExpected: 200
387 const attaches = immutableAssign(baseCorrectAttaches, {
388 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
391 await makeUploadRequest({
393 path: path + '/upload',
394 token: server.accessToken,
397 statusCodeExpected: 200
402 const attaches = immutableAssign(baseCorrectAttaches, {
403 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.ogv')
406 await makeUploadRequest({
408 path: path + '/upload',
409 token: server.accessToken,
412 statusCodeExpected: 200
418 describe('When updating a video', function () {
419 const baseCorrectParams = {
420 name: 'my super name',
425 commentsEnabled: false,
426 description: 'my super description',
427 privacy: VideoPrivacy.PUBLIC,
428 tags: [ 'tag1', 'tag2' ]
431 before(async function () {
432 const res = await getVideosList(server.url)
433 videoId = res.body.data[0].uuid
436 it('Should fail with nothing', async function () {
438 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
441 it('Should fail without a valid uuid', async function () {
442 const fields = baseCorrectParams
443 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
446 it('Should fail with an unknown id', async function () {
447 const fields = baseCorrectParams
449 await makePutBodyRequest({
451 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
452 token: server.accessToken,
454 statusCodeExpected: 404
458 it('Should fail with a long name', async function () {
459 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
461 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
464 it('Should fail with a bad category', async function () {
465 const fields = immutableAssign(baseCorrectParams, { category: 125 })
467 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
470 it('Should fail with a bad licence', async function () {
471 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
473 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
476 it('Should fail with a bad language', async function () {
477 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
479 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
482 it('Should fail with a long description', async function () {
483 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
485 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
488 it('Should fail with a long support text', async function () {
489 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
491 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
494 it('Should fail with a bad channel', async function () {
495 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
497 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
500 it('Should fail with too many tags', async function () {
501 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
503 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
506 it('Should fail with a tag length too low', async function () {
507 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
509 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
512 it('Should fail with a tag length too big', async function () {
513 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
515 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
518 it('Should fail with a bad schedule update (miss updateAt)', async function () {
519 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
521 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
524 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
525 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
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