3 const async = require('async')
4 const chai = require('chai')
5 const expect = chai.expect
6 const pathUtils = require('path')
7 const request = require('supertest')
9 const utils = require('./utils')
11 describe('Test parameters validator', function () {
15 function makePostRequest (path, fields, attach, done, fail) {
17 if (fail !== undefined && fail === false) status_code = 200
19 const req = request(url)
21 .set('Accept', 'application/json')
23 Object.keys(fields).forEach(function (field) {
24 const value = fields[field]
25 req.field(field, value)
28 req.expect(status_code, done)
31 function makePostBodyRequest (path, fields, done, fail) {
33 if (fail !== undefined && fail === false) status_code = 200
37 .set('Accept', 'application/json')
39 .expect(status_code, done)
42 // ---------------------------------------------------------------
44 before(function (done) {
49 utils.flushTests(next)
52 utils.runServer(1, function (app1, url1) {
61 describe('Of the pods API', function () {
62 const path = '/api/v1/pods/'
64 describe('When adding a pod', function () {
65 it('Should fail with nothing', function (done) {
67 makePostBodyRequest(path, data, done)
70 it('Should fail without public key', function (done) {
73 url: 'http://coucou.com'
76 makePostBodyRequest(path, data, done)
79 it('Should fail without an url', function (done) {
82 publicKey: 'mysuperpublickey'
85 makePostBodyRequest(path, data, done)
88 it('Should fail with an incorrect url', function (done) {
92 publicKey: 'mysuperpublickey'
95 makePostBodyRequest(path, data, function () {
96 data.data.url = 'http://coucou'
97 makePostBodyRequest(path, data, function () {
98 data.data.url = 'coucou'
99 makePostBodyRequest(path, data, done)
104 it('Should succeed with the correct parameters', function (done) {
107 url: 'http://coucou.com',
108 publicKey: 'mysuperpublickey'
111 makePostBodyRequest(path, data, done, false)
116 describe('Of the videos API', function () {
117 const path = '/api/v1/videos/'
119 describe('When searching a video', function () {
120 it('Should fail with nothing', function (done) {
122 .get(pathUtils.join(path, 'search'))
123 .set('Accept', 'application/json')
128 describe('When adding a video', function () {
129 it('Should fail with nothing', function (done) {
132 makePostRequest(path, data, attach, done)
135 it('Should fail without name', function (done) {
137 description: 'my super description'
140 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
142 makePostRequest(path, data, attach, done)
145 it('Should fail with a long name', function (done) {
147 name: 'My very very very very very very very very very very very very very very very very long name',
148 description: 'my super description'
151 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
153 makePostRequest(path, data, attach, done)
156 it('Should fail without description', function (done) {
158 name: 'my super name'
161 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
163 makePostRequest(path, data, attach, done)
166 it('Should fail with a long description', function (done) {
168 name: 'my super name',
169 description: 'my super description which is very very very very very very very very very very very very very very' +
170 'very very very very very very very very very very very very very very very very very very very very very' +
171 'very very very very very very very very very very very very very very very long'
174 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
176 makePostRequest(path, data, attach, done)
179 it('Should fail without an input file', function (done) {
181 name: 'my super name',
182 description: 'my super description'
185 makePostRequest(path, data, attach, done)
188 it('Should fail without an incorrect input file', function (done) {
190 name: 'my super name',
191 description: 'my super description'
194 'input_video': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
196 makePostRequest(path, data, attach, done)
199 it('Should succeed with the correct parameters', function (done) {
201 name: 'my super name',
202 description: 'my super description'
205 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
207 makePostRequest(path, data, attach, function () {
208 attach.input_video = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4')
209 makePostRequest(path, data, attach, function () {
210 attach.input_video = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv')
211 makePostRequest(path, data, attach, done, true)
217 describe('When getting a video', function () {
218 it('Should return the list of the videos with nothing', function (done) {
221 .set('Accept', 'application/json')
223 .expect('Content-Type', /json/)
224 .end(function (err, res) {
227 expect(res.body).to.be.an('array')
228 expect(res.body.length).to.equal(0)
234 it('Should fail without a mongodb id', function (done) {
236 .get(path + 'coucou')
237 .set('Accept', 'application/json')
241 it('Should return 404 with an incorrect video', function (done) {
243 .get(path + '123456789012345678901234')
244 .set('Accept', 'application/json')
248 it('Should succeed with the correct parameters')
251 describe('When removing a video', function () {
252 it('Should have 404 with nothing', function (done) {
258 it('Should fail without a mongodb id', function (done) {
260 .delete(path + 'hello')
264 it('Should fail with a video which does not exist', function (done) {
266 .delete(path + '123456789012345678901234')
270 it('Should fail with a video of another pod')
272 it('Should succeed with the correct parameters')
276 describe('Of the remote videos API', function () {
277 describe('When making a secure request', function () {
278 it('Should check a secure request')
281 describe('When adding a video', function () {
282 it('Should check when adding a video')
285 describe('When removing a video', function () {
286 it('Should check when removing a video')
290 after(function (done) {
291 process.kill(-app.pid)
293 // Keep the logs if the test failed
295 utils.flushTests(done)