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 succeed with the correct parameters', async function () {
339 const fields = getCompleteVideoUploadAttributes()
340 const attaches = getVideoUploadAttaches()
342 await makePostUploadRequest({
344 path: path + '/upload',
345 token: server.accessToken,
348 statusCodeExpected: 204
351 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.mp4')
352 await makePostUploadRequest({
354 path: path + '/upload',
355 token: server.accessToken,
358 statusCodeExpected: 204
361 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.ogv')
362 await makePostUploadRequest({
364 path: path + '/upload',
365 token: server.accessToken,
368 statusCodeExpected: 204
373 describe('When updating a video', function () {
376 before(async function () {
377 const res = await getVideosList(server.url)
378 videoId = res.body.data[0].id
381 it('Should fail with nothing', async function () {
383 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
386 it('Should fail without a valid uuid', async function () {
387 const fields = getCompleteVideoUpdateAttributes()
388 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
391 it('Should fail with an unknown id', async function () {
392 const fields = getCompleteVideoUpdateAttributes()
394 await makePutBodyRequest({
396 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
397 token: server.accessToken,
399 statusCodeExpected: 404
403 it('Should fail with a long name', async function () {
404 const fields = getCompleteVideoUpdateAttributes()
405 fields.name = 'My very very very very very very very very very very very very very very very very long'.repeat(3)
407 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
410 it('Should fail with a bad category', async function () {
411 const fields = getCompleteVideoUpdateAttributes()
412 fields.category = 128
414 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
417 it('Should fail with a bad licence', async function () {
418 const fields = getCompleteVideoUpdateAttributes()
421 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
424 it('Should fail with a bad language', async function () {
425 const fields = getCompleteVideoUpdateAttributes()
426 fields.language = 896
428 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
431 it('Should fail with a bad nsfw attribute', async function () {
432 const fields = getCompleteVideoUpdateAttributes()
433 fields.nsfw = (-4 as any)
435 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
438 it('Should fail with a long description', async function () {
439 const fields = getCompleteVideoUpdateAttributes()
440 fields.description = 'my super description which is very very very very very very very very very very very very very long'.repeat(35)
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 = getCompleteVideoUpdateAttributes()
447 fields.tags = [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ]
449 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
452 it('Should fail with a tag length too low', async function () {
453 const fields = getCompleteVideoUpdateAttributes()
454 fields.tags = [ 'tag1', 't' ]
456 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
459 it('Should fail with a tag length too big', async function () {
460 const fields = getCompleteVideoUpdateAttributes()
461 fields.tags = [ 'my_super_tag_too_long_long_long_long', 'tag1' ]
463 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
466 it('Should fail with a video of another user')
468 it('Should fail with a video of another server')
470 it('Should succeed with the correct parameters', async function () {
471 const fields = getCompleteVideoUpdateAttributes()
473 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 })
477 describe('When getting a video', function () {
478 it('Should return the list of the videos with nothing', async function () {
479 const res = await request(server.url)
481 .set('Accept', 'application/json')
483 .expect('Content-Type', /json/)
485 expect(res.body.data).to.be.an('array')
486 expect(res.body.data.length).to.equal(3)
489 it('Should fail without a correct uuid', async function () {
490 await request(server.url)
491 .get(path + 'coucou')
492 .set('Accept', 'application/json')
496 it('Should return 404 with an incorrect video', async function () {
497 await request(server.url)
498 .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
499 .set('Accept', 'application/json')
503 it('Should succeed with the correct parameters')
506 describe('When rating a video', function () {
509 before(async function () {
510 const res = await getVideosList(server.url)
511 videoId = res.body.data[0].id
514 it('Should fail without a valid uuid', async function () {
518 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
521 it('Should fail with an unknown id', async function () {
525 await makePutBodyRequest({
527 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
528 token: server.accessToken,
530 statusCodeExpected: 404
534 it('Should fail with a wrong rating', async function () {
538 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
541 it('Should succeed with the correct parameters', async function () {
545 await makePutBodyRequest({
547 path: path + videoId + '/rate',
548 token: server.accessToken,
550 statusCodeExpected: 204
555 describe('When removing a video', function () {
556 it('Should have 404 with nothing', async function () {
557 await request(server.url)
559 .set('Authorization', 'Bearer ' + server.accessToken)
563 it('Should fail without a correct uuid', async function () {
564 await request(server.url)
565 .delete(path + 'hello')
566 .set('Authorization', 'Bearer ' + server.accessToken)
570 it('Should fail with a video which does not exist', async function () {
571 await request(server.url)
572 .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
573 .set('Authorization', 'Bearer ' + server.accessToken)
577 it('Should fail with a video of another user')
579 it('Should fail with a video of another server')
581 it('Should succeed with the correct parameters')
584 after(async function () {
585 killallServers([ server ])
587 // Keep the logs if the test failed