diff options
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/checkParams.js | 12 | ||||
-rw-r--r-- | server/tests/api/friendsAdvanced.js | 34 | ||||
-rw-r--r-- | server/tests/api/friendsBasic.js | 20 | ||||
-rw-r--r-- | server/tests/api/multiplePods.js | 50 | ||||
-rw-r--r-- | server/tests/api/singlePod.js | 34 | ||||
-rw-r--r-- | server/tests/api/users.js | 20 | ||||
-rw-r--r-- | server/tests/api/utils.js | 64 |
7 files changed, 117 insertions, 117 deletions
diff --git a/server/tests/api/checkParams.js b/server/tests/api/checkParams.js index 59ee0bfc3..71113fd39 100644 --- a/server/tests/api/checkParams.js +++ b/server/tests/api/checkParams.js | |||
@@ -12,8 +12,8 @@ describe('Test parameters validator', function () { | |||
12 | let server = null | 12 | let server = null |
13 | 13 | ||
14 | function makePostRequest (path, token, fields, attach, done, fail) { | 14 | function makePostRequest (path, token, fields, attach, done, fail) { |
15 | let status_code = 400 | 15 | let statusCode = 400 |
16 | if (fail !== undefined && fail === false) status_code = 200 | 16 | if (fail !== undefined && fail === false) statusCode = 200 |
17 | 17 | ||
18 | const req = request(server.url) | 18 | const req = request(server.url) |
19 | .post(path) | 19 | .post(path) |
@@ -26,18 +26,18 @@ describe('Test parameters validator', function () { | |||
26 | req.field(field, value) | 26 | req.field(field, value) |
27 | }) | 27 | }) |
28 | 28 | ||
29 | req.expect(status_code, done) | 29 | req.expect(statusCode, done) |
30 | } | 30 | } |
31 | 31 | ||
32 | function makePostBodyRequest (path, fields, done, fail) { | 32 | function makePostBodyRequest (path, fields, done, fail) { |
33 | let status_code = 400 | 33 | let statusCode = 400 |
34 | if (fail !== undefined && fail === false) status_code = 200 | 34 | if (fail !== undefined && fail === false) statusCode = 200 |
35 | 35 | ||
36 | request(server.url) | 36 | request(server.url) |
37 | .post(path) | 37 | .post(path) |
38 | .set('Accept', 'application/json') | 38 | .set('Accept', 'application/json') |
39 | .send(fields) | 39 | .send(fields) |
40 | .expect(status_code, done) | 40 | .expect(statusCode, done) |
41 | } | 41 | } |
42 | 42 | ||
43 | // --------------------------------------------------------------- | 43 | // --------------------------------------------------------------- |
diff --git a/server/tests/api/friendsAdvanced.js b/server/tests/api/friendsAdvanced.js index 6f18648d7..833a530dd 100644 --- a/server/tests/api/friendsAdvanced.js +++ b/server/tests/api/friendsAdvanced.js | |||
@@ -9,44 +9,44 @@ const utils = require('./utils') | |||
9 | describe('Test advanced friends', function () { | 9 | describe('Test advanced friends', function () { |
10 | let servers = [] | 10 | let servers = [] |
11 | 11 | ||
12 | function makeFriends (pod_number, callback) { | 12 | function makeFriends (podNumber, callback) { |
13 | return utils.makeFriends(servers[pod_number - 1].url, callback) | 13 | return utils.makeFriends(servers[podNumber - 1].url, callback) |
14 | } | 14 | } |
15 | 15 | ||
16 | function quitFriends (pod_number, callback) { | 16 | function quitFriends (podNumber, callback) { |
17 | return utils.quitFriends(servers[pod_number - 1].url, callback) | 17 | return utils.quitFriends(servers[podNumber - 1].url, callback) |
18 | } | 18 | } |
19 | 19 | ||
20 | function getFriendsList (pod_number, end) { | 20 | function getFriendsList (podNumber, end) { |
21 | return utils.getFriendsList(servers[pod_number - 1].url, end) | 21 | return utils.getFriendsList(servers[podNumber - 1].url, end) |
22 | } | 22 | } |
23 | 23 | ||
24 | function uploadVideo (pod_number, callback) { | 24 | function uploadVideo (podNumber, callback) { |
25 | const name = 'my super video' | 25 | const name = 'my super video' |
26 | const description = 'my super description' | 26 | const description = 'my super description' |
27 | const fixture = 'video_short.webm' | 27 | const fixture = 'video_short.webm' |
28 | const server = servers[pod_number - 1] | 28 | const server = servers[podNumber - 1] |
29 | 29 | ||
30 | return utils.uploadVideo(server.url, server.access_token, name, description, fixture, callback) | 30 | return utils.uploadVideo(server.url, server.access_token, name, description, fixture, callback) |
31 | } | 31 | } |
32 | 32 | ||
33 | function getVideos (pod_number, callback) { | 33 | function getVideos (podNumber, callback) { |
34 | return utils.getVideosList(servers[pod_number - 1].url, callback) | 34 | return utils.getVideosList(servers[podNumber - 1].url, callback) |
35 | } | 35 | } |
36 | 36 | ||
37 | // --------------------------------------------------------------- | 37 | // --------------------------------------------------------------- |
38 | 38 | ||
39 | before(function (done) { | 39 | before(function (done) { |
40 | this.timeout(30000) | 40 | this.timeout(30000) |
41 | utils.flushAndRunMultipleServers(6, function (servers_run, urls_run) { | 41 | utils.flushAndRunMultipleServers(6, function (serversRun, urlsRun) { |
42 | servers = servers_run | 42 | servers = serversRun |
43 | 43 | ||
44 | async.each(servers, function (server, callback_each) { | 44 | async.each(servers, function (server, callbackEach) { |
45 | utils.loginAndGetAccessToken(server, function (err, access_token) { | 45 | utils.loginAndGetAccessToken(server, function (err, accessToken) { |
46 | if (err) return callback_each(err) | 46 | if (err) return callbackEach(err) |
47 | 47 | ||
48 | server.access_token = access_token | 48 | server.accessToken = accessToken |
49 | callback_each() | 49 | callbackEach() |
50 | }) | 50 | }) |
51 | }, done) | 51 | }, done) |
52 | }) | 52 | }) |
diff --git a/server/tests/api/friendsBasic.js b/server/tests/api/friendsBasic.js index 49e51804f..c9e3bc9ad 100644 --- a/server/tests/api/friendsBasic.js +++ b/server/tests/api/friendsBasic.js | |||
@@ -10,25 +10,25 @@ const utils = require('./utils') | |||
10 | describe('Test basic friends', function () { | 10 | describe('Test basic friends', function () { |
11 | let servers = [] | 11 | let servers = [] |
12 | 12 | ||
13 | function testMadeFriends (servers, server_to_test, callback) { | 13 | function testMadeFriends (servers, serverToTest, callback) { |
14 | const friends = [] | 14 | const friends = [] |
15 | for (let i = 0; i < servers.length; i++) { | 15 | for (let i = 0; i < servers.length; i++) { |
16 | if (servers[i].url === server_to_test.url) continue | 16 | if (servers[i].url === serverToTest.url) continue |
17 | friends.push(servers[i].url) | 17 | friends.push(servers[i].url) |
18 | } | 18 | } |
19 | 19 | ||
20 | utils.getFriendsList(server_to_test.url, function (err, res) { | 20 | utils.getFriendsList(serverToTest.url, function (err, res) { |
21 | if (err) throw err | 21 | if (err) throw err |
22 | 22 | ||
23 | const result = res.body | 23 | const result = res.body |
24 | const result_urls = [ result[0].url, result[1].url ] | 24 | const resultUrls = [ result[0].url, result[1].url ] |
25 | expect(result).to.be.an('array') | 25 | expect(result).to.be.an('array') |
26 | expect(result.length).to.equal(2) | 26 | expect(result.length).to.equal(2) |
27 | expect(result_urls[0]).to.not.equal(result_urls[1]) | 27 | expect(resultUrls[0]).to.not.equal(resultUrls[1]) |
28 | 28 | ||
29 | const error_string = 'Friends url do not correspond for ' + server_to_test.url | 29 | const errorString = 'Friends url do not correspond for ' + serverToTest.url |
30 | expect(friends).to.contain(result_urls[0], error_string) | 30 | expect(friends).to.contain(resultUrls[0], errorString) |
31 | expect(friends).to.contain(result_urls[1], error_string) | 31 | expect(friends).to.contain(resultUrls[1], errorString) |
32 | callback() | 32 | callback() |
33 | }) | 33 | }) |
34 | } | 34 | } |
@@ -37,8 +37,8 @@ describe('Test basic friends', function () { | |||
37 | 37 | ||
38 | before(function (done) { | 38 | before(function (done) { |
39 | this.timeout(20000) | 39 | this.timeout(20000) |
40 | utils.flushAndRunMultipleServers(3, function (servers_run, urls_run) { | 40 | utils.flushAndRunMultipleServers(3, function (serversRun, urlsRun) { |
41 | servers = servers_run | 41 | servers = serversRun |
42 | done() | 42 | done() |
43 | }) | 43 | }) |
44 | }) | 44 | }) |
diff --git a/server/tests/api/multiplePods.js b/server/tests/api/multiplePods.js index b361e373b..f1415f6f1 100644 --- a/server/tests/api/multiplePods.js +++ b/server/tests/api/multiplePods.js | |||
@@ -11,7 +11,7 @@ webtorrent.silent = true | |||
11 | 11 | ||
12 | describe('Test multiple pods', function () { | 12 | describe('Test multiple pods', function () { |
13 | let servers = [] | 13 | let servers = [] |
14 | const to_remove = [] | 14 | const toRemove = [] |
15 | 15 | ||
16 | before(function (done) { | 16 | before(function (done) { |
17 | this.timeout(30000) | 17 | this.timeout(30000) |
@@ -19,19 +19,19 @@ describe('Test multiple pods', function () { | |||
19 | async.series([ | 19 | async.series([ |
20 | // Run servers | 20 | // Run servers |
21 | function (next) { | 21 | function (next) { |
22 | utils.flushAndRunMultipleServers(3, function (servers_run) { | 22 | utils.flushAndRunMultipleServers(3, function (serversRun) { |
23 | servers = servers_run | 23 | servers = serversRun |
24 | next() | 24 | next() |
25 | }) | 25 | }) |
26 | }, | 26 | }, |
27 | // Get the access tokens | 27 | // Get the access tokens |
28 | function (next) { | 28 | function (next) { |
29 | async.each(servers, function (server, callback_each) { | 29 | async.each(servers, function (server, callbackEach) { |
30 | utils.loginAndGetAccessToken(server, function (err, access_token) { | 30 | utils.loginAndGetAccessToken(server, function (err, accessToken) { |
31 | if (err) return callback_each(err) | 31 | if (err) return callbackEach(err) |
32 | 32 | ||
33 | server.access_token = access_token | 33 | server.accessToken = accessToken |
34 | callback_each() | 34 | callbackEach() |
35 | }) | 35 | }) |
36 | }, next) | 36 | }, next) |
37 | }, | 37 | }, |
@@ -82,7 +82,7 @@ describe('Test multiple pods', function () { | |||
82 | if (err) throw err | 82 | if (err) throw err |
83 | 83 | ||
84 | async.each(servers, function (server, callback) { | 84 | async.each(servers, function (server, callback) { |
85 | let base_magnet = null | 85 | let baseMagnet = null |
86 | 86 | ||
87 | utils.getVideosList(server.url, function (err, res) { | 87 | utils.getVideosList(server.url, function (err, res) { |
88 | if (err) throw err | 88 | if (err) throw err |
@@ -104,8 +104,8 @@ describe('Test multiple pods', function () { | |||
104 | } | 104 | } |
105 | 105 | ||
106 | // All pods should have the same magnet Uri | 106 | // All pods should have the same magnet Uri |
107 | if (base_magnet === null) { | 107 | if (baseMagnet === null) { |
108 | base_magnet = video.magnetUri | 108 | baseMagnet = video.magnetUri |
109 | } else { | 109 | } else { |
110 | expect(video.magnetUri).to.equal.magnetUri | 110 | expect(video.magnetUri).to.equal.magnetUri |
111 | } | 111 | } |
@@ -137,7 +137,7 @@ describe('Test multiple pods', function () { | |||
137 | if (err) throw err | 137 | if (err) throw err |
138 | 138 | ||
139 | async.each(servers, function (server, callback) { | 139 | async.each(servers, function (server, callback) { |
140 | let base_magnet = null | 140 | let baseMagnet = null |
141 | 141 | ||
142 | utils.getVideosList(server.url, function (err, res) { | 142 | utils.getVideosList(server.url, function (err, res) { |
143 | if (err) throw err | 143 | if (err) throw err |
@@ -159,8 +159,8 @@ describe('Test multiple pods', function () { | |||
159 | } | 159 | } |
160 | 160 | ||
161 | // All pods should have the same magnet Uri | 161 | // All pods should have the same magnet Uri |
162 | if (base_magnet === null) { | 162 | if (baseMagnet === null) { |
163 | base_magnet = video.magnetUri | 163 | baseMagnet = video.magnetUri |
164 | } else { | 164 | } else { |
165 | expect(video.magnetUri).to.equal.magnetUri | 165 | expect(video.magnetUri).to.equal.magnetUri |
166 | } | 166 | } |
@@ -193,7 +193,7 @@ describe('Test multiple pods', function () { | |||
193 | function (err) { | 193 | function (err) { |
194 | if (err) throw err | 194 | if (err) throw err |
195 | 195 | ||
196 | let base_magnet = null | 196 | let baseMagnet = null |
197 | // All pods should have this video | 197 | // All pods should have this video |
198 | async.each(servers, function (server, callback) { | 198 | async.each(servers, function (server, callback) { |
199 | utils.getVideosList(server.url, function (err, res) { | 199 | utils.getVideosList(server.url, function (err, res) { |
@@ -235,8 +235,8 @@ describe('Test multiple pods', function () { | |||
235 | } | 235 | } |
236 | 236 | ||
237 | // All pods should have the same magnet Uri | 237 | // All pods should have the same magnet Uri |
238 | if (base_magnet === null) { | 238 | if (baseMagnet === null) { |
239 | base_magnet = video2.magnetUri | 239 | baseMagnet = video2.magnetUri |
240 | } else { | 240 | } else { |
241 | expect(video2.magnetUri).to.equal.magnetUri | 241 | expect(video2.magnetUri).to.equal.magnetUri |
242 | } | 242 | } |
@@ -268,8 +268,8 @@ describe('Test multiple pods', function () { | |||
268 | if (err) throw err | 268 | if (err) throw err |
269 | 269 | ||
270 | const video = res.body[0] | 270 | const video = res.body[0] |
271 | to_remove.push(res.body[2].id) | 271 | toRemove.push(res.body[2].id) |
272 | to_remove.push(res.body[3].id) | 272 | toRemove.push(res.body[3].id) |
273 | 273 | ||
274 | webtorrent.add(video.magnetUri, function (torrent) { | 274 | webtorrent.add(video.magnetUri, function (torrent) { |
275 | expect(torrent.files).to.exist | 275 | expect(torrent.files).to.exist |
@@ -343,10 +343,10 @@ describe('Test multiple pods', function () { | |||
343 | 343 | ||
344 | async.series([ | 344 | async.series([ |
345 | function (next) { | 345 | function (next) { |
346 | utils.removeVideo(servers[2].url, servers[2].access_token, to_remove[0], next) | 346 | utils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[0], next) |
347 | }, | 347 | }, |
348 | function (next) { | 348 | function (next) { |
349 | utils.removeVideo(servers[2].url, servers[2].access_token, to_remove[1], next) | 349 | utils.removeVideo(servers[2].url, servers[2].accessToken, toRemove[1], next) |
350 | }], | 350 | }], |
351 | function (err) { | 351 | function (err) { |
352 | if (err) throw err | 352 | if (err) throw err |
@@ -364,10 +364,10 @@ describe('Test multiple pods', function () { | |||
364 | expect(videos).to.be.an('array') | 364 | expect(videos).to.be.an('array') |
365 | expect(videos.length).to.equal(2) | 365 | expect(videos.length).to.equal(2) |
366 | expect(videos[0].id).not.to.equal(videos[1].id) | 366 | expect(videos[0].id).not.to.equal(videos[1].id) |
367 | expect(videos[0].id).not.to.equal(to_remove[0]) | 367 | expect(videos[0].id).not.to.equal(toRemove[0]) |
368 | expect(videos[1].id).not.to.equal(to_remove[0]) | 368 | expect(videos[1].id).not.to.equal(toRemove[0]) |
369 | expect(videos[0].id).not.to.equal(to_remove[1]) | 369 | expect(videos[0].id).not.to.equal(toRemove[1]) |
370 | expect(videos[1].id).not.to.equal(to_remove[1]) | 370 | expect(videos[1].id).not.to.equal(toRemove[1]) |
371 | 371 | ||
372 | callback() | 372 | callback() |
373 | }) | 373 | }) |
diff --git a/server/tests/api/singlePod.js b/server/tests/api/singlePod.js index e8b578770..542dea430 100644 --- a/server/tests/api/singlePod.js +++ b/server/tests/api/singlePod.js | |||
@@ -14,7 +14,7 @@ const utils = require('./utils') | |||
14 | 14 | ||
15 | describe('Test a single pod', function () { | 15 | describe('Test a single pod', function () { |
16 | let server = null | 16 | let server = null |
17 | let video_id = -1 | 17 | let videoId = -1 |
18 | 18 | ||
19 | before(function (done) { | 19 | before(function (done) { |
20 | this.timeout(20000) | 20 | this.timeout(20000) |
@@ -80,7 +80,7 @@ describe('Test a single pod', function () { | |||
80 | if (err) throw err | 80 | if (err) throw err |
81 | expect(test).to.equal(true) | 81 | expect(test).to.equal(true) |
82 | 82 | ||
83 | video_id = video.id | 83 | videoId = video.id |
84 | 84 | ||
85 | webtorrent.add(video.magnetUri, function (torrent) { | 85 | webtorrent.add(video.magnetUri, function (torrent) { |
86 | expect(torrent.files).to.exist | 86 | expect(torrent.files).to.exist |
@@ -97,7 +97,7 @@ describe('Test a single pod', function () { | |||
97 | // Yes, this could be long | 97 | // Yes, this could be long |
98 | this.timeout(60000) | 98 | this.timeout(60000) |
99 | 99 | ||
100 | utils.getVideo(server.url, video_id, function (err, res) { | 100 | utils.getVideo(server.url, videoId, function (err, res) { |
101 | if (err) throw err | 101 | if (err) throw err |
102 | 102 | ||
103 | const video = res.body | 103 | const video = res.body |
@@ -158,7 +158,7 @@ describe('Test a single pod', function () { | |||
158 | }) | 158 | }) |
159 | 159 | ||
160 | it('Should remove the video', function (done) { | 160 | it('Should remove the video', function (done) { |
161 | utils.removeVideo(server.url, server.access_token, video_id, function (err) { | 161 | utils.removeVideo(server.url, server.accessToken, videoId, function (err) { |
162 | if (err) throw err | 162 | if (err) throw err |
163 | 163 | ||
164 | fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) { | 164 | fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) { |
@@ -187,8 +187,8 @@ describe('Test a single pod', function () { | |||
187 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', | 187 | 'video_short.mp4', 'video_short.ogv', 'video_short.webm', |
188 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' | 188 | 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' |
189 | ] | 189 | ] |
190 | async.each(videos, function (video, callback_each) { | 190 | async.each(videos, function (video, callbackEach) { |
191 | utils.uploadVideo(server.url, server.access_token, video + ' name', video + ' description', video, callback_each) | 191 | utils.uploadVideo(server.url, server.accessToken, video + ' name', video + ' description', video, callbackEach) |
192 | }, done) | 192 | }, done) |
193 | }) | 193 | }) |
194 | 194 | ||
@@ -200,13 +200,13 @@ describe('Test a single pod', function () { | |||
200 | expect(videos).to.be.an('array') | 200 | expect(videos).to.be.an('array') |
201 | expect(videos.length).to.equal(6) | 201 | expect(videos.length).to.equal(6) |
202 | 202 | ||
203 | const videos_by_name = keyBy(videos, 'name') | 203 | const videosByName = keyBy(videos, 'name') |
204 | expect(videos_by_name['video_short.mp4 name'].duration).to.equal(5) | 204 | expect(videosByName['video_short.mp4 name'].duration).to.equal(5) |
205 | expect(videos_by_name['video_short.ogv name'].duration).to.equal(5) | 205 | expect(videosByName['video_short.ogv name'].duration).to.equal(5) |
206 | expect(videos_by_name['video_short.webm name'].duration).to.equal(5) | 206 | expect(videosByName['video_short.webm name'].duration).to.equal(5) |
207 | expect(videos_by_name['video_short1.webm name'].duration).to.equal(10) | 207 | expect(videosByName['video_short1.webm name'].duration).to.equal(10) |
208 | expect(videos_by_name['video_short2.webm name'].duration).to.equal(5) | 208 | expect(videosByName['video_short2.webm name'].duration).to.equal(5) |
209 | expect(videos_by_name['video_short3.webm name'].duration).to.equal(5) | 209 | expect(videosByName['video_short3.webm name'].duration).to.equal(5) |
210 | 210 | ||
211 | done() | 211 | done() |
212 | }) | 212 | }) |
@@ -216,15 +216,15 @@ describe('Test a single pod', function () { | |||
216 | utils.getVideosList(server.url, function (err, res) { | 216 | utils.getVideosList(server.url, function (err, res) { |
217 | const videos = res.body | 217 | const videos = res.body |
218 | 218 | ||
219 | async.each(videos, function (video, callback_each) { | 219 | async.each(videos, function (video, callbackEach) { |
220 | if (err) throw err | 220 | if (err) throw err |
221 | const video_name = video.name.replace(' name', '') | 221 | const videoName = video.name.replace(' name', '') |
222 | 222 | ||
223 | utils.testImage(server.url, video_name, video.thumbnailPath, function (err, test) { | 223 | utils.testImage(server.url, videoName, video.thumbnailPath, function (err, test) { |
224 | if (err) throw err | 224 | if (err) throw err |
225 | 225 | ||
226 | expect(test).to.equal(true) | 226 | expect(test).to.equal(true) |
227 | callback_each() | 227 | callbackEach() |
228 | }) | 228 | }) |
229 | }, done) | 229 | }, done) |
230 | }) | 230 | }) |
diff --git a/server/tests/api/users.js b/server/tests/api/users.js index e5395a79f..57417a69e 100644 --- a/server/tests/api/users.js +++ b/server/tests/api/users.js | |||
@@ -12,8 +12,8 @@ const utils = require('./utils') | |||
12 | 12 | ||
13 | describe('Test users', function () { | 13 | describe('Test users', function () { |
14 | let server = null | 14 | let server = null |
15 | let access_token = null | 15 | let accessToken = null |
16 | let video_id | 16 | let videoId |
17 | 17 | ||
18 | before(function (done) { | 18 | before(function (done) { |
19 | this.timeout(20000) | 19 | this.timeout(20000) |
@@ -78,21 +78,21 @@ describe('Test users', function () { | |||
78 | }) | 78 | }) |
79 | 79 | ||
80 | it('Should not be able to upload a video', function (done) { | 80 | it('Should not be able to upload a video', function (done) { |
81 | access_token = 'mysupertoken' | 81 | accessToken = 'mysupertoken' |
82 | utils.uploadVideo(server.url, access_token, 'my super name', 'my super description', 'video_short.webm', 401, done) | 82 | utils.uploadVideo(server.url, accessToken, 'my super name', 'my super description', 'video_short.webm', 401, done) |
83 | }) | 83 | }) |
84 | 84 | ||
85 | it('Should be able to login', function (done) { | 85 | it('Should be able to login', function (done) { |
86 | utils.login(server.url, server.client, server.user, 200, function (err, res) { | 86 | utils.login(server.url, server.client, server.user, 200, function (err, res) { |
87 | if (err) throw err | 87 | if (err) throw err |
88 | 88 | ||
89 | access_token = res.body.access_token | 89 | accessToken = res.body.access_token |
90 | done() | 90 | done() |
91 | }) | 91 | }) |
92 | }) | 92 | }) |
93 | 93 | ||
94 | it('Should upload the video with the correct token', function (done) { | 94 | it('Should upload the video with the correct token', function (done) { |
95 | utils.uploadVideo(server.url, access_token, 'my super name', 'my super description', 'video_short.webm', 204, function (err, res) { | 95 | utils.uploadVideo(server.url, accessToken, 'my super name', 'my super description', 'video_short.webm', 204, function (err, res) { |
96 | if (err) throw err | 96 | if (err) throw err |
97 | 97 | ||
98 | utils.getVideosList(server.url, function (err, res) { | 98 | utils.getVideosList(server.url, function (err, res) { |
@@ -101,24 +101,24 @@ describe('Test users', function () { | |||
101 | const video = res.body[0] | 101 | const video = res.body[0] |
102 | expect(video.author).to.equal('root') | 102 | expect(video.author).to.equal('root') |
103 | 103 | ||
104 | video_id = video.id | 104 | videoId = video.id |
105 | done() | 105 | done() |
106 | }) | 106 | }) |
107 | }) | 107 | }) |
108 | }) | 108 | }) |
109 | 109 | ||
110 | it('Should upload the video again with the correct token', function (done) { | 110 | it('Should upload the video again with the correct token', function (done) { |
111 | utils.uploadVideo(server.url, access_token, 'my super name 2', 'my super description 2', 'video_short.webm', 204, done) | 111 | utils.uploadVideo(server.url, accessToken, 'my super name 2', 'my super description 2', 'video_short.webm', 204, done) |
112 | }) | 112 | }) |
113 | 113 | ||
114 | it('Should not be able to remove the video with an incorrect token', function (done) { | 114 | it('Should not be able to remove the video with an incorrect token', function (done) { |
115 | utils.removeVideo(server.url, 'bad_token', video_id, 401, done) | 115 | utils.removeVideo(server.url, 'bad_token', videoId, 401, done) |
116 | }) | 116 | }) |
117 | 117 | ||
118 | it('Should not be able to remove the video with the token of another account') | 118 | it('Should not be able to remove the video with the token of another account') |
119 | 119 | ||
120 | it('Should be able to remove the video with the correct token', function (done) { | 120 | it('Should be able to remove the video with the correct token', function (done) { |
121 | utils.removeVideo(server.url, access_token, video_id, done) | 121 | utils.removeVideo(server.url, accessToken, videoId, done) |
122 | }) | 122 | }) |
123 | 123 | ||
124 | it('Should logout') | 124 | it('Should logout') |
diff --git a/server/tests/api/utils.js b/server/tests/api/utils.js index 3d3169fde..45f11ac8f 100644 --- a/server/tests/api/utils.js +++ b/server/tests/api/utils.js | |||
@@ -1,8 +1,8 @@ | |||
1 | 'use strict' | 1 | 'use strict' |
2 | 2 | ||
3 | const child_process = require('child_process') | 3 | const childProcess = require('child_process') |
4 | const exec = child_process.exec | 4 | const exec = childProcess.exec |
5 | const fork = child_process.fork | 5 | const fork = childProcess.fork |
6 | const fs = require('fs') | 6 | const fs = require('fs') |
7 | const pathUtils = require('path') | 7 | const pathUtils = require('path') |
8 | const request = require('supertest') | 8 | const request = require('supertest') |
@@ -63,10 +63,10 @@ function getVideosList (url, end) { | |||
63 | .end(end) | 63 | .end(end) |
64 | } | 64 | } |
65 | 65 | ||
66 | function login (url, client, user, expected_status, end) { | 66 | function login (url, client, user, expectedStatus, end) { |
67 | if (!end) { | 67 | if (!end) { |
68 | end = expected_status | 68 | end = expectedStatus |
69 | expected_status = 200 | 69 | expectedStatus = 200 |
70 | } | 70 | } |
71 | 71 | ||
72 | const path = '/api/v1/users/token' | 72 | const path = '/api/v1/users/token' |
@@ -85,7 +85,7 @@ function login (url, client, user, expected_status, end) { | |||
85 | .post(path) | 85 | .post(path) |
86 | .type('form') | 86 | .type('form') |
87 | .send(body) | 87 | .send(body) |
88 | .expect(expected_status) | 88 | .expect(expectedStatus) |
89 | .end(end) | 89 | .end(end) |
90 | } | 90 | } |
91 | 91 | ||
@@ -97,10 +97,10 @@ function loginAndGetAccessToken (server, callback) { | |||
97 | }) | 97 | }) |
98 | } | 98 | } |
99 | 99 | ||
100 | function makeFriends (url, expected_status, callback) { | 100 | function makeFriends (url, expectedStatus, callback) { |
101 | if (!callback) { | 101 | if (!callback) { |
102 | callback = expected_status | 102 | callback = expectedStatus |
103 | expected_status = 204 | 103 | expectedStatus = 204 |
104 | } | 104 | } |
105 | 105 | ||
106 | const path = '/api/v1/pods/makefriends' | 106 | const path = '/api/v1/pods/makefriends' |
@@ -109,7 +109,7 @@ function makeFriends (url, expected_status, callback) { | |||
109 | request(url) | 109 | request(url) |
110 | .get(path) | 110 | .get(path) |
111 | .set('Accept', 'application/json') | 111 | .set('Accept', 'application/json') |
112 | .expect(expected_status) | 112 | .expect(expectedStatus) |
113 | .end(function (err, res) { | 113 | .end(function (err, res) { |
114 | if (err) throw err | 114 | if (err) throw err |
115 | 115 | ||
@@ -134,10 +134,10 @@ function quitFriends (url, callback) { | |||
134 | }) | 134 | }) |
135 | } | 135 | } |
136 | 136 | ||
137 | function removeVideo (url, token, id, expected_status, end) { | 137 | function removeVideo (url, token, id, expectedStatus, end) { |
138 | if (!end) { | 138 | if (!end) { |
139 | end = expected_status | 139 | end = expectedStatus |
140 | expected_status = 204 | 140 | expectedStatus = 204 |
141 | } | 141 | } |
142 | 142 | ||
143 | const path = '/api/v1/videos' | 143 | const path = '/api/v1/videos' |
@@ -146,11 +146,11 @@ function removeVideo (url, token, id, expected_status, end) { | |||
146 | .delete(path + '/' + id) | 146 | .delete(path + '/' + id) |
147 | .set('Accept', 'application/json') | 147 | .set('Accept', 'application/json') |
148 | .set('Authorization', 'Bearer ' + token) | 148 | .set('Authorization', 'Bearer ' + token) |
149 | .expect(expected_status) | 149 | .expect(expectedStatus) |
150 | .end(end) | 150 | .end(end) |
151 | } | 151 | } |
152 | 152 | ||
153 | function flushAndRunMultipleServers (total_servers, serversRun) { | 153 | function flushAndRunMultipleServers (totalServers, serversRun) { |
154 | let apps = [] | 154 | let apps = [] |
155 | let urls = [] | 155 | let urls = [] |
156 | let i = 0 | 156 | let i = 0 |
@@ -159,13 +159,13 @@ function flushAndRunMultipleServers (total_servers, serversRun) { | |||
159 | apps[number - 1] = app | 159 | apps[number - 1] = app |
160 | urls[number - 1] = url | 160 | urls[number - 1] = url |
161 | i++ | 161 | i++ |
162 | if (i === total_servers) { | 162 | if (i === totalServers) { |
163 | serversRun(apps, urls) | 163 | serversRun(apps, urls) |
164 | } | 164 | } |
165 | } | 165 | } |
166 | 166 | ||
167 | flushTests(function () { | 167 | flushTests(function () { |
168 | for (let j = 1; j <= total_servers; j++) { | 168 | for (let j = 1; j <= totalServers; j++) { |
169 | // For the virtual buffer | 169 | // For the virtual buffer |
170 | setTimeout(function () { | 170 | setTimeout(function () { |
171 | runServer(j, function (app, url) { | 171 | runServer(j, function (app, url) { |
@@ -191,7 +191,7 @@ function runServer (number, callback) { | |||
191 | } | 191 | } |
192 | 192 | ||
193 | // These actions are async so we need to be sure that they have both been done | 193 | // These actions are async so we need to be sure that they have both been done |
194 | const server_run_string = { | 194 | const serverRunString = { |
195 | 'Connected to mongodb': false, | 195 | 'Connected to mongodb': false, |
196 | 'Server listening on port': false | 196 | 'Server listening on port': false |
197 | } | 197 | } |
@@ -215,7 +215,7 @@ function runServer (number, callback) { | |||
215 | 215 | ||
216 | server.app = fork(pathUtils.join(__dirname, '../../../server.js'), [], options) | 216 | server.app = fork(pathUtils.join(__dirname, '../../../server.js'), [], options) |
217 | server.app.stdout.on('data', function onStdout (data) { | 217 | server.app.stdout.on('data', function onStdout (data) { |
218 | let dont_continue = false | 218 | let dontContinue = false |
219 | 219 | ||
220 | // Capture things if we want to | 220 | // Capture things if we want to |
221 | for (const key of Object.keys(regexps)) { | 221 | for (const key of Object.keys(regexps)) { |
@@ -230,13 +230,13 @@ function runServer (number, callback) { | |||
230 | } | 230 | } |
231 | 231 | ||
232 | // Check if all required sentences are here | 232 | // Check if all required sentences are here |
233 | for (const key of Object.keys(server_run_string)) { | 233 | for (const key of Object.keys(serverRunString)) { |
234 | if (data.toString().indexOf(key) !== -1) server_run_string[key] = true | 234 | if (data.toString().indexOf(key) !== -1) serverRunString[key] = true |
235 | if (server_run_string[key] === false) dont_continue = true | 235 | if (serverRunString[key] === false) dontContinue = true |
236 | } | 236 | } |
237 | 237 | ||
238 | // If no, there is maybe one thing not already initialized (mongodb...) | 238 | // If no, there is maybe one thing not already initialized (mongodb...) |
239 | if (dont_continue === true) return | 239 | if (dontContinue === true) return |
240 | 240 | ||
241 | server.app.stdout.removeListener('data', onStdout) | 241 | server.app.stdout.removeListener('data', onStdout) |
242 | callback(server) | 242 | callback(server) |
@@ -254,14 +254,14 @@ function searchVideo (url, search, end) { | |||
254 | .end(end) | 254 | .end(end) |
255 | } | 255 | } |
256 | 256 | ||
257 | function testImage (url, video_name, image_path, callback) { | 257 | function testImage (url, videoName, imagePath, callback) { |
258 | request(url) | 258 | request(url) |
259 | .get(image_path) | 259 | .get(imagePath) |
260 | .expect(200) | 260 | .expect(200) |
261 | .end(function (err, res) { | 261 | .end(function (err, res) { |
262 | if (err) return callback(err) | 262 | if (err) return callback(err) |
263 | 263 | ||
264 | fs.readFile(pathUtils.join(__dirname, 'fixtures', video_name + '.jpg'), function (err, data) { | 264 | fs.readFile(pathUtils.join(__dirname, 'fixtures', videoName + '.jpg'), function (err, data) { |
265 | if (err) return callback(err) | 265 | if (err) return callback(err) |
266 | 266 | ||
267 | callback(null, data.equals(res.body)) | 267 | callback(null, data.equals(res.body)) |
@@ -269,10 +269,10 @@ function testImage (url, video_name, image_path, callback) { | |||
269 | }) | 269 | }) |
270 | } | 270 | } |
271 | 271 | ||
272 | function uploadVideo (url, access_token, name, description, fixture, special_status, end) { | 272 | function uploadVideo (url, accessToken, name, description, fixture, specialStatus, end) { |
273 | if (!end) { | 273 | if (!end) { |
274 | end = special_status | 274 | end = specialStatus |
275 | special_status = 204 | 275 | specialStatus = 204 |
276 | } | 276 | } |
277 | 277 | ||
278 | const path = '/api/v1/videos' | 278 | const path = '/api/v1/videos' |
@@ -280,11 +280,11 @@ function uploadVideo (url, access_token, name, description, fixture, special_sta | |||
280 | request(url) | 280 | request(url) |
281 | .post(path) | 281 | .post(path) |
282 | .set('Accept', 'application/json') | 282 | .set('Accept', 'application/json') |
283 | .set('Authorization', 'Bearer ' + access_token) | 283 | .set('Authorization', 'Bearer ' + accessToken) |
284 | .field('name', name) | 284 | .field('name', name) |
285 | .field('description', description) | 285 | .field('description', description) |
286 | .attach('videofile', pathUtils.join(__dirname, 'fixtures', fixture)) | 286 | .attach('videofile', pathUtils.join(__dirname, 'fixtures', fixture)) |
287 | .expect(special_status) | 287 | .expect(specialStatus) |
288 | .end(end) | 288 | .end(end) |
289 | } | 289 | } |
290 | 290 | ||