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,
20 describe('Test videos API validator', function () {
21 const path = '/api/v1/videos/'
22 let server: ServerInfo
24 // ---------------------------------------------------------------
26 before(async function () {
31 server = await runServer(1)
33 await setAccessTokensToServers([ server ])
36 describe('When listing a video', function () {
37 it('Should fail with a bad start pagination', async function () {
38 await request(server.url)
40 .query({ start: 'hello' })
41 .set('Accept', 'application/json')
45 it('Should fail with a bad count pagination', async function () {
46 await request(server.url)
48 .query({ count: 'hello' })
49 .set('Accept', 'application/json')
53 it('Should fail with an incorrect sort', async function () {
54 await request(server.url)
56 .query({ sort: 'hello' })
57 .set('Accept', 'application/json')
62 describe('When searching a video', function () {
63 it('Should fail with nothing', async function () {
64 await request(server.url)
65 .get(join(path, 'search'))
66 .set('Accept', 'application/json')
70 it('Should fail with a bad start pagination', async function () {
71 await request(server.url)
72 .get(join(path, 'search', 'test'))
73 .query({ start: 'hello' })
74 .set('Accept', 'application/json')
78 it('Should fail with a bad count pagination', async function () {
79 await request(server.url)
80 .get(join(path, 'search', 'test'))
81 .query({ count: 'hello' })
82 .set('Accept', 'application/json')
86 it('Should fail with an incorrect sort', async function () {
87 await request(server.url)
88 .get(join(path, 'search', 'test'))
89 .query({ sort: 'hello' })
90 .set('Accept', 'application/json')
95 describe('When adding a video', function () {
96 it('Should fail with nothing', async function () {
99 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
102 it('Should fail without name', async function () {
108 description: 'my super description',
109 tags: [ 'tag1', 'tag2' ]
112 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
114 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
117 it('Should fail with a long name', async function () {
119 name: 'My very very very very very very very very very very very very very very very very long name',
124 description: 'my super description',
125 tags: [ 'tag1', 'tag2' ]
128 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
130 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
133 it('Should fail without a category', async function () {
135 name: 'my super name',
139 description: 'my super description',
140 tags: [ 'tag1', 'tag2' ]
143 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
145 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
148 it('Should fail with a bad category', async function () {
150 name: 'my super name',
155 description: 'my super description',
156 tags: [ 'tag1', 'tag2' ]
159 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
161 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
164 it('Should fail without a licence', async function () {
166 name: 'my super name',
170 description: 'my super description',
171 tags: [ 'tag1', 'tag2' ]
174 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
176 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
179 it('Should fail with a bad licence', async function () {
181 name: 'my super name',
186 description: 'my super description',
187 tags: [ 'tag1', 'tag2' ]
190 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
192 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
195 it('Should fail with a bad language', async function () {
197 name: 'my super name',
202 description: 'my super description',
203 tags: [ 'tag1', 'tag2' ]
206 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
208 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
211 it('Should fail without nsfw attribute', async function () {
213 name: 'my super name',
217 description: 'my super description',
218 tags: [ 'tag1', 'tag2' ]
221 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
223 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
226 it('Should fail with a bad nsfw attribue', async function () {
228 name: 'my super name',
233 description: 'my super description',
234 tags: [ 'tag1', 'tag2' ]
237 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
239 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
242 it('Should fail without description', async function () {
244 name: 'my super name',
249 tags: [ 'tag1', 'tag2' ]
252 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
254 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
257 it('Should fail with a long description', async function () {
259 name: 'my super name',
264 description: 'my super description which is very very very very very very very very very very very very very very' +
265 'very very very very very very very very very very very very very very very very very very very very very' +
266 'very very very very very very very very very very very very very very very long',
267 tags: [ 'tag1', 'tag2' ]
270 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
272 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
275 it('Should fail with too many tags', async function () {
277 name: 'my super name',
282 description: 'my super description',
283 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
286 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
288 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
291 it('Should fail with a tag length too low', async function () {
293 name: 'my super name',
298 description: 'my super description',
299 tags: [ 'tag1', 't' ]
302 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
304 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
307 it('Should fail with a tag length too big', async function () {
309 name: 'my super name',
314 description: 'my super description',
315 tags: [ 'my_super_tag_too_long', 'tag1' ]
318 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
320 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
323 it('Should fail without an input file', async function () {
325 name: 'my super name',
330 description: 'my super description',
331 tags: [ 'tag1', 'tag2' ]
334 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
337 it('Should fail without an incorrect input file', async function () {
339 name: 'my super name',
344 description: 'my super description',
345 tags: [ 'tag1', 'tag2' ]
348 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
350 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
353 it('Should fail with a too big duration', async function () {
355 name: 'my super name',
360 description: 'my super description',
361 tags: [ 'tag1', 'tag2' ]
364 'videofile': join(__dirname, '..', 'fixtures', 'video_too_long.webm')
366 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches })
369 it('Should succeed with the correct parameters', async function () {
373 name: 'my super name',
378 description: 'my super description',
379 tags: [ 'tag1', 'tag2' ]
382 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm')
385 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 204 })
387 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.mp4')
388 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 204 })
390 attaches.videofile = join(__dirname, '..', 'fixtures', 'video_short.ogv')
391 await makePostUploadRequest({ url: server.url, path, token: server.accessToken, fields, attaches, statusCodeExpected: 204 })
395 describe('When updating a video', function () {
398 before(async function () {
399 const res = await getVideosList(server.url)
400 videoId = res.body.data[0].id
403 it('Should fail with nothing', async function () {
405 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
408 it('Should fail without a valid uuid', async function () {
414 description: 'my super description',
415 tags: [ 'tag1', 'tag2' ]
417 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
420 it('Should fail with an unknown id', async function () {
426 description: 'my super description',
427 tags: [ 'tag1', 'tag2' ]
429 await makePutBodyRequest({
431 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
432 token: server.accessToken,
434 statusCodeExpected: 404
438 it('Should fail with a long name', async function () {
440 name: 'My very very very very very very very very very very very very very very very very long name',
445 description: 'my super description',
446 tags: [ 'tag1', 'tag2' ]
448 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
451 it('Should fail with a bad category', async function () {
453 name: 'my super name',
458 description: 'my super description',
459 tags: [ 'tag1', 'tag2' ]
461 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
464 it('Should fail with a bad licence', async function () {
466 name: 'my super name',
471 description: 'my super description',
472 tags: [ 'tag1', 'tag2' ]
474 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
477 it('Should fail with a bad language', async function () {
479 name: 'my super name',
484 description: 'my super description',
485 tags: [ 'tag1', 'tag2' ]
487 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
490 it('Should fail with a bad nsfw attribute', async function () {
492 name: 'my super name',
497 description: 'my super description',
498 tags: [ 'tag1', 'tag2' ]
500 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
503 it('Should fail with a long description', async function () {
505 name: 'my super name',
510 description: 'my super description which is very very very very very very very very very very very very very very' +
511 'very very very very very very very very very very very very very very very very very very very very very' +
512 'very very very very very very very very very very very very very very very long',
513 tags: [ 'tag1', 'tag2' ]
515 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
518 it('Should fail with too many tags', async function () {
520 name: 'my super name',
525 description: 'my super description',
526 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
528 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
531 it('Should fail with a tag length too low', async function () {
533 name: 'my super name',
538 description: 'my super description',
539 tags: [ 'tag1', 't' ]
541 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
544 it('Should fail with a tag length too big', async function () {
546 name: 'my super name',
551 description: 'my super description',
552 tags: [ 'my_super_tag_too_long', 'tag1' ]
554 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
557 it('Should fail with a video of another user')
559 it('Should fail with a video of another pod')
562 describe('When getting a video', function () {
563 it('Should return the list of the videos with nothing', async function () {
564 const res = await request(server.url)
566 .set('Accept', 'application/json')
568 .expect('Content-Type', /json/)
570 expect(res.body.data).to.be.an('array')
571 expect(res.body.data.length).to.equal(3)
574 it('Should fail without a correct uuid', async function () {
575 await request(server.url)
576 .get(path + 'coucou')
577 .set('Accept', 'application/json')
581 it('Should return 404 with an incorrect video', async function () {
582 await request(server.url)
583 .get(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
584 .set('Accept', 'application/json')
588 it('Should succeed with the correct parameters')
591 describe('When rating a video', function () {
594 before(async function () {
595 const res = await getVideosList(server.url)
596 videoId = res.body.data[0].id
599 it('Should fail without a valid uuid', async function () {
603 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
606 it('Should fail with an unknown id', async function () {
610 await makePutBodyRequest({
612 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
613 token: server.accessToken,
615 statusCodeExpected: 404
619 it('Should fail with a wrong rating', async function () {
623 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
626 it('Should succeed with the correct parameters', async function () {
630 await makePutBodyRequest({
632 path: path + videoId + '/rate',
633 token: server.accessToken,
635 statusCodeExpected: 204
640 describe('When removing a video', function () {
641 it('Should have 404 with nothing', async function () {
642 await request(server.url)
644 .set('Authorization', 'Bearer ' + server.accessToken)
648 it('Should fail without a correct uuid', async function () {
649 await request(server.url)
650 .delete(path + 'hello')
651 .set('Authorization', 'Bearer ' + server.accessToken)
655 it('Should fail with a video which does not exist', async function () {
656 await request(server.url)
657 .delete(path + '4da6fde3-88f7-4d16-b119-108df5630b06')
658 .set('Authorization', 'Bearer ' + server.accessToken)
662 it('Should fail with a video of another user')
664 it('Should fail with a video of another pod')
666 it('Should succeed with the correct parameters')
669 after(async function () {
670 killallServers([ server ])
672 // Keep the logs if the test failed