aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-03-16 22:29:27 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-03-16 22:29:27 +0100
commitf0f5567b6918fc60c8cab15e13aec03a89a91dfb (patch)
tree99dfdb9fa8273c9cda1360fd3b6bfccc515bf8be /server/tests/api
parent5101105ef91bfe478f97546b78b321882da2079c (diff)
downloadPeerTube-f0f5567b6918fc60c8cab15e13aec03a89a91dfb.tar.gz
PeerTube-f0f5567b6918fc60c8cab15e13aec03a89a91dfb.tar.zst
PeerTube-f0f5567b6918fc60c8cab15e13aec03a89a91dfb.zip
Use const/let now we use node 4.2
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/checkParams.js70
-rw-r--r--server/tests/api/friendsAdvanced.js22
-rw-r--r--server/tests/api/friendsBasic.js36
-rw-r--r--server/tests/api/multiplePods.js46
-rw-r--r--server/tests/api/singlePod.js24
-rw-r--r--server/tests/api/utils.js62
6 files changed, 129 insertions, 131 deletions
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 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var chai = require('chai') 4const chai = require('chai')
5var expect = chai.expect 5const expect = chai.expect
6var pathUtils = require('path') 6const pathUtils = require('path')
7var request = require('supertest') 7const request = require('supertest')
8 8
9var utils = require('./utils') 9const utils = require('./utils')
10 10
11describe('Test parameters validator', function () { 11describe('Test parameters validator', function () {
12 var app = null 12 let app = null
13 var url = '' 13 let url = ''
14 14
15 function makePostRequest (path, fields, attach, done, fail) { 15 function makePostRequest (path, fields, attach, done, fail) {
16 var status_code = 400 16 let status_code = 400
17 if (fail !== undefined && fail === false) status_code = 200 17 if (fail !== undefined && fail === false) status_code = 200
18 18
19 var req = request(url) 19 const req = request(url)
20 .post(path) 20 .post(path)
21 .set('Accept', 'application/json') 21 .set('Accept', 'application/json')
22 22
23 Object.keys(fields).forEach(function (field) { 23 Object.keys(fields).forEach(function (field) {
24 var value = fields[field] 24 const value = fields[field]
25 req.field(field, value) 25 req.field(field, value)
26 }) 26 })
27 27
@@ -29,7 +29,7 @@ describe('Test parameters validator', function () {
29 } 29 }
30 30
31 function makePostBodyRequest (path, fields, done, fail) { 31 function makePostBodyRequest (path, fields, done, fail) {
32 var status_code = 400 32 let status_code = 400
33 if (fail !== undefined && fail === false) status_code = 200 33 if (fail !== undefined && fail === false) status_code = 200
34 34
35 request(url) 35 request(url)
@@ -59,16 +59,16 @@ describe('Test parameters validator', function () {
59 }) 59 })
60 60
61 describe('Of the pods API', function () { 61 describe('Of the pods API', function () {
62 var path = '/api/v1/pods/' 62 const path = '/api/v1/pods/'
63 63
64 describe('When adding a pod', function () { 64 describe('When adding a pod', function () {
65 it('Should fail with nothing', function (done) { 65 it('Should fail with nothing', function (done) {
66 var data = {} 66 const data = {}
67 makePostBodyRequest(path, data, done) 67 makePostBodyRequest(path, data, done)
68 }) 68 })
69 69
70 it('Should fail without public key', function (done) { 70 it('Should fail without public key', function (done) {
71 var data = { 71 const data = {
72 data: { 72 data: {
73 url: 'http://coucou.com' 73 url: 'http://coucou.com'
74 } 74 }
@@ -77,7 +77,7 @@ describe('Test parameters validator', function () {
77 }) 77 })
78 78
79 it('Should fail without an url', function (done) { 79 it('Should fail without an url', function (done) {
80 var data = { 80 const data = {
81 data: { 81 data: {
82 publicKey: 'mysuperpublickey' 82 publicKey: 'mysuperpublickey'
83 } 83 }
@@ -86,7 +86,7 @@ describe('Test parameters validator', function () {
86 }) 86 })
87 87
88 it('Should fail with an incorrect url', function (done) { 88 it('Should fail with an incorrect url', function (done) {
89 var data = { 89 const data = {
90 data: { 90 data: {
91 url: 'coucou.com', 91 url: 'coucou.com',
92 publicKey: 'mysuperpublickey' 92 publicKey: 'mysuperpublickey'
@@ -102,7 +102,7 @@ describe('Test parameters validator', function () {
102 }) 102 })
103 103
104 it('Should succeed with the correct parameters', function (done) { 104 it('Should succeed with the correct parameters', function (done) {
105 var data = { 105 const data = {
106 data: { 106 data: {
107 url: 'http://coucou.com', 107 url: 'http://coucou.com',
108 publicKey: 'mysuperpublickey' 108 publicKey: 'mysuperpublickey'
@@ -114,7 +114,7 @@ describe('Test parameters validator', function () {
114 }) 114 })
115 115
116 describe('Of the videos API', function () { 116 describe('Of the videos API', function () {
117 var path = '/api/v1/videos/' 117 const path = '/api/v1/videos/'
118 118
119 describe('When searching a video', function () { 119 describe('When searching a video', function () {
120 it('Should fail with nothing', function (done) { 120 it('Should fail with nothing', function (done) {
@@ -127,81 +127,81 @@ describe('Test parameters validator', function () {
127 127
128 describe('When adding a video', function () { 128 describe('When adding a video', function () {
129 it('Should fail with nothing', function (done) { 129 it('Should fail with nothing', function (done) {
130 var data = {} 130 const data = {}
131 var attach = {} 131 const attach = {}
132 makePostRequest(path, data, attach, done) 132 makePostRequest(path, data, attach, done)
133 }) 133 })
134 134
135 it('Should fail without name', function (done) { 135 it('Should fail without name', function (done) {
136 var data = { 136 const data = {
137 description: 'my super description' 137 description: 'my super description'
138 } 138 }
139 var attach = { 139 const attach = {
140 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 140 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
141 } 141 }
142 makePostRequest(path, data, attach, done) 142 makePostRequest(path, data, attach, done)
143 }) 143 })
144 144
145 it('Should fail with a long name', function (done) { 145 it('Should fail with a long name', function (done) {
146 var data = { 146 const data = {
147 name: 'My very very very very very very very very very very very very very very very very long name', 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' 148 description: 'my super description'
149 } 149 }
150 var attach = { 150 const attach = {
151 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 151 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
152 } 152 }
153 makePostRequest(path, data, attach, done) 153 makePostRequest(path, data, attach, done)
154 }) 154 })
155 155
156 it('Should fail without description', function (done) { 156 it('Should fail without description', function (done) {
157 var data = { 157 const data = {
158 name: 'my super name' 158 name: 'my super name'
159 } 159 }
160 var attach = { 160 const attach = {
161 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 161 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
162 } 162 }
163 makePostRequest(path, data, attach, done) 163 makePostRequest(path, data, attach, done)
164 }) 164 })
165 165
166 it('Should fail with a long description', function (done) { 166 it('Should fail with a long description', function (done) {
167 var data = { 167 const data = {
168 name: 'my super name', 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' + 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' + 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' 171 'very very very very very very very very very very very very very very very long'
172 } 172 }
173 var attach = { 173 const attach = {
174 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 174 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
175 } 175 }
176 makePostRequest(path, data, attach, done) 176 makePostRequest(path, data, attach, done)
177 }) 177 })
178 178
179 it('Should fail without an input file', function (done) { 179 it('Should fail without an input file', function (done) {
180 var data = { 180 const data = {
181 name: 'my super name', 181 name: 'my super name',
182 description: 'my super description' 182 description: 'my super description'
183 } 183 }
184 var attach = {} 184 const attach = {}
185 makePostRequest(path, data, attach, done) 185 makePostRequest(path, data, attach, done)
186 }) 186 })
187 187
188 it('Should fail without an incorrect input file', function (done) { 188 it('Should fail without an incorrect input file', function (done) {
189 var data = { 189 const data = {
190 name: 'my super name', 190 name: 'my super name',
191 description: 'my super description' 191 description: 'my super description'
192 } 192 }
193 var attach = { 193 const attach = {
194 'input_video': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm') 194 'input_video': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
195 } 195 }
196 makePostRequest(path, data, attach, done) 196 makePostRequest(path, data, attach, done)
197 }) 197 })
198 198
199 it('Should succeed with the correct parameters', function (done) { 199 it('Should succeed with the correct parameters', function (done) {
200 var data = { 200 const data = {
201 name: 'my super name', 201 name: 'my super name',
202 description: 'my super description' 202 description: 'my super description'
203 } 203 }
204 var attach = { 204 const attach = {
205 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 205 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
206 } 206 }
207 makePostRequest(path, data, attach, function () { 207 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 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var chai = require('chai') 4const chai = require('chai')
5var expect = chai.expect 5const expect = chai.expect
6 6
7var utils = require('./utils') 7const utils = require('./utils')
8 8
9describe('Test advanced friends', function () { 9describe('Test advanced friends', function () {
10 var apps = [] 10 let apps = []
11 var urls = [] 11 let urls = []
12 12
13 function makeFriends (pod_number, callback) { 13 function makeFriends (pod_number, callback) {
14 return utils.makeFriends(urls[pod_number - 1], callback) 14 return utils.makeFriends(urls[pod_number - 1], callback)
@@ -23,9 +23,9 @@ describe('Test advanced friends', function () {
23 } 23 }
24 24
25 function uploadVideo (pod_number, callback) { 25 function uploadVideo (pod_number, callback) {
26 var name = 'my super video' 26 const name = 'my super video'
27 var description = 'my super description' 27 const description = 'my super description'
28 var fixture = 'video_short.webm' 28 const fixture = 'video_short.webm'
29 29
30 return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback) 30 return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback)
31 } 31 }
@@ -171,9 +171,9 @@ describe('Test advanced friends', function () {
171 if (err) throw err 171 if (err) throw err
172 172
173 // Pod 4 should not be our friend 173 // Pod 4 should not be our friend
174 var result = res.body 174 const result = res.body
175 expect(result.length).to.equal(3) 175 expect(result.length).to.equal(3)
176 for (var pod of result) { 176 for (const pod of result) {
177 expect(pod.url).not.equal(urls[3]) 177 expect(pod.url).not.equal(urls[3])
178 } 178 }
179 179
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 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var chai = require('chai') 4const chai = require('chai')
5var expect = chai.expect 5const expect = chai.expect
6var request = require('supertest') 6const request = require('supertest')
7 7
8var utils = require('./utils') 8const utils = require('./utils')
9 9
10describe('Test basic friends', function () { 10describe('Test basic friends', function () {
11 var apps = [] 11 let apps = []
12 var urls = [] 12 let urls = []
13 13
14 function testMadeFriends (urls, url_to_test, callback) { 14 function testMadeFriends (urls, url_to_test, callback) {
15 var friends = [] 15 const friends = []
16 for (var i = 0; i < urls.length; i++) { 16 for (let i = 0; i < urls.length; i++) {
17 if (urls[i] === url_to_test) continue 17 if (urls[i] === url_to_test) continue
18 friends.push(urls[i]) 18 friends.push(urls[i])
19 } 19 }
@@ -21,13 +21,13 @@ describe('Test basic friends', function () {
21 utils.getFriendsList(url_to_test, function (err, res) { 21 utils.getFriendsList(url_to_test, function (err, res) {
22 if (err) throw err 22 if (err) throw err
23 23
24 var result = res.body 24 const result = res.body
25 var result_urls = [ result[0].url, result[1].url ] 25 const result_urls = [ result[0].url, result[1].url ]
26 expect(result).to.be.an('array') 26 expect(result).to.be.an('array')
27 expect(result.length).to.equal(2) 27 expect(result.length).to.equal(2)
28 expect(result_urls[0]).to.not.equal(result_urls[1]) 28 expect(result_urls[0]).to.not.equal(result_urls[1])
29 29
30 var error_string = 'Friends url do not correspond for ' + url_to_test 30 const error_string = 'Friends url do not correspond for ' + url_to_test
31 expect(friends).to.contain(result_urls[0], error_string) 31 expect(friends).to.contain(result_urls[0], error_string)
32 expect(friends).to.contain(result_urls[1], error_string) 32 expect(friends).to.contain(result_urls[1], error_string)
33 callback() 33 callback()
@@ -50,7 +50,7 @@ describe('Test basic friends', function () {
50 utils.getFriendsList(url, function (err, res) { 50 utils.getFriendsList(url, function (err, res) {
51 if (err) throw err 51 if (err) throw err
52 52
53 var result = res.body 53 const result = res.body
54 expect(result).to.be.an('array') 54 expect(result).to.be.an('array')
55 expect(result.length).to.equal(0) 55 expect(result.length).to.equal(0)
56 callback() 56 callback()
@@ -61,7 +61,7 @@ describe('Test basic friends', function () {
61 it('Should make friends', function (done) { 61 it('Should make friends', function (done) {
62 this.timeout(10000) 62 this.timeout(10000)
63 63
64 var path = '/api/v1/pods/makefriends' 64 const path = '/api/v1/pods/makefriends'
65 65
66 async.series([ 66 async.series([
67 // The second pod make friend with the third 67 // The second pod make friend with the third
@@ -81,7 +81,7 @@ describe('Test basic friends', function () {
81 utils.getFriendsList(urls[1], function (err, res) { 81 utils.getFriendsList(urls[1], function (err, res) {
82 if (err) throw err 82 if (err) throw err
83 83
84 var result = res.body 84 const result = res.body
85 expect(result).to.be.an('array') 85 expect(result).to.be.an('array')
86 expect(result.length).to.equal(1) 86 expect(result.length).to.equal(1)
87 expect(result[0].url).to.be.equal(urls[2]) 87 expect(result[0].url).to.be.equal(urls[2])
@@ -94,7 +94,7 @@ describe('Test basic friends', function () {
94 utils.getFriendsList(urls[2], function (err, res) { 94 utils.getFriendsList(urls[2], function (err, res) {
95 if (err) throw err 95 if (err) throw err
96 96
97 var result = res.body 97 const result = res.body
98 expect(result).to.be.an('array') 98 expect(result).to.be.an('array')
99 expect(result.length).to.equal(1) 99 expect(result.length).to.equal(1)
100 expect(result[0].url).to.be.equal(urls[1]) 100 expect(result[0].url).to.be.equal(urls[1])
@@ -139,7 +139,7 @@ describe('Test basic friends', function () {
139 utils.getFriendsList(urls[1], function (err, res) { 139 utils.getFriendsList(urls[1], function (err, res) {
140 if (err) throw err 140 if (err) throw err
141 141
142 var result = res.body 142 const result = res.body
143 expect(result).to.be.an('array') 143 expect(result).to.be.an('array')
144 expect(result.length).to.equal(0) 144 expect(result.length).to.equal(0)
145 145
@@ -152,7 +152,7 @@ describe('Test basic friends', function () {
152 utils.getFriendsList(url, function (err, res) { 152 utils.getFriendsList(url, function (err, res) {
153 if (err) throw err 153 if (err) throw err
154 154
155 var result = res.body 155 const result = res.body
156 expect(result).to.be.an('array') 156 expect(result).to.be.an('array')
157 expect(result.length).to.equal(1) 157 expect(result.length).to.equal(1)
158 expect(result[0].url).not.to.be.equal(urls[1]) 158 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 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var chai = require('chai') 4const chai = require('chai')
5var expect = chai.expect 5const expect = chai.expect
6var pathUtils = require('path') 6const pathUtils = require('path')
7 7
8var utils = require('./utils') 8const utils = require('./utils')
9var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) 9const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
10webtorrent.silent = true 10webtorrent.silent = true
11 11
12describe('Test multiple pods', function () { 12describe('Test multiple pods', function () {
13 var apps = [] 13 let apps = []
14 var urls = [] 14 let urls = []
15 var to_remove = [] 15 const to_remove = []
16 16
17 before(function (done) { 17 before(function (done) {
18 this.timeout(30000) 18 this.timeout(30000)
@@ -73,15 +73,15 @@ describe('Test multiple pods', function () {
73 if (err) throw err 73 if (err) throw err
74 74
75 async.each(urls, function (url, callback) { 75 async.each(urls, function (url, callback) {
76 var base_magnet = null 76 let base_magnet = null
77 77
78 utils.getVideosList(url, function (err, res) { 78 utils.getVideosList(url, function (err, res) {
79 if (err) throw err 79 if (err) throw err
80 80
81 var videos = res.body 81 const videos = res.body
82 expect(videos).to.be.an('array') 82 expect(videos).to.be.an('array')
83 expect(videos.length).to.equal(1) 83 expect(videos.length).to.equal(1)
84 var video = videos[0] 84 const video = videos[0]
85 expect(video.name).to.equal('my super name for pod 1') 85 expect(video.name).to.equal('my super name for pod 1')
86 expect(video.description).to.equal('my super description for pod 1') 86 expect(video.description).to.equal('my super description for pod 1')
87 expect(video.podUrl).to.equal('http://localhost:9001') 87 expect(video.podUrl).to.equal('http://localhost:9001')
@@ -116,15 +116,15 @@ describe('Test multiple pods', function () {
116 if (err) throw err 116 if (err) throw err
117 117
118 async.each(urls, function (url, callback) { 118 async.each(urls, function (url, callback) {
119 var base_magnet = null 119 let base_magnet = null
120 120
121 utils.getVideosList(url, function (err, res) { 121 utils.getVideosList(url, function (err, res) {
122 if (err) throw err 122 if (err) throw err
123 123
124 var videos = res.body 124 const videos = res.body
125 expect(videos).to.be.an('array') 125 expect(videos).to.be.an('array')
126 expect(videos.length).to.equal(2) 126 expect(videos.length).to.equal(2)
127 var video = videos[1] 127 const video = videos[1]
128 expect(video.name).to.equal('my super name for pod 2') 128 expect(video.name).to.equal('my super name for pod 2')
129 expect(video.description).to.equal('my super description for pod 2') 129 expect(video.description).to.equal('my super description for pod 2')
130 expect(video.podUrl).to.equal('http://localhost:9002') 130 expect(video.podUrl).to.equal('http://localhost:9002')
@@ -160,16 +160,16 @@ describe('Test multiple pods', function () {
160 function (err) { 160 function (err) {
161 if (err) throw err 161 if (err) throw err
162 162
163 var base_magnet = null 163 let base_magnet = null
164 // All pods should have this video 164 // All pods should have this video
165 async.each(urls, function (url, callback) { 165 async.each(urls, function (url, callback) {
166 utils.getVideosList(url, function (err, res) { 166 utils.getVideosList(url, function (err, res) {
167 if (err) throw err 167 if (err) throw err
168 168
169 var videos = res.body 169 const videos = res.body
170 expect(videos).to.be.an('array') 170 expect(videos).to.be.an('array')
171 expect(videos.length).to.equal(4) 171 expect(videos.length).to.equal(4)
172 var video = videos[2] 172 let video = videos[2]
173 expect(video.name).to.equal('my super name for pod 3') 173 expect(video.name).to.equal('my super name for pod 3')
174 expect(video.description).to.equal('my super description for pod 3') 174 expect(video.description).to.equal('my super description for pod 3')
175 expect(video.podUrl).to.equal('http://localhost:9003') 175 expect(video.podUrl).to.equal('http://localhost:9003')
@@ -204,7 +204,7 @@ describe('Test multiple pods', function () {
204 utils.getVideosList(urls[2], function (err, res) { 204 utils.getVideosList(urls[2], function (err, res) {
205 if (err) throw err 205 if (err) throw err
206 206
207 var video = res.body[0] 207 const video = res.body[0]
208 to_remove.push(res.body[2]._id) 208 to_remove.push(res.body[2]._id)
209 to_remove.push(res.body[3]._id) 209 to_remove.push(res.body[3]._id)
210 210
@@ -225,7 +225,7 @@ describe('Test multiple pods', function () {
225 utils.getVideosList(urls[0], function (err, res) { 225 utils.getVideosList(urls[0], function (err, res) {
226 if (err) throw err 226 if (err) throw err
227 227
228 var video = res.body[1] 228 const video = res.body[1]
229 229
230 webtorrent.add(video.magnetUri, function (torrent) { 230 webtorrent.add(video.magnetUri, function (torrent) {
231 expect(torrent.files).to.exist 231 expect(torrent.files).to.exist
@@ -244,7 +244,7 @@ describe('Test multiple pods', function () {
244 utils.getVideosList(urls[1], function (err, res) { 244 utils.getVideosList(urls[1], function (err, res) {
245 if (err) throw err 245 if (err) throw err
246 246
247 var video = res.body[2] 247 const video = res.body[2]
248 248
249 webtorrent.add(video.magnetUri, function (torrent) { 249 webtorrent.add(video.magnetUri, function (torrent) {
250 expect(torrent.files).to.exist 250 expect(torrent.files).to.exist
@@ -263,7 +263,7 @@ describe('Test multiple pods', function () {
263 utils.getVideosList(urls[0], function (err, res) { 263 utils.getVideosList(urls[0], function (err, res) {
264 if (err) throw err 264 if (err) throw err
265 265
266 var video = res.body[3] 266 const video = res.body[3]
267 267
268 webtorrent.add(video.magnetUri, function (torrent) { 268 webtorrent.add(video.magnetUri, function (torrent) {
269 expect(torrent.files).to.exist 269 expect(torrent.files).to.exist
@@ -297,7 +297,7 @@ describe('Test multiple pods', function () {
297 utils.getVideosList(url, function (err, res) { 297 utils.getVideosList(url, function (err, res) {
298 if (err) throw err 298 if (err) throw err
299 299
300 var videos = res.body 300 const videos = res.body
301 expect(videos).to.be.an('array') 301 expect(videos).to.be.an('array')
302 expect(videos.length).to.equal(2) 302 expect(videos.length).to.equal(2)
303 expect(videos[0]._id).not.to.equal(videos[1]._id) 303 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 @@
1'use strict' 1'use strict'
2 2
3var async = require('async') 3const async = require('async')
4var chai = require('chai') 4const chai = require('chai')
5var expect = chai.expect 5const expect = chai.expect
6var fs = require('fs') 6const fs = require('fs')
7var pathUtils = require('path') 7const pathUtils = require('path')
8 8
9var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) 9const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
10webtorrent.silent = true 10webtorrent.silent = true
11 11
12var utils = require('./utils') 12const utils = require('./utils')
13 13
14describe('Test a single pod', function () { 14describe('Test a single pod', function () {
15 var app = null 15 let app = null
16 var url = '' 16 let url = ''
17 var video_id = -1 17 let video_id = -1
18 18
19 before(function (done) { 19 before(function (done) {
20 this.timeout(20000) 20 this.timeout(20000)
@@ -62,7 +62,7 @@ describe('Test a single pod', function () {
62 expect(res.body).to.be.an('array') 62 expect(res.body).to.be.an('array')
63 expect(res.body.length).to.equal(1) 63 expect(res.body.length).to.equal(1)
64 64
65 var video = res.body[0] 65 const video = res.body[0]
66 expect(video.name).to.equal('my super name') 66 expect(video.name).to.equal('my super name')
67 expect(video.description).to.equal('my super description') 67 expect(video.description).to.equal('my super description')
68 expect(video.podUrl).to.equal('http://localhost:9001') 68 expect(video.podUrl).to.equal('http://localhost:9001')
@@ -87,7 +87,7 @@ describe('Test a single pod', function () {
87 expect(res.body).to.be.an('array') 87 expect(res.body).to.be.an('array')
88 expect(res.body.length).to.equal(1) 88 expect(res.body.length).to.equal(1)
89 89
90 var video = res.body[0] 90 const video = res.body[0]
91 expect(video.name).to.equal('my super name') 91 expect(video.name).to.equal('my super name')
92 expect(video.description).to.equal('my super description') 92 expect(video.description).to.equal('my super description')
93 expect(video.podUrl).to.equal('http://localhost:9001') 93 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 @@
1'use strict' 1'use strict'
2 2
3var child_process = require('child_process') 3const child_process = require('child_process')
4var exec = child_process.exec 4const exec = child_process.exec
5var fork = child_process.fork 5const fork = child_process.fork
6var pathUtils = require('path') 6const pathUtils = require('path')
7var request = require('supertest') 7const request = require('supertest')
8 8
9var testUtils = { 9const testUtils = {
10 flushTests: flushTests, 10 flushTests: flushTests,
11 getFriendsList: getFriendsList, 11 getFriendsList: getFriendsList,
12 getVideosList: getVideosList, 12 getVideosList: getVideosList,
@@ -26,7 +26,7 @@ function flushTests (callback) {
26} 26}
27 27
28function getFriendsList (url, end) { 28function getFriendsList (url, end) {
29 var path = '/api/v1/pods/' 29 const path = '/api/v1/pods/'
30 30
31 request(url) 31 request(url)
32 .get(path) 32 .get(path)
@@ -37,7 +37,7 @@ function getFriendsList (url, end) {
37} 37}
38 38
39function getVideosList (url, end) { 39function getVideosList (url, end) {
40 var path = '/api/v1/videos' 40 const path = '/api/v1/videos'
41 41
42 request(url) 42 request(url)
43 .get(path) 43 .get(path)
@@ -53,7 +53,7 @@ function makeFriends (url, expected_status, callback) {
53 expected_status = 204 53 expected_status = 204
54 } 54 }
55 55
56 var path = '/api/v1/pods/makefriends' 56 const path = '/api/v1/pods/makefriends'
57 57
58 // The first pod make friend with the third 58 // The first pod make friend with the third
59 request(url) 59 request(url)
@@ -69,7 +69,7 @@ function makeFriends (url, expected_status, callback) {
69} 69}
70 70
71function quitFriends (url, callback) { 71function quitFriends (url, callback) {
72 var path = '/api/v1/pods/quitfriends' 72 const path = '/api/v1/pods/quitfriends'
73 73
74 // The first pod make friend with the third 74 // The first pod make friend with the third
75 request(url) 75 request(url)
@@ -85,7 +85,7 @@ function quitFriends (url, callback) {
85} 85}
86 86
87function removeVideo (url, id, end) { 87function removeVideo (url, id, end) {
88 var path = '/api/v1/videos' 88 const path = '/api/v1/videos'
89 89
90 request(url) 90 request(url)
91 .delete(path + '/' + id) 91 .delete(path + '/' + id)
@@ -95,9 +95,9 @@ function removeVideo (url, id, end) {
95} 95}
96 96
97function flushAndRunMultipleServers (total_servers, serversRun) { 97function flushAndRunMultipleServers (total_servers, serversRun) {
98 var apps = [] 98 let apps = []
99 var urls = [] 99 let urls = []
100 var i = 0 100 let i = 0
101 101
102 function anotherServerDone (number, app, url) { 102 function anotherServerDone (number, app, url) {
103 apps[number - 1] = app 103 apps[number - 1] = app
@@ -109,41 +109,39 @@ function flushAndRunMultipleServers (total_servers, serversRun) {
109 } 109 }
110 110
111 flushTests(function () { 111 flushTests(function () {
112 for (var j = 1; j <= total_servers; j++) { 112 for (let j = 1; j <= total_servers; j++) {
113 (function (k) { // TODO: ES6 with let 113 // For the virtual buffer
114 // For the virtual buffer 114 setTimeout(function () {
115 setTimeout(function () { 115 runServer(j, function (app, url) {
116 runServer(k, function (app, url) { 116 anotherServerDone(j, app, url)
117 anotherServerDone(k, app, url) 117 })
118 }) 118 }, 1000 * j)
119 }, 1000 * k)
120 })(j)
121 } 119 }
122 }) 120 })
123} 121}
124 122
125function runServer (number, callback) { 123function runServer (number, callback) {
126 var port = 9000 + number 124 const port = 9000 + number
127 var server_run_string = { 125 const server_run_string = {
128 'Connected to mongodb': false, 126 'Connected to mongodb': false,
129 'Server listening on port': false 127 'Server listening on port': false
130 } 128 }
131 129
132 // Share the environment 130 // Share the environment
133 var env = Object.create(process.env) 131 const env = Object.create(process.env)
134 env.NODE_ENV = 'test' 132 env.NODE_ENV = 'test'
135 env.NODE_APP_INSTANCE = number 133 env.NODE_APP_INSTANCE = number
136 var options = { 134 const options = {
137 silent: true, 135 silent: true,
138 env: env, 136 env: env,
139 detached: true 137 detached: true
140 } 138 }
141 139
142 var app = fork(pathUtils.join(__dirname, '../../../server.js'), [], options) 140 const app = fork(pathUtils.join(__dirname, '../../../server.js'), [], options)
143 app.stdout.on('data', function onStdout (data) { 141 app.stdout.on('data', function onStdout (data) {
144 var dont_continue = false 142 let dont_continue = false
145 // Check if all required sentences are here 143 // Check if all required sentences are here
146 for (var key of Object.keys(server_run_string)) { 144 for (const key of Object.keys(server_run_string)) {
147 if (data.toString().indexOf(key) !== -1) server_run_string[key] = true 145 if (data.toString().indexOf(key) !== -1) server_run_string[key] = true
148 if (server_run_string[key] === false) dont_continue = true 146 if (server_run_string[key] === false) dont_continue = true
149 } 147 }
@@ -157,7 +155,7 @@ function runServer (number, callback) {
157} 155}
158 156
159function searchVideo (url, search, end) { 157function searchVideo (url, search, end) {
160 var path = '/api/v1/videos' 158 const path = '/api/v1/videos'
161 159
162 request(url) 160 request(url)
163 .get(path + '/search/' + search) 161 .get(path + '/search/' + search)
@@ -168,7 +166,7 @@ function searchVideo (url, search, end) {
168} 166}
169 167
170function uploadVideo (url, name, description, fixture, end) { 168function uploadVideo (url, name, description, fixture, end) {
171 var path = '/api/v1/videos' 169 const path = '/api/v1/videos'
172 170
173 request(url) 171 request(url)
174 .post(path) 172 .post(path)