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, makePostUploadRequest, 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 description: 'my super description',
104 tags: [ 'tag1', 'tag2' ],
105 privacy: VideoPrivacy.PUBLIC,
110 it('Should fail with nothing', async function () {
113 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
116 it('Should fail without name', async function () {
117 const fields = omit(baseCorrectParams, 'name')
118 const attaches = baseCorrectAttaches
120 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
123 it('Should fail with a long name', async function () {
124 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
125 const attaches = baseCorrectAttaches
127 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
130 it('Should fail with a bad category', async function () {
131 const fields = immutableAssign(baseCorrectParams, { category: 125 })
132 const attaches = baseCorrectAttaches
134 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
137 it('Should fail with a bad licence', async function () {
138 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
139 const attaches = baseCorrectAttaches
141 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
144 it('Should fail with a bad language', async function () {
145 const fields = immutableAssign(baseCorrectParams, { language: 125 })
146 const attaches = baseCorrectAttaches
148 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
151 it('Should fail without nsfw attribute', async function () {
152 const fields = omit(baseCorrectParams, 'nsfw')
153 const attaches = baseCorrectAttaches
155 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
158 it('Should fail with a bad nsfw attribute', async function () {
159 const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
160 const attaches = baseCorrectAttaches
162 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
165 it('Should fail with a long description', async function () {
166 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) })
167 const attaches = baseCorrectAttaches
169 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
172 it('Should fail without a channel', async function () {
173 const fields = omit(baseCorrectParams, 'channelId')
174 const attaches = baseCorrectAttaches
176 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
179 it('Should fail with a bad channel', async function () {
180 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
181 const attaches = baseCorrectAttaches
183 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
186 it('Should fail with another user channel', async function () {
189 password: 'fake_password'
191 await createUser(server.url, server.accessToken, user.username, user.password)
193 const accessTokenUser = await userLogin(server, user)
194 const res = await getMyUserInformation(server.url, accessTokenUser)
195 const customChannelId = res.body.videoChannels[0].id
197 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
198 const attaches = baseCorrectAttaches
200 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
203 it('Should fail with too many tags', async function () {
204 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
205 const attaches = baseCorrectAttaches
207 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
210 it('Should fail with a tag length too low', async function () {
211 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
212 const attaches = baseCorrectAttaches
214 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
217 it('Should fail with a tag length too big', async function () {
218 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
219 const attaches = baseCorrectAttaches
221 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
224 it('Should fail without an input file', async function () {
225 const fields = baseCorrectParams
227 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
230 it('Should fail without an incorrect input file', async function () {
231 const fields = baseCorrectParams
233 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
235 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
238 it('Should succeed with the correct parameters', async function () {
241 const fields = baseCorrectParams
244 const attaches = baseCorrectAttaches
245 await makePostUploadRequest({
247 path: path + '/upload',
248 token: server.accessToken,
251 statusCodeExpected: 200
256 const attaches = immutableAssign(baseCorrectAttaches, {
257 videofile: join(__dirname, '..', 'fixtures', 'video_short.mp4')
260 await makePostUploadRequest({
262 path: path + '/upload',
263 token: server.accessToken,
266 statusCodeExpected: 200
271 const attaches = immutableAssign(baseCorrectAttaches, {
272 videofile: join(__dirname, '..', 'fixtures', 'video_short.ogv')
275 await makePostUploadRequest({
277 path: path + '/upload',
278 token: server.accessToken,
281 statusCodeExpected: 200
287 describe('When updating a video', function () {
288 const baseCorrectParams = {
289 name: 'my super name',
294 description: 'my super description',
295 privacy: VideoPrivacy.PUBLIC,
296 tags: [ 'tag1', 'tag2' ]
300 before(async function () {
301 const res = await getVideosList(server.url)
302 videoId = res.body.data[0].id
305 it('Should fail with nothing', async function () {
307 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
310 it('Should fail without a valid uuid', async function () {
311 const fields = baseCorrectParams
312 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
315 it('Should fail with an unknown id', async function () {
316 const fields = baseCorrectParams
318 await makePutBodyRequest({
320 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
321 token: server.accessToken,
323 statusCodeExpected: 404
327 it('Should fail with a long name', async function () {
328 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
330 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
333 it('Should fail with a bad category', async function () {
334 const fields = immutableAssign(baseCorrectParams, { category: 125 })
336 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
339 it('Should fail with a bad licence', async function () {
340 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
342 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
345 it('Should fail with a bad language', async function () {
346 const fields = immutableAssign(baseCorrectParams, { language: 125 })
348 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
351 it('Should fail with a bad nsfw attribute', async function () {
352 const fields = immutableAssign(baseCorrectParams, { nsfw: 2 })
354 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
357 it('Should fail with a long description', async function () {
358 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) })
360 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
363 it('Should fail with too many tags', async function () {
364 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
366 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
369 it('Should fail with a tag length too low', async function () {
370 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
372 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
375 it('Should fail with a tag length too big', async function () {
376 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
378 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
381 it('Should fail with a video of another user')
383 it('Should fail with a video of another server')
385 it('Should succeed with the correct parameters', async function () {
386 const fields = baseCorrectParams
388 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
392 describe('When getting a video', function () {
393 it('Should return the list of the videos with nothing', async function () {
394 const res = await makeGetRequest({
397 statusCodeExpected: 200
400 expect(res.body.data).to.be.an('array')
401 expect(res.body.data.length).to.equal(3)
404 it('Should fail without a correct uuid', async function () {
405 await getVideo(server.url, 'coucou', 400)
408 it('Should return 404 with an incorrect video', async function () {
409 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
412 it('Should succeed with the correct parameters')
415 describe('When rating a video', function () {
418 before(async function () {
419 const res = await getVideosList(server.url)
420 videoId = res.body.data[0].id
423 it('Should fail without a valid uuid', async function () {
427 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
430 it('Should fail with an unknown id', async function () {
434 await makePutBodyRequest({
436 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
437 token: server.accessToken,
439 statusCodeExpected: 404
443 it('Should fail with a wrong rating', async function () {
447 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
450 it('Should succeed with the correct parameters', async function () {
454 await makePutBodyRequest({
456 path: path + videoId + '/rate',
457 token: server.accessToken,
459 statusCodeExpected: 204
464 describe('When removing a video', function () {
465 it('Should have 404 with nothing', async function () {
466 await makeDeleteRequest({
469 statusCodeExpected: 400
473 it('Should fail without a correct uuid', async function () {
474 await removeVideo(server.url, server.accessToken, 'hello', 400)
477 it('Should fail with a video which does not exist', async function () {
478 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404)
481 it('Should fail with a video of another user')
483 it('Should fail with a video of another server')
485 it('Should succeed with the correct parameters')
488 after(async function () {
489 killallServers([ server ])
491 // Keep the logs if the test failed