diff options
Diffstat (limited to 'server/tests/api/utils.js')
-rw-r--r-- | server/tests/api/utils.js | 62 |
1 files changed, 30 insertions, 32 deletions
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 | ||
3 | var child_process = require('child_process') | 3 | const child_process = require('child_process') |
4 | var exec = child_process.exec | 4 | const exec = child_process.exec |
5 | var fork = child_process.fork | 5 | const fork = child_process.fork |
6 | var pathUtils = require('path') | 6 | const pathUtils = require('path') |
7 | var request = require('supertest') | 7 | const request = require('supertest') |
8 | 8 | ||
9 | var testUtils = { | 9 | const 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 | ||
28 | function getFriendsList (url, end) { | 28 | function 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 | ||
39 | function getVideosList (url, end) { | 39 | function 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 | ||
71 | function quitFriends (url, callback) { | 71 | function 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 | ||
87 | function removeVideo (url, id, end) { | 87 | function 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 | ||
97 | function flushAndRunMultipleServers (total_servers, serversRun) { | 97 | function 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 | ||
125 | function runServer (number, callback) { | 123 | function 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 | ||
159 | function searchVideo (url, search, end) { | 157 | function 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 | ||
170 | function uploadVideo (url, name, description, fixture, end) { | 168 | function 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) |