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 downloadEnabled: true,
183 waitTranscoding: true,
184 description: 'my super description',
185 support: 'my super support text',
186 tags: [ 'tag1', 'tag2' ],
187 privacy: VideoPrivacy.PUBLIC,
192 it('Should fail with nothing', async function () {
195 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
198 it('Should fail without name', async function () {
199 const fields = omit(baseCorrectParams, 'name')
200 const attaches = baseCorrectAttaches
202 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
205 it('Should fail with a long name', async function () {
206 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
207 const attaches = baseCorrectAttaches
209 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
212 it('Should fail with a bad category', async function () {
213 const fields = immutableAssign(baseCorrectParams, { category: 125 })
214 const attaches = baseCorrectAttaches
216 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
219 it('Should fail with a bad licence', async function () {
220 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
221 const attaches = baseCorrectAttaches
223 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
226 it('Should fail with a bad language', async function () {
227 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
228 const attaches = baseCorrectAttaches
230 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
233 it('Should fail with a long description', async function () {
234 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
235 const attaches = baseCorrectAttaches
237 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
240 it('Should fail with a long support text', async function () {
241 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
242 const attaches = baseCorrectAttaches
244 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
247 it('Should fail without a channel', async function () {
248 const fields = omit(baseCorrectParams, 'channelId')
249 const attaches = baseCorrectAttaches
251 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
254 it('Should fail with a bad channel', async function () {
255 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
256 const attaches = baseCorrectAttaches
258 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
261 it('Should fail with another user channel', async function () {
264 password: 'fake_password'
266 await createUser(server.url, server.accessToken, user.username, user.password)
268 const accessTokenUser = await userLogin(server, user)
269 const res = await getMyUserInformation(server.url, accessTokenUser)
270 const customChannelId = res.body.videoChannels[0].id
272 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
273 const attaches = baseCorrectAttaches
275 await makeUploadRequest({ url: server.url, path: path + '/upload', token: userAccessToken, fields, attaches })
278 it('Should fail with too many tags', async function () {
279 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
280 const attaches = baseCorrectAttaches
282 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
285 it('Should fail with a tag length too low', async function () {
286 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
287 const attaches = baseCorrectAttaches
289 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
292 it('Should fail with a tag length too big', async function () {
293 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
294 const attaches = baseCorrectAttaches
296 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
299 it('Should fail with a bad schedule update (miss updateAt)', async function () {
300 const fields = immutableAssign(baseCorrectParams, { 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC })
301 const attaches = baseCorrectAttaches
303 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
306 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
307 const fields = immutableAssign(baseCorrectParams, {
308 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC,
309 'scheduleUpdate[updateAt]': 'toto'
311 const attaches = baseCorrectAttaches
313 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
316 it('Should fail without an input file', async function () {
317 const fields = baseCorrectParams
319 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
322 it('Should fail without an incorrect input file', async function () {
323 const fields = baseCorrectParams
325 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm')
327 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
330 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mkv')
332 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
335 it('Should fail with an incorrect thumbnail file', async function () {
336 const fields = baseCorrectParams
338 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.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 a big thumbnail file', async function () {
346 const fields = baseCorrectParams
348 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.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 an incorrect preview file', async function () {
356 const fields = baseCorrectParams
358 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.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 fail with a big preview file', async function () {
366 const fields = baseCorrectParams
368 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
369 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
372 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
375 it('Should succeed with the correct parameters', async function () {
378 const fields = baseCorrectParams
381 const attaches = baseCorrectAttaches
382 await makeUploadRequest({
384 path: path + '/upload',
385 token: server.accessToken,
388 statusCodeExpected: 200
393 const attaches = immutableAssign(baseCorrectAttaches, {
394 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
397 await makeUploadRequest({
399 path: path + '/upload',
400 token: server.accessToken,
403 statusCodeExpected: 200
408 const attaches = immutableAssign(baseCorrectAttaches, {
409 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.ogv')
412 await makeUploadRequest({
414 path: path + '/upload',
415 token: server.accessToken,
418 statusCodeExpected: 200
424 describe('When updating a video', function () {
425 const baseCorrectParams = {
426 name: 'my super name',
431 commentsEnabled: false,
432 downloadEnabled: false,
433 description: 'my super description',
434 privacy: VideoPrivacy.PUBLIC,
435 tags: [ 'tag1', 'tag2' ]
438 before(async function () {
439 const res = await getVideosList(server.url)
440 videoId = res.body.data[0].uuid
443 it('Should fail with nothing', async function () {
445 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
448 it('Should fail without a valid uuid', async function () {
449 const fields = baseCorrectParams
450 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
453 it('Should fail with an unknown id', async function () {
454 const fields = baseCorrectParams
456 await makePutBodyRequest({
458 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
459 token: server.accessToken,
461 statusCodeExpected: 404
465 it('Should fail with a long name', async function () {
466 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
468 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
471 it('Should fail with a bad category', async function () {
472 const fields = immutableAssign(baseCorrectParams, { category: 125 })
474 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
477 it('Should fail with a bad licence', async function () {
478 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
480 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
483 it('Should fail with a bad language', async function () {
484 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
486 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
489 it('Should fail with a long description', async function () {
490 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
492 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
495 it('Should fail with a long support text', async function () {
496 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
498 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
501 it('Should fail with a bad channel', async function () {
502 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
504 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
507 it('Should fail with too many tags', async function () {
508 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
510 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
513 it('Should fail with a tag length too low', async function () {
514 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
516 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
519 it('Should fail with a tag length too big', async function () {
520 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
522 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
525 it('Should fail with a bad schedule update (miss updateAt)', async function () {
526 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
528 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
531 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
532 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
534 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
537 it('Should fail with an incorrect thumbnail file', async function () {
538 const fields = baseCorrectParams
540 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
543 await makeUploadRequest({
546 path: path + videoId,
547 token: server.accessToken,
553 it('Should fail with a big thumbnail file', async function () {
554 const fields = baseCorrectParams
556 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
559 await makeUploadRequest({
562 path: path + videoId,
563 token: server.accessToken,
569 it('Should fail with an incorrect preview file', async function () {
570 const fields = baseCorrectParams
572 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
575 await makeUploadRequest({
578 path: path + videoId,
579 token: server.accessToken,
585 it('Should fail with a big preview file', async function () {
586 const fields = baseCorrectParams
588 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
591 await makeUploadRequest({
594 path: path + videoId,
595 token: server.accessToken,
601 it('Should fail with a video of another user without the appropriate right', async function () {
602 const fields = baseCorrectParams
604 await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 })
607 it('Should fail with a video of another server')
609 it('Should succeed with the correct parameters', async function () {
610 const fields = baseCorrectParams
612 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
616 describe('When getting a video', function () {
617 it('Should return the list of the videos with nothing', async function () {
618 const res = await makeGetRequest({
621 statusCodeExpected: 200
624 expect(res.body.data).to.be.an('array')
625 expect(res.body.data.length).to.equal(3)
628 it('Should fail without a correct uuid', async function () {
629 await getVideo(server.url, 'coucou', 400)
632 it('Should return 404 with an incorrect video', async function () {
633 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
636 it('Should succeed with the correct parameters', async function () {
637 await getVideo(server.url, videoId)
641 describe('When rating a video', function () {
644 before(async function () {
645 const res = await getVideosList(server.url)
646 videoId = res.body.data[0].id
649 it('Should fail without a valid uuid', async function () {
653 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
656 it('Should fail with an unknown id', async function () {
660 await makePutBodyRequest({
662 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
663 token: server.accessToken,
665 statusCodeExpected: 404
669 it('Should fail with a wrong rating', async function () {
673 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
676 it('Should succeed with the correct parameters', async function () {
680 await makePutBodyRequest({
682 path: path + videoId + '/rate',
683 token: server.accessToken,
685 statusCodeExpected: 204
690 describe('When removing a video', function () {
691 it('Should have 404 with nothing', async function () {
692 await makeDeleteRequest({
695 statusCodeExpected: 400
699 it('Should fail without a correct uuid', async function () {
700 await removeVideo(server.url, server.accessToken, 'hello', 400)
703 it('Should fail with a video which does not exist', async function () {
704 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
707 it('Should fail with a video of another user without the appropriate right', async function () {
708 await removeVideo(server.url, userAccessToken, videoId, 403)
711 it('Should fail with a video of another server')
713 it('Should succeed with the correct parameters', async function () {
714 await removeVideo(server.url, server.accessToken, videoId)
718 after(async function () {
719 killallServers([ server ])
721 // Keep the logs if the test failed