From f0f5567b6918fc60c8cab15e13aec03a89a91dfb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 16 Mar 2016 22:29:27 +0100 Subject: Use const/let now we use node 4.2 --- server/tests/api/checkParams.js | 70 ++++++++++++++++++------------------- server/tests/api/friendsAdvanced.js | 22 ++++++------ server/tests/api/friendsBasic.js | 36 +++++++++---------- server/tests/api/multiplePods.js | 46 ++++++++++++------------ server/tests/api/singlePod.js | 24 ++++++------- server/tests/api/utils.js | 62 ++++++++++++++++---------------- 6 files changed, 129 insertions(+), 131 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/checkParams.js b/server/tests/api/checkParams.js index 01b620873..b31b0e894 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,81 +127,81 @@ 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 = { + const attach = { 'input_video': 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 = { + const attach = { 'input_video': 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 = { + const attach = { 'input_video': 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 = { + const attach = { 'input_video': 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 = { + const attach = { 'input_video': 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 = { + const attach = { 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') } makePostRequest(path, data, attach, function () { diff --git a/server/tests/api/friendsAdvanced.js b/server/tests/api/friendsAdvanced.js index 9838d890f..6c4b7567f 100644 --- a/server/tests/api/friendsAdvanced.js +++ b/server/tests/api/friendsAdvanced.js @@ -1,14 +1,14 @@ 'use strict' -var async = require('async') -var chai = require('chai') -var expect = chai.expect +const async = require('async') +const chai = require('chai') +const expect = chai.expect -var utils = require('./utils') +const utils = require('./utils') describe('Test advanced friends', function () { - var apps = [] - var urls = [] + let apps = [] + let urls = [] function makeFriends (pod_number, callback) { return utils.makeFriends(urls[pod_number - 1], callback) @@ -23,9 +23,9 @@ describe('Test advanced friends', function () { } function uploadVideo (pod_number, callback) { - var name = 'my super video' - var description = 'my super description' - var fixture = 'video_short.webm' + const name = 'my super video' + const description = 'my super description' + const fixture = 'video_short.webm' return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback) } @@ -171,9 +171,9 @@ describe('Test advanced friends', function () { if (err) throw err // Pod 4 should not be our friend - var result = res.body + const result = res.body expect(result.length).to.equal(3) - for (var pod of result) { + for (const pod of result) { expect(pod.url).not.equal(urls[3]) } diff --git a/server/tests/api/friendsBasic.js b/server/tests/api/friendsBasic.js index 328724936..62eac51ec 100644 --- a/server/tests/api/friendsBasic.js +++ b/server/tests/api/friendsBasic.js @@ -1,19 +1,19 @@ 'use strict' -var async = require('async') -var chai = require('chai') -var expect = chai.expect -var request = require('supertest') +const async = require('async') +const chai = require('chai') +const expect = chai.expect +const request = require('supertest') -var utils = require('./utils') +const utils = require('./utils') describe('Test basic friends', function () { - var apps = [] - var urls = [] + let apps = [] + let urls = [] function testMadeFriends (urls, url_to_test, callback) { - var friends = [] - for (var i = 0; i < urls.length; i++) { + const friends = [] + for (let i = 0; i < urls.length; i++) { if (urls[i] === url_to_test) continue friends.push(urls[i]) } @@ -21,13 +21,13 @@ describe('Test basic friends', function () { utils.getFriendsList(url_to_test, function (err, res) { if (err) throw err - var result = res.body - var result_urls = [ result[0].url, result[1].url ] + const result = res.body + const result_urls = [ result[0].url, result[1].url ] expect(result).to.be.an('array') expect(result.length).to.equal(2) expect(result_urls[0]).to.not.equal(result_urls[1]) - var error_string = 'Friends url do not correspond for ' + url_to_test + const error_string = 'Friends url do not correspond for ' + url_to_test expect(friends).to.contain(result_urls[0], error_string) expect(friends).to.contain(result_urls[1], error_string) callback() @@ -50,7 +50,7 @@ describe('Test basic friends', function () { utils.getFriendsList(url, function (err, res) { if (err) throw err - var result = res.body + const result = res.body expect(result).to.be.an('array') expect(result.length).to.equal(0) callback() @@ -61,7 +61,7 @@ describe('Test basic friends', function () { it('Should make friends', function (done) { this.timeout(10000) - var path = '/api/v1/pods/makefriends' + const path = '/api/v1/pods/makefriends' async.series([ // The second pod make friend with the third @@ -81,7 +81,7 @@ describe('Test basic friends', function () { utils.getFriendsList(urls[1], function (err, res) { if (err) throw err - var result = res.body + const result = res.body expect(result).to.be.an('array') expect(result.length).to.equal(1) expect(result[0].url).to.be.equal(urls[2]) @@ -94,7 +94,7 @@ describe('Test basic friends', function () { utils.getFriendsList(urls[2], function (err, res) { if (err) throw err - var result = res.body + const result = res.body expect(result).to.be.an('array') expect(result.length).to.equal(1) expect(result[0].url).to.be.equal(urls[1]) @@ -139,7 +139,7 @@ describe('Test basic friends', function () { utils.getFriendsList(urls[1], function (err, res) { if (err) throw err - var result = res.body + const result = res.body expect(result).to.be.an('array') expect(result.length).to.equal(0) @@ -152,7 +152,7 @@ describe('Test basic friends', function () { utils.getFriendsList(url, function (err, res) { if (err) throw err - var result = res.body + const result = res.body expect(result).to.be.an('array') expect(result.length).to.equal(1) expect(result[0].url).not.to.be.equal(urls[1]) diff --git a/server/tests/api/multiplePods.js b/server/tests/api/multiplePods.js index 9fdd0f308..e8b182622 100644 --- a/server/tests/api/multiplePods.js +++ b/server/tests/api/multiplePods.js @@ -1,18 +1,18 @@ 'use strict' -var async = require('async') -var chai = require('chai') -var expect = chai.expect -var pathUtils = require('path') +const async = require('async') +const chai = require('chai') +const expect = chai.expect +const pathUtils = require('path') -var utils = require('./utils') -var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) +const utils = require('./utils') +const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) webtorrent.silent = true describe('Test multiple pods', function () { - var apps = [] - var urls = [] - var to_remove = [] + let apps = [] + let urls = [] + const to_remove = [] before(function (done) { this.timeout(30000) @@ -73,15 +73,15 @@ describe('Test multiple pods', function () { if (err) throw err async.each(urls, function (url, callback) { - var base_magnet = null + let base_magnet = null utils.getVideosList(url, function (err, res) { if (err) throw err - var videos = res.body + const videos = res.body expect(videos).to.be.an('array') expect(videos.length).to.equal(1) - var video = videos[0] + const video = videos[0] expect(video.name).to.equal('my super name for pod 1') expect(video.description).to.equal('my super description for pod 1') expect(video.podUrl).to.equal('http://localhost:9001') @@ -116,15 +116,15 @@ describe('Test multiple pods', function () { if (err) throw err async.each(urls, function (url, callback) { - var base_magnet = null + let base_magnet = null utils.getVideosList(url, function (err, res) { if (err) throw err - var videos = res.body + const videos = res.body expect(videos).to.be.an('array') expect(videos.length).to.equal(2) - var video = videos[1] + const video = videos[1] expect(video.name).to.equal('my super name for pod 2') expect(video.description).to.equal('my super description for pod 2') expect(video.podUrl).to.equal('http://localhost:9002') @@ -160,16 +160,16 @@ describe('Test multiple pods', function () { function (err) { if (err) throw err - var base_magnet = null + let base_magnet = null // All pods should have this video async.each(urls, function (url, callback) { utils.getVideosList(url, function (err, res) { if (err) throw err - var videos = res.body + const videos = res.body expect(videos).to.be.an('array') expect(videos.length).to.equal(4) - var video = videos[2] + let video = videos[2] expect(video.name).to.equal('my super name for pod 3') expect(video.description).to.equal('my super description for pod 3') expect(video.podUrl).to.equal('http://localhost:9003') @@ -204,7 +204,7 @@ describe('Test multiple pods', function () { utils.getVideosList(urls[2], function (err, res) { if (err) throw err - var video = res.body[0] + const video = res.body[0] to_remove.push(res.body[2]._id) to_remove.push(res.body[3]._id) @@ -225,7 +225,7 @@ describe('Test multiple pods', function () { utils.getVideosList(urls[0], function (err, res) { if (err) throw err - var video = res.body[1] + const video = res.body[1] webtorrent.add(video.magnetUri, function (torrent) { expect(torrent.files).to.exist @@ -244,7 +244,7 @@ describe('Test multiple pods', function () { utils.getVideosList(urls[1], function (err, res) { if (err) throw err - var video = res.body[2] + const video = res.body[2] webtorrent.add(video.magnetUri, function (torrent) { expect(torrent.files).to.exist @@ -263,7 +263,7 @@ describe('Test multiple pods', function () { utils.getVideosList(urls[0], function (err, res) { if (err) throw err - var video = res.body[3] + const video = res.body[3] webtorrent.add(video.magnetUri, function (torrent) { expect(torrent.files).to.exist @@ -297,7 +297,7 @@ describe('Test multiple pods', function () { utils.getVideosList(url, function (err, res) { if (err) throw err - var videos = res.body + const videos = res.body expect(videos).to.be.an('array') expect(videos.length).to.equal(2) expect(videos[0]._id).not.to.equal(videos[1]._id) diff --git a/server/tests/api/singlePod.js b/server/tests/api/singlePod.js index d572aacf6..14f893f13 100644 --- a/server/tests/api/singlePod.js +++ b/server/tests/api/singlePod.js @@ -1,20 +1,20 @@ 'use strict' -var async = require('async') -var chai = require('chai') -var expect = chai.expect -var fs = require('fs') -var pathUtils = require('path') +const async = require('async') +const chai = require('chai') +const expect = chai.expect +const fs = require('fs') +const pathUtils = require('path') -var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) +const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) webtorrent.silent = true -var utils = require('./utils') +const utils = require('./utils') describe('Test a single pod', function () { - var app = null - var url = '' - var video_id = -1 + let app = null + let url = '' + let video_id = -1 before(function (done) { this.timeout(20000) @@ -62,7 +62,7 @@ describe('Test a single pod', function () { expect(res.body).to.be.an('array') expect(res.body.length).to.equal(1) - var video = res.body[0] + const video = res.body[0] expect(video.name).to.equal('my super name') expect(video.description).to.equal('my super description') expect(video.podUrl).to.equal('http://localhost:9001') @@ -87,7 +87,7 @@ describe('Test a single pod', function () { expect(res.body).to.be.an('array') expect(res.body.length).to.equal(1) - var video = res.body[0] + const video = res.body[0] expect(video.name).to.equal('my super name') expect(video.description).to.equal('my super description') expect(video.podUrl).to.equal('http://localhost:9001') diff --git a/server/tests/api/utils.js b/server/tests/api/utils.js index 60c3c8d4e..05142085f 100644 --- a/server/tests/api/utils.js +++ b/server/tests/api/utils.js @@ -1,12 +1,12 @@ 'use strict' -var child_process = require('child_process') -var exec = child_process.exec -var fork = child_process.fork -var pathUtils = require('path') -var request = require('supertest') +const child_process = require('child_process') +const exec = child_process.exec +const fork = child_process.fork +const pathUtils = require('path') +const request = require('supertest') -var testUtils = { +const testUtils = { flushTests: flushTests, getFriendsList: getFriendsList, getVideosList: getVideosList, @@ -26,7 +26,7 @@ function flushTests (callback) { } function getFriendsList (url, end) { - var path = '/api/v1/pods/' + const path = '/api/v1/pods/' request(url) .get(path) @@ -37,7 +37,7 @@ function getFriendsList (url, end) { } function getVideosList (url, end) { - var path = '/api/v1/videos' + const path = '/api/v1/videos' request(url) .get(path) @@ -53,7 +53,7 @@ function makeFriends (url, expected_status, callback) { expected_status = 204 } - var path = '/api/v1/pods/makefriends' + const path = '/api/v1/pods/makefriends' // The first pod make friend with the third request(url) @@ -69,7 +69,7 @@ function makeFriends (url, expected_status, callback) { } function quitFriends (url, callback) { - var path = '/api/v1/pods/quitfriends' + const path = '/api/v1/pods/quitfriends' // The first pod make friend with the third request(url) @@ -85,7 +85,7 @@ function quitFriends (url, callback) { } function removeVideo (url, id, end) { - var path = '/api/v1/videos' + const path = '/api/v1/videos' request(url) .delete(path + '/' + id) @@ -95,9 +95,9 @@ function removeVideo (url, id, end) { } function flushAndRunMultipleServers (total_servers, serversRun) { - var apps = [] - var urls = [] - var i = 0 + let apps = [] + let urls = [] + let i = 0 function anotherServerDone (number, app, url) { apps[number - 1] = app @@ -109,41 +109,39 @@ function flushAndRunMultipleServers (total_servers, serversRun) { } flushTests(function () { - for (var j = 1; j <= total_servers; j++) { - (function (k) { // TODO: ES6 with let - // For the virtual buffer - setTimeout(function () { - runServer(k, function (app, url) { - anotherServerDone(k, app, url) - }) - }, 1000 * k) - })(j) + for (let j = 1; j <= total_servers; j++) { + // For the virtual buffer + setTimeout(function () { + runServer(j, function (app, url) { + anotherServerDone(j, app, url) + }) + }, 1000 * j) } }) } function runServer (number, callback) { - var port = 9000 + number - var server_run_string = { + const port = 9000 + number + const server_run_string = { 'Connected to mongodb': false, 'Server listening on port': false } // Share the environment - var env = Object.create(process.env) + const env = Object.create(process.env) env.NODE_ENV = 'test' env.NODE_APP_INSTANCE = number - var options = { + const options = { silent: true, env: env, detached: true } - var app = fork(pathUtils.join(__dirname, '../../../server.js'), [], options) + const app = fork(pathUtils.join(__dirname, '../../../server.js'), [], options) app.stdout.on('data', function onStdout (data) { - var dont_continue = false + let dont_continue = false // Check if all required sentences are here - for (var key of Object.keys(server_run_string)) { + for (const key of Object.keys(server_run_string)) { if (data.toString().indexOf(key) !== -1) server_run_string[key] = true if (server_run_string[key] === false) dont_continue = true } @@ -157,7 +155,7 @@ function runServer (number, callback) { } function searchVideo (url, search, end) { - var path = '/api/v1/videos' + const path = '/api/v1/videos' request(url) .get(path + '/search/' + search) @@ -168,7 +166,7 @@ function searchVideo (url, search, end) { } function uploadVideo (url, name, description, fixture, end) { - var path = '/api/v1/videos' + const path = '/api/v1/videos' request(url) .post(path) -- cgit v1.2.3