1 /* tslint:disable:no-unused-expression */
3 import * as request from 'supertest'
4 import { join } from 'path'
6 import * as chai from 'chai'
7 const expect = chai.expect
15 setAccessTokensToServers,
17 makePostUploadRequest,
22 import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
24 describe('Test videos API validator', function () {
25 const path = '/api/v1/videos/'
26 let server: ServerInfo
29 function getCompleteVideoUploadAttributes () {
31 name: 'my super name',
36 description: 'my super description',
37 tags: [ 'tag1', 'tag2' ],
38 privacy: VideoPrivacy.PUBLIC,
43 function getCompleteVideoUpdateAttributes () {
45 name: 'my super name',
50 description: 'my super description',
51 privacy: VideoPrivacy.PUBLIC,
52 tags: [ 'tag1', 'tag2' ]
56 function getVideoUploadAttaches () {
58 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
62 // ---------------------------------------------------------------
64 before(async function () {
69 server = await runServer(1)
71 await setAccessTokensToServers([ server ])
73 const res = await getMyUserInformation(server.url, server.accessToken)
74 channelId = res.body.videoChannels[0].id
77 describe('When listing a video', function () {
78 it('Should fail with a bad start pagination', async function () {
79 await request(server.url)
81 .query({ start: 'hello' })
82 .set('Accept', 'application/json')
86 it('Should fail with a bad count pagination', async function () {
87 await request(server.url)
89 .query({ count: 'hello' })
90 .set('Accept', 'application/json')
94 it('Should fail with an incorrect sort', async function () {
95 await request(server.url)
97 .query({ sort: 'hello' })
98 .set('Accept', 'application/json')
103 describe('When searching a video', function () {
104 it('Should fail with nothing', async function () {
105 await request(server.url)
106 .get(join(path, 'search'))
107 .set('Accept', 'application/json')
111 it('Should fail with a bad start pagination', async function () {
112 await request(server.url)
113 .get(join(path, 'search', 'test'))
114 .query({ start: 'hello' })
115 .set('Accept', 'application/json')
119 it('Should fail with a bad count pagination', async function () {
120 await request(server.url)
121 .get(join(path, 'search', 'test'))
122 .query({ count: 'hello' })
123 .set('Accept', 'application/json')
127 it('Should fail with an incorrect sort', async function () {
128 await request(server.url)
129 .get(join(path, 'search', 'test'))
130 .query({ sort: 'hello' })
131 .set('Accept', 'application/json')
136 describe('When listing my videos', function () {
137 const path = '/api/v1/users/me/videos'
139 it('Should fail with a bad start pagination', async function () {
140 await request(server.url)
142 .set('Authorization', 'Bearer ' + server.accessToken)
143 .query({ start: 'hello' })
144 .set('Accept', 'application/json')
148 it('Should fail with a bad count pagination', async function () {
149 await request(server.url)
151 .set('Authorization', 'Bearer ' + server.accessToken)
152 .query({ count: 'hello' })
153 .set('Accept', 'application/json')
157 it('Should fail with an incorrect sort', async function () {
158 await request(server.url)
160 .set('Authorization', 'Bearer ' + server.accessToken)
161 .query({ sort: 'hello' })
162 .set('Accept', 'application/json')
167 describe('When adding a video', function () {
168 it('Should fail with nothing', async function () {
171 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
174 it('Should fail without name', async function () {
175 const fields = getCompleteVideoUploadAttributes()
178 const attaches = getVideoUploadAttaches()
179 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
182 it('Should fail with a long name', async function () {
183 const fields = getCompleteVideoUploadAttributes()
184 fields.name = 'My very very very very very very very very very very very very very very very very very ' +
185 'very very very very very very very very very very very very very very very very long long' +
186 'very very very very very very very very very very very very very very very very long name'
188 const attaches = getVideoUploadAttaches
189 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
192 it('Should fail without a category', async function () {
193 const fields = getCompleteVideoUploadAttributes()
194 delete fields.category
196 const attaches = getVideoUploadAttaches
197 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
200 it('Should fail with a bad category', async function () {
201 const fields = getCompleteVideoUploadAttributes()
202 fields.category = 125
204 const attaches = getVideoUploadAttaches
205 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
208 it('Should fail without a licence', async function () {
209 const fields = getCompleteVideoUploadAttributes()
210 delete fields.licence
212 const attaches = getVideoUploadAttaches()
213 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
216 it('Should fail with a bad licence', async function () {
217 const fields = getCompleteVideoUploadAttributes()
220 const attaches = getVideoUploadAttaches()
221 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
224 it('Should fail with a bad language', async function () {
225 const fields = getCompleteVideoUploadAttributes()
226 fields.language = 563
228 const attaches = getVideoUploadAttaches()
229 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
232 it('Should fail without nsfw attribute', async function () {
233 const fields = getCompleteVideoUploadAttributes()
236 const attaches = getVideoUploadAttaches()
237 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
240 it('Should fail with a bad nsfw attribute', async function () {
241 const fields = getCompleteVideoUploadAttributes()
242 fields.nsfw = 2 as any
244 const attaches = getVideoUploadAttaches()
245 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
248 it('Should fail without description', async function () {
249 const fields = getCompleteVideoUploadAttributes()
250 delete fields.description
252 const attaches = getVideoUploadAttaches()
253 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
256 it('Should fail with a long description', async function () {
257 const fields = getCompleteVideoUploadAttributes()
258 fields.description = 'my super description which is very very very very very very very very very very very very long'.repeat(35)
260 const attaches = getVideoUploadAttaches()
261 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
264 it('Should fail without a channel', async function () {
265 const fields = getCompleteVideoUploadAttributes()
266 delete fields.channelId
268 const attaches = getVideoUploadAttaches()
269 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
272 it('Should fail with a bad channel', async function () {
273 const fields = getCompleteVideoUploadAttributes()
274 fields.channelId = 545454
276 const attaches = getVideoUploadAttaches()
277 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
280 it('Should fail with another user channel', async function () {
283 password: 'fake_password'
285 await createUser(server.url, server.accessToken, user.username, user.password)
287 const accessTokenUser = await getUserAccessToken(server, user)
288 const res = await getMyUserInformation(server.url, accessTokenUser)
289 const customChannelId = res.body.videoChannels[0].id
291 const fields = getCompleteVideoUploadAttributes()
292 fields.channelId = customChannelId
294 const attaches = getVideoUploadAttaches()
295 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
298 it('Should fail with too many tags', async function () {
299 const fields = getCompleteVideoUploadAttributes()
300 fields.tags = [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ]
302 const attaches = getVideoUploadAttaches()
303 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
306 it('Should fail with a tag length too low', async function () {
307 const fields = getCompleteVideoUploadAttributes()
308 fields.tags = [ 'tag1', 't' ]
310 const attaches = getVideoUploadAttaches()
311 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
314 it('Should fail with a tag length too big', async function () {
315 const fields = getCompleteVideoUploadAttributes()
316 fields.tags = [ 'my_super_tag_too_long_long_long_long_long_long', 'tag1' ]
318 const attaches = getVideoUploadAttaches()
319 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
322 it('Should fail without an input file', async function () {
323 const fields = getCompleteVideoUploadAttributes()
325 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
328 it('Should fail without an incorrect input file', async function () {
329 const fields = getCompleteVideoUploadAttributes()
331 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
333 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
336 it('Should fail with a too big duration', async function () {
337 const fields = getCompleteVideoUploadAttributes()
339 'videofile': join(__dirname, '..', 'fixtures', 'video_too_long.webm')
341 await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
344 it('Should succeed with the correct parameters', async function () {
347 const fields = getCompleteVideoUploadAttributes()
348 const attaches = getVideoUploadAttaches()
350 await makePostUploadRequest({
352 path: path + '/upload',
353 token: server.accessToken,
356 statusCodeExpected: 204
359 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.mp4')
360 await makePostUploadRequest({
362 path: path + '/upload',
363 token: server.accessToken,
366 statusCodeExpected: 204
369 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.ogv')
370 await makePostUploadRequest({
372 path: path + '/upload',
373 token: server.accessToken,
376 statusCodeExpected: 204
381 describe('When updating a video', function () {
384 before(async function () {
385 const res = await getVideosList(server.url)
386 videoId = res.body.data[0].id
389 it('Should fail with nothing', async function () {
391 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
394 it('Should fail without a valid uuid', async function () {
395 const fields = getCompleteVideoUpdateAttributes()
396 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
399 it('Should fail with an unknown id', async function () {
400 const fields = getCompleteVideoUpdateAttributes()
402 await makePutBodyRequest({
404 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
405 token: server.accessToken,
407 statusCodeExpected: 404
411 it('Should fail with a long name', async function () {
412 const fields = getCompleteVideoUpdateAttributes()
413 fields.name = 'My very very very very very very very very very very very very very very very very long'.repeat(3)
415 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
418 it('Should fail with a bad category', async function () {
419 const fields = getCompleteVideoUpdateAttributes()
420 fields.category = 128
422 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
425 it('Should fail with a bad licence', async function () {
426 const fields = getCompleteVideoUpdateAttributes()
429 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
432 it('Should fail with a bad language', async function () {
433 const fields = getCompleteVideoUpdateAttributes()
434 fields.language = 896
436 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
439 it('Should fail with a bad nsfw attribute', async function () {
440 const fields = getCompleteVideoUpdateAttributes()
441 fields.nsfw = (-4 as any)
443 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
446 it('Should fail with a long description', async function () {
447 const fields = getCompleteVideoUpdateAttributes()
448 fields.description = 'my super description which is very very very very very very very very very very very very very long'.repeat(35)
450 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
453 it('Should fail with too many tags', async function () {
454 const fields = getCompleteVideoUpdateAttributes()
455 fields.tags = [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ]
457 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
460 it('Should fail with a tag length too low', async function () {
461 const fields = getCompleteVideoUpdateAttributes()
462 fields.tags = [ 'tag1', 't' ]
464 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
467 it('Should fail with a tag length too big', async function () {
468 const fields = getCompleteVideoUpdateAttributes()
469 fields.tags = [ 'my_super_tag_too_long_long_long_long', 'tag1' ]
471 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
474 it('Should fail with a video of another user')
476 it('Should fail with a video of another server')
478 it('Should succeed with the correct parameters', async function () {
479 const fields = getCompleteVideoUpdateAttributes()
481 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
485 describe('When getting a video', function () {
486 it('Should return the list of the videos with nothing', async function () {
487 const res = await request(server.url)
489 .set('Accept', 'application/json')
491 .expect('Content-Type', /json/)
493 expect(res.body.data).to.be.an('array')
494 expect(res.body.data.length).to.equal(3)
497 it('Should fail without a correct uuid', async function () {
498 await request(server.url)
499 .get(path + 'coucou')
500 .set('Accept', 'application/json')
504 it('Should return 404 with an incorrect video', async function () {
505 await request(server.url)
506 .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
507 .set('Accept', 'application/json')
511 it('Should succeed with the correct parameters')
514 describe('When rating a video', function () {
517 before(async function () {
518 const res = await getVideosList(server.url)
519 videoId = res.body.data[0].id
522 it('Should fail without a valid uuid', async function () {
526 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
529 it('Should fail with an unknown id', async function () {
533 await makePutBodyRequest({
535 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
536 token: server.accessToken,
538 statusCodeExpected: 404
542 it('Should fail with a wrong rating', async function () {
546 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
549 it('Should succeed with the correct parameters', async function () {
553 await makePutBodyRequest({
555 path: path + videoId + '/rate',
556 token: server.accessToken,
558 statusCodeExpected: 204
563 describe('When removing a video', function () {
564 it('Should have 404 with nothing', async function () {
565 await request(server.url)
567 .set('Authorization', 'Bearer ' + server.accessToken)
571 it('Should fail without a correct uuid', async function () {
572 await request(server.url)
573 .delete(path + 'hello')
574 .set('Authorization', 'Bearer ' + server.accessToken)
578 it('Should fail with a video which does not exist', async function () {
579 await request(server.url)
580 .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
581 .set('Authorization', 'Bearer ' + server.accessToken)
585 it('Should fail with a video of another user')
587 it('Should fail with a video of another server')
589 it('Should succeed with the correct parameters')
592 after(async function () {
593 killallServers([ server ])
595 // Keep the logs if the test failed