X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2FcheckParams.js;h=dcc190e97a3cb8bf0e829d97dbd842900aafc963;hb=8c9c1942f6b5675cfca802e2f707bef3c217afbf;hp=1c1ec71b3cf336442dc642017508b98617c2da6b;hpb=b9a3e09ad5a7673f64556d1dba122ed4c4fac980;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/checkParams.js b/server/tests/api/checkParams.js index 1c1ec71b3..dcc190e97 100644 --- a/server/tests/api/checkParams.js +++ b/server/tests/api/checkParams.js @@ -1,27 +1,27 @@ 'use strict' -var async = require('async') -var chai = require('chai') -var expect = chai.expect -var pathUtils = require('path') -var request = require('supertest') +const async = require('async') +const chai = require('chai') +const expect = chai.expect +const pathUtils = require('path') +const request = require('supertest') -var utils = require('./utils') +const utils = require('./utils') describe('Test parameters validator', function () { - var app = null - var url = '' + let app = null + let url = '' function makePostRequest (path, fields, attach, done, fail) { - var status_code = 400 + let status_code = 400 if (fail !== undefined && fail === false) status_code = 200 - var req = request(url) + const req = request(url) .post(path) .set('Accept', 'application/json') Object.keys(fields).forEach(function (field) { - var value = fields[field] + const value = fields[field] req.field(field, value) }) @@ -29,7 +29,7 @@ describe('Test parameters validator', function () { } function makePostBodyRequest (path, fields, done, fail) { - var status_code = 400 + let status_code = 400 if (fail !== undefined && fail === false) status_code = 200 request(url) @@ -59,16 +59,16 @@ describe('Test parameters validator', function () { }) describe('Of the pods API', function () { - var path = '/api/v1/pods/' + const path = '/api/v1/pods/' describe('When adding a pod', function () { it('Should fail with nothing', function (done) { - var data = {} + const data = {} makePostBodyRequest(path, data, done) }) it('Should fail without public key', function (done) { - var data = { + const data = { data: { url: 'http://coucou.com' } @@ -77,7 +77,7 @@ describe('Test parameters validator', function () { }) it('Should fail without an url', function (done) { - var data = { + const data = { data: { publicKey: 'mysuperpublickey' } @@ -86,7 +86,7 @@ describe('Test parameters validator', function () { }) it('Should fail with an incorrect url', function (done) { - var data = { + const data = { data: { url: 'coucou.com', publicKey: 'mysuperpublickey' @@ -102,7 +102,7 @@ describe('Test parameters validator', function () { }) it('Should succeed with the correct parameters', function (done) { - var data = { + const data = { data: { url: 'http://coucou.com', publicKey: 'mysuperpublickey' @@ -114,7 +114,7 @@ describe('Test parameters validator', function () { }) describe('Of the videos API', function () { - var path = '/api/v1/videos/' + const path = '/api/v1/videos/' describe('When searching a video', function () { it('Should fail with nothing', function (done) { @@ -127,87 +127,87 @@ describe('Test parameters validator', function () { describe('When adding a video', function () { it('Should fail with nothing', function (done) { - var data = {} - var attach = {} + const data = {} + const attach = {} makePostRequest(path, data, attach, done) }) it('Should fail without name', function (done) { - var data = { + const data = { description: 'my super description' } - var attach = { - 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') } makePostRequest(path, data, attach, done) }) it('Should fail with a long name', function (done) { - var data = { + const data = { name: 'My very very very very very very very very very very very very very very very very long name', description: 'my super description' } - var attach = { - 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') } makePostRequest(path, data, attach, done) }) it('Should fail without description', function (done) { - var data = { + const data = { name: 'my super name' } - var attach = { - 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') } makePostRequest(path, data, attach, done) }) it('Should fail with a long description', function (done) { - var data = { + const data = { name: 'my super name', description: 'my super description which is very very very very very very very very very very very very very very' + 'very very very very very very very very very very very very very very very very very very very very very' + 'very very very very very very very very very very very very very very very long' } - var attach = { - 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') } makePostRequest(path, data, attach, done) }) it('Should fail without an input file', function (done) { - var data = { + const data = { name: 'my super name', description: 'my super description' } - var attach = {} + const attach = {} makePostRequest(path, data, attach, done) }) it('Should fail without an incorrect input file', function (done) { - var data = { + const data = { name: 'my super name', description: 'my super description' } - var attach = { - 'input_video': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm') + const attach = { + 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm') } makePostRequest(path, data, attach, done) }) it('Should succeed with the correct parameters', function (done) { - var data = { + const data = { name: 'my super name', description: 'my super description' } - var attach = { - 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') } makePostRequest(path, data, attach, function () { - attach.input_video = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4') + attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4') makePostRequest(path, data, attach, function () { - attach.input_video = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv') + attach.videofile = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv') makePostRequest(path, data, attach, done, true) }, true) }, true) @@ -252,7 +252,7 @@ describe('Test parameters validator', function () { it('Should have 404 with nothing', function (done) { request(url) .delete(path) - .expect(404, done) + .expect(400, done) }) it('Should fail without a mongodb id', function (done) {