aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'tests/api')
-rw-r--r--tests/api/checkParams.js490
-rw-r--r--tests/api/friendsAdvanced.js424
-rw-r--r--tests/api/friendsBasic.js300
-rw-r--r--tests/api/index.js16
-rw-r--r--tests/api/multiplePods.js544
-rw-r--r--tests/api/singlePod.js224
-rw-r--r--tests/api/utils.js340
7 files changed, 1162 insertions, 1176 deletions
diff --git a/tests/api/checkParams.js b/tests/api/checkParams.js
index 8ce1bd476..1c1ec71b3 100644
--- a/tests/api/checkParams.js
+++ b/tests/api/checkParams.js
@@ -1,302 +1,300 @@
1;(function () { 1'use strict'
2 'use strict'
3 2
4 var async = require('async') 3var async = require('async')
5 var chai = require('chai') 4var chai = require('chai')
6 var expect = chai.expect 5var expect = chai.expect
7 var pathUtils = require('path') 6var pathUtils = require('path')
8 var request = require('supertest') 7var request = require('supertest')
9 8
10 var utils = require('./utils') 9var utils = require('./utils')
11 10
12 describe('Test parameters validator', function () { 11describe('Test parameters validator', function () {
13 var app = null 12 var app = null
14 var url = '' 13 var url = ''
15 14
16 function makePostRequest (path, fields, attach, done, fail) { 15 function makePostRequest (path, fields, attach, done, fail) {
17 var status_code = 400 16 var status_code = 400
18 if (fail !== undefined && fail === false) status_code = 200 17 if (fail !== undefined && fail === false) status_code = 200
19 18
20 var req = request(url) 19 var req = request(url)
21 .post(path) 20 .post(path)
22 .set('Accept', 'application/json') 21 .set('Accept', 'application/json')
23 22
24 Object.keys(fields).forEach(function (field) { 23 Object.keys(fields).forEach(function (field) {
25 var value = fields[field] 24 var value = fields[field]
26 req.field(field, value) 25 req.field(field, value)
27 })
28
29 req.expect(status_code, done)
30 }
31
32 function makePostBodyRequest (path, fields, done, fail) {
33 var status_code = 400
34 if (fail !== undefined && fail === false) status_code = 200
35
36 request(url)
37 .post(path)
38 .set('Accept', 'application/json')
39 .send(fields)
40 .expect(status_code, done)
41 }
42
43 // ---------------------------------------------------------------
44
45 before(function (done) {
46 this.timeout(20000)
47
48 async.series([
49 function (next) {
50 utils.flushTests(next)
51 },
52 function (next) {
53 utils.runServer(1, function (app1, url1) {
54 app = app1
55 url = url1
56 next()
57 })
58 }
59 ], done)
60 }) 26 })
61 27
62 describe('Of the pods API', function () { 28 req.expect(status_code, done)
63 var path = '/api/v1/pods/' 29 }
64 30
65 describe('When adding a pod', function () { 31 function makePostBodyRequest (path, fields, done, fail) {
66 it('Should fail with nothing', function (done) { 32 var status_code = 400
67 var data = {} 33 if (fail !== undefined && fail === false) status_code = 200
68 makePostBodyRequest(path, data, done) 34
35 request(url)
36 .post(path)
37 .set('Accept', 'application/json')
38 .send(fields)
39 .expect(status_code, done)
40 }
41
42 // ---------------------------------------------------------------
43
44 before(function (done) {
45 this.timeout(20000)
46
47 async.series([
48 function (next) {
49 utils.flushTests(next)
50 },
51 function (next) {
52 utils.runServer(1, function (app1, url1) {
53 app = app1
54 url = url1
55 next()
69 }) 56 })
57 }
58 ], done)
59 })
60
61 describe('Of the pods API', function () {
62 var path = '/api/v1/pods/'
63
64 describe('When adding a pod', function () {
65 it('Should fail with nothing', function (done) {
66 var data = {}
67 makePostBodyRequest(path, data, done)
68 })
70 69
71 it('Should fail without public key', function (done) { 70 it('Should fail without public key', function (done) {
72 var data = { 71 var data = {
73 data: { 72 data: {
74 url: 'http://coucou.com' 73 url: 'http://coucou.com'
75 }
76 } 74 }
77 makePostBodyRequest(path, data, done) 75 }
78 }) 76 makePostBodyRequest(path, data, done)
77 })
79 78
80 it('Should fail without an url', function (done) { 79 it('Should fail without an url', function (done) {
81 var data = { 80 var data = {
82 data: { 81 data: {
83 publicKey: 'mysuperpublickey' 82 publicKey: 'mysuperpublickey'
84 }
85 } 83 }
86 makePostBodyRequest(path, data, done) 84 }
87 }) 85 makePostBodyRequest(path, data, done)
86 })
88 87
89 it('Should fail with an incorrect url', function (done) { 88 it('Should fail with an incorrect url', function (done) {
90 var data = { 89 var data = {
91 data: { 90 data: {
92 url: 'coucou.com', 91 url: 'coucou.com',
93 publicKey: 'mysuperpublickey' 92 publicKey: 'mysuperpublickey'
94 }
95 } 93 }
94 }
95 makePostBodyRequest(path, data, function () {
96 data.data.url = 'http://coucou'
96 makePostBodyRequest(path, data, function () { 97 makePostBodyRequest(path, data, function () {
97 data.data.url = 'http://coucou' 98 data.data.url = 'coucou'
98 makePostBodyRequest(path, data, function () { 99 makePostBodyRequest(path, data, done)
99 data.data.url = 'coucou'
100 makePostBodyRequest(path, data, done)
101 })
102 }) 100 })
103 }) 101 })
102 })
104 103
105 it('Should succeed with the correct parameters', function (done) { 104 it('Should succeed with the correct parameters', function (done) {
106 var data = { 105 var data = {
107 data: { 106 data: {
108 url: 'http://coucou.com', 107 url: 'http://coucou.com',
109 publicKey: 'mysuperpublickey' 108 publicKey: 'mysuperpublickey'
110 }
111 } 109 }
112 makePostBodyRequest(path, data, done, false) 110 }
113 }) 111 makePostBodyRequest(path, data, done, false)
114 }) 112 })
115 }) 113 })
114 })
116 115
117 describe('Of the videos API', function () { 116 describe('Of the videos API', function () {
118 var path = '/api/v1/videos/' 117 var path = '/api/v1/videos/'
119 118
120 describe('When searching a video', function () { 119 describe('When searching a video', function () {
121 it('Should fail with nothing', function (done) { 120 it('Should fail with nothing', function (done) {
122 request(url) 121 request(url)
123 .get(pathUtils.join(path, 'search')) 122 .get(pathUtils.join(path, 'search'))
124 .set('Accept', 'application/json') 123 .set('Accept', 'application/json')
125 .expect(400, done) 124 .expect(400, done)
126 })
127 }) 125 })
126 })
128 127
129 describe('When adding a video', function () { 128 describe('When adding a video', function () {
130 it('Should fail with nothing', function (done) { 129 it('Should fail with nothing', function (done) {
131 var data = {} 130 var data = {}
132 var attach = {} 131 var attach = {}
133 makePostRequest(path, data, attach, done) 132 makePostRequest(path, data, attach, done)
134 }) 133 })
135 134
136 it('Should fail without name', function (done) { 135 it('Should fail without name', function (done) {
137 var data = { 136 var data = {
138 description: 'my super description' 137 description: 'my super description'
139 } 138 }
140 var attach = { 139 var attach = {
141 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 140 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
142 } 141 }
143 makePostRequest(path, data, attach, done) 142 makePostRequest(path, data, attach, done)
144 }) 143 })
145 144
146 it('Should fail with a long name', function (done) { 145 it('Should fail with a long name', function (done) {
147 var data = { 146 var data = {
148 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',
149 description: 'my super description' 148 description: 'my super description'
150 } 149 }
151 var attach = { 150 var attach = {
152 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 151 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
153 } 152 }
154 makePostRequest(path, data, attach, done) 153 makePostRequest(path, data, attach, done)
155 }) 154 })
156 155
157 it('Should fail without description', function (done) { 156 it('Should fail without description', function (done) {
158 var data = { 157 var data = {
159 name: 'my super name' 158 name: 'my super name'
160 } 159 }
161 var attach = { 160 var attach = {
162 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 161 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
163 } 162 }
164 makePostRequest(path, data, attach, done) 163 makePostRequest(path, data, attach, done)
165 }) 164 })
166 165
167 it('Should fail with a long description', function (done) { 166 it('Should fail with a long description', function (done) {
168 var data = { 167 var data = {
169 name: 'my super name', 168 name: 'my super name',
170 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' +
171 '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' +
172 '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'
173 } 172 }
174 var attach = { 173 var attach = {
175 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 174 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
176 } 175 }
177 makePostRequest(path, data, attach, done) 176 makePostRequest(path, data, attach, done)
178 }) 177 })
179 178
180 it('Should fail without an input file', function (done) { 179 it('Should fail without an input file', function (done) {
181 var data = { 180 var data = {
182 name: 'my super name', 181 name: 'my super name',
183 description: 'my super description' 182 description: 'my super description'
184 } 183 }
185 var attach = {} 184 var attach = {}
186 makePostRequest(path, data, attach, done) 185 makePostRequest(path, data, attach, done)
187 }) 186 })
188 187
189 it('Should fail without an incorrect input file', function (done) { 188 it('Should fail without an incorrect input file', function (done) {
190 var data = { 189 var data = {
191 name: 'my super name', 190 name: 'my super name',
192 description: 'my super description' 191 description: 'my super description'
193 } 192 }
194 var attach = { 193 var attach = {
195 'input_video': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm') 194 'input_video': pathUtils.join(__dirname, '..', 'fixtures', 'video_short_fake.webm')
196 } 195 }
197 makePostRequest(path, data, attach, done) 196 makePostRequest(path, data, attach, done)
198 }) 197 })
199 198
200 it('Should succeed with the correct parameters', function (done) { 199 it('Should succeed with the correct parameters', function (done) {
201 var data = { 200 var data = {
202 name: 'my super name', 201 name: 'my super name',
203 description: 'my super description' 202 description: 'my super description'
204 } 203 }
205 var attach = { 204 var attach = {
206 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 205 'input_video': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
207 } 206 }
207 makePostRequest(path, data, attach, function () {
208 attach.input_video = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4')
208 makePostRequest(path, data, attach, function () { 209 makePostRequest(path, data, attach, function () {
209 attach.input_video = pathUtils.join(__dirname, 'fixtures', 'video_short.mp4') 210 attach.input_video = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv')
210 makePostRequest(path, data, attach, function () { 211 makePostRequest(path, data, attach, done, true)
211 attach.input_video = pathUtils.join(__dirname, 'fixtures', 'video_short.ogv')
212 makePostRequest(path, data, attach, done, true)
213 }, true)
214 }, true) 212 }, true)
215 }) 213 }, true)
216 }) 214 })
215 })
217 216
218 describe('When getting a video', function () { 217 describe('When getting a video', function () {
219 it('Should return the list of the videos with nothing', function (done) { 218 it('Should return the list of the videos with nothing', function (done) {
220 request(url) 219 request(url)
221 .get(path) 220 .get(path)
222 .set('Accept', 'application/json') 221 .set('Accept', 'application/json')
223 .expect(200) 222 .expect(200)
224 .expect('Content-Type', /json/) 223 .expect('Content-Type', /json/)
225 .end(function (err, res) { 224 .end(function (err, res) {
226 if (err) throw err 225 if (err) throw err
227
228 expect(res.body).to.be.an('array')
229 expect(res.body.length).to.equal(0)
230
231 done()
232 })
233 })
234 226
235 it('Should fail without a mongodb id', function (done) { 227 expect(res.body).to.be.an('array')
236 request(url) 228 expect(res.body.length).to.equal(0)
237 .get(path + 'coucou')
238 .set('Accept', 'application/json')
239 .expect(400, done)
240 })
241 229
242 it('Should return 404 with an incorrect video', function (done) { 230 done()
243 request(url) 231 })
244 .get(path + '123456789012345678901234') 232 })
245 .set('Accept', 'application/json')
246 .expect(404, done)
247 })
248 233
249 it('Should succeed with the correct parameters') 234 it('Should fail without a mongodb id', function (done) {
235 request(url)
236 .get(path + 'coucou')
237 .set('Accept', 'application/json')
238 .expect(400, done)
250 }) 239 })
251 240
252 describe('When removing a video', function () { 241 it('Should return 404 with an incorrect video', function (done) {
253 it('Should have 404 with nothing', function (done) { 242 request(url)
254 request(url) 243 .get(path + '123456789012345678901234')
255 .delete(path) 244 .set('Accept', 'application/json')
256 .expect(404, done) 245 .expect(404, done)
257 })
258
259 it('Should fail without a mongodb id', function (done) {
260 request(url)
261 .delete(path + 'hello')
262 .expect(400, done)
263 })
264
265 it('Should fail with a video which does not exist', function (done) {
266 request(url)
267 .delete(path + '123456789012345678901234')
268 .expect(404, done)
269 })
270
271 it('Should fail with a video of another pod')
272
273 it('Should succeed with the correct parameters')
274 }) 246 })
247
248 it('Should succeed with the correct parameters')
275 }) 249 })
276 250
277 describe('Of the remote videos API', function () { 251 describe('When removing a video', function () {
278 describe('When making a secure request', function () { 252 it('Should have 404 with nothing', function (done) {
279 it('Should check a secure request') 253 request(url)
254 .delete(path)
255 .expect(404, done)
280 }) 256 })
281 257
282 describe('When adding a video', function () { 258 it('Should fail without a mongodb id', function (done) {
283 it('Should check when adding a video') 259 request(url)
260 .delete(path + 'hello')
261 .expect(400, done)
284 }) 262 })
285 263
286 describe('When removing a video', function () { 264 it('Should fail with a video which does not exist', function (done) {
287 it('Should check when removing a video') 265 request(url)
266 .delete(path + '123456789012345678901234')
267 .expect(404, done)
288 }) 268 })
269
270 it('Should fail with a video of another pod')
271
272 it('Should succeed with the correct parameters')
289 }) 273 })
274 })
290 275
291 after(function (done) { 276 describe('Of the remote videos API', function () {
292 process.kill(-app.pid) 277 describe('When making a secure request', function () {
278 it('Should check a secure request')
279 })
293 280
294 // Keep the logs if the test failed 281 describe('When adding a video', function () {
295 if (this.ok) { 282 it('Should check when adding a video')
296 utils.flushTests(done)
297 } else {
298 done()
299 }
300 }) 283 })
284
285 describe('When removing a video', function () {
286 it('Should check when removing a video')
287 })
288 })
289
290 after(function (done) {
291 process.kill(-app.pid)
292
293 // Keep the logs if the test failed
294 if (this.ok) {
295 utils.flushTests(done)
296 } else {
297 done()
298 }
301 }) 299 })
302})() 300})
diff --git a/tests/api/friendsAdvanced.js b/tests/api/friendsAdvanced.js
index 61483bee6..9838d890f 100644
--- a/tests/api/friendsAdvanced.js
+++ b/tests/api/friendsAdvanced.js
@@ -1,252 +1,250 @@
1;(function () { 1'use strict'
2 'use strict'
3 2
4 var async = require('async') 3var async = require('async')
5 var chai = require('chai') 4var chai = require('chai')
6 var expect = chai.expect 5var expect = chai.expect
7 6
8 var utils = require('./utils') 7var utils = require('./utils')
9 8
10 describe('Test advanced friends', function () { 9describe('Test advanced friends', function () {
11 var apps = [] 10 var apps = []
12 var urls = [] 11 var urls = []
13 12
14 function makeFriends (pod_number, callback) { 13 function makeFriends (pod_number, callback) {
15 return utils.makeFriends(urls[pod_number - 1], callback) 14 return utils.makeFriends(urls[pod_number - 1], callback)
16 } 15 }
17 16
18 function quitFriends (pod_number, callback) { 17 function quitFriends (pod_number, callback) {
19 return utils.quitFriends(urls[pod_number - 1], callback) 18 return utils.quitFriends(urls[pod_number - 1], callback)
20 } 19 }
21 20
22 function getFriendsList (pod_number, end) { 21 function getFriendsList (pod_number, end) {
23 return utils.getFriendsList(urls[pod_number - 1], end) 22 return utils.getFriendsList(urls[pod_number - 1], end)
24 } 23 }
25 24
26 function uploadVideo (pod_number, callback) { 25 function uploadVideo (pod_number, callback) {
27 var name = 'my super video' 26 var name = 'my super video'
28 var description = 'my super description' 27 var description = 'my super description'
29 var fixture = 'video_short.webm' 28 var fixture = 'video_short.webm'
30 29
31 return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback) 30 return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback)
32 } 31 }
33 32
34 function getVideos (pod_number, callback) { 33 function getVideos (pod_number, callback) {
35 return utils.getVideosList(urls[pod_number - 1], callback) 34 return utils.getVideosList(urls[pod_number - 1], callback)
36 } 35 }
37 36
38 // --------------------------------------------------------------- 37 // ---------------------------------------------------------------
39 38
40 before(function (done) { 39 before(function (done) {
41 this.timeout(30000) 40 this.timeout(30000)
42 utils.flushAndRunMultipleServers(6, function (apps_run, urls_run) { 41 utils.flushAndRunMultipleServers(6, function (apps_run, urls_run) {
43 apps = apps_run 42 apps = apps_run
44 urls = urls_run 43 urls = urls_run
45 done() 44 done()
46 })
47 }) 45 })
46 })
48 47
49 it('Should make friends with two pod each in a different group', function (done) { 48 it('Should make friends with two pod each in a different group', function (done) {
50 this.timeout(20000) 49 this.timeout(20000)
51 50
52 async.series([ 51 async.series([
53 // Pod 3 makes friend with the first one 52 // Pod 3 makes friend with the first one
54 function (next) { 53 function (next) {
55 makeFriends(3, next) 54 makeFriends(3, next)
56 }, 55 },
57 // Pod 4 makes friend with the second one 56 // Pod 4 makes friend with the second one
58 function (next) { 57 function (next) {
59 makeFriends(4, next) 58 makeFriends(4, next)
60 }, 59 },
61 // Now if the fifth wants to make friends with the third et the first 60 // Now if the fifth wants to make friends with the third et the first
62 function (next) { 61 function (next) {
63 makeFriends(5, next) 62 makeFriends(5, next)
64 }, 63 },
65 function (next) { 64 function (next) {
66 setTimeout(next, 11000) 65 setTimeout(next, 11000)
67 }], 66 }],
68 function (err) { 67 function (err) {
68 if (err) throw err
69
70 // It should have 0 friends
71 getFriendsList(5, function (err, res) {
69 if (err) throw err 72 if (err) throw err
70 73
71 // It should have 0 friends 74 expect(res.body.length).to.equal(0)
72 getFriendsList(5, function (err, res) { 75
76 done()
77 })
78 }
79 )
80 })
81
82 it('Should quit all friends', function (done) {
83 this.timeout(10000)
84
85 async.series([
86 function (next) {
87 quitFriends(1, next)
88 },
89 function (next) {
90 quitFriends(2, next)
91 }],
92 function (err) {
93 if (err) throw err
94
95 async.each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) {
96 getFriendsList(i, function (err, res) {
73 if (err) throw err 97 if (err) throw err
74 98
75 expect(res.body.length).to.equal(0) 99 expect(res.body.length).to.equal(0)
76 100
77 done() 101 callback()
78 }) 102 })
79 } 103 }, done)
80 ) 104 }
81 }) 105 )
106 })
82 107
83 it('Should quit all friends', function (done) { 108 it('Should make friends with the pods 1, 2, 3', function (done) {
84 this.timeout(10000) 109 this.timeout(150000)
85 110
86 async.series([ 111 async.series([
87 function (next) { 112 // Pods 1, 2, 3 and 4 become friends
88 quitFriends(1, next) 113 function (next) {
89 }, 114 makeFriends(2, next)
90 function (next) { 115 },
91 quitFriends(2, next) 116 function (next) {
92 }], 117 makeFriends(1, next)
93 function (err) { 118 },
119 function (next) {
120 makeFriends(4, next)
121 },
122 // Kill pod 4
123 function (next) {
124 apps[3].kill()
125 next()
126 },
127 // Expulse pod 4 from pod 1 and 2
128 function (next) {
129 uploadVideo(1, next)
130 },
131 function (next) {
132 uploadVideo(2, next)
133 },
134 function (next) {
135 setTimeout(next, 11000)
136 },
137 function (next) {
138 uploadVideo(1, next)
139 },
140 function (next) {
141 uploadVideo(2, next)
142 },
143 function (next) {
144 setTimeout(next, 20000)
145 },
146 // Rerun server 4
147 function (next) {
148 utils.runServer(4, function (app, url) {
149 apps[3] = app
150 next()
151 })
152 },
153 function (next) {
154 getFriendsList(4, function (err, res) {
94 if (err) throw err 155 if (err) throw err
95 156
96 async.each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) { 157 // Pod 4 didn't know pod 1 and 2 removed it
97 getFriendsList(i, function (err, res) { 158 expect(res.body.length).to.equal(3)
98 if (err) throw err
99
100 expect(res.body.length).to.equal(0)
101 159
102 callback()
103 })
104 }, done)
105 }
106 )
107 })
108
109 it('Should make friends with the pods 1, 2, 3', function (done) {
110 this.timeout(150000)
111
112 async.series([
113 // Pods 1, 2, 3 and 4 become friends
114 function (next) {
115 makeFriends(2, next)
116 },
117 function (next) {
118 makeFriends(1, next)
119 },
120 function (next) {
121 makeFriends(4, next)
122 },
123 // Kill pod 4
124 function (next) {
125 apps[3].kill()
126 next() 160 next()
127 }, 161 })
128 // Expulse pod 4 from pod 1 and 2 162 },
129 function (next) { 163 // Pod 6 ask pod 1, 2 and 3
130 uploadVideo(1, next) 164 function (next) {
131 }, 165 makeFriends(6, next)
132 function (next) { 166 }],
133 uploadVideo(2, next) 167 function (err) {
134 }, 168 if (err) throw err
135 function (next) { 169
136 setTimeout(next, 11000) 170 getFriendsList(6, function (err, res) {
137 },
138 function (next) {
139 uploadVideo(1, next)
140 },
141 function (next) {
142 uploadVideo(2, next)
143 },
144 function (next) {
145 setTimeout(next, 20000)
146 },
147 // Rerun server 4
148 function (next) {
149 utils.runServer(4, function (app, url) {
150 apps[3] = app
151 next()
152 })
153 },
154 function (next) {
155 getFriendsList(4, function (err, res) {
156 if (err) throw err
157
158 // Pod 4 didn't know pod 1 and 2 removed it
159 expect(res.body.length).to.equal(3)
160
161 next()
162 })
163 },
164 // Pod 6 ask pod 1, 2 and 3
165 function (next) {
166 makeFriends(6, next)
167 }],
168 function (err) {
169 if (err) throw err 171 if (err) throw err
170 172
171 getFriendsList(6, function (err, res) { 173 // Pod 4 should not be our friend
172 if (err) throw err 174 var result = res.body
175 expect(result.length).to.equal(3)
176 for (var pod of result) {
177 expect(pod.url).not.equal(urls[3])
178 }
173 179
174 // Pod 4 should not be our friend 180 done()
175 var result = res.body 181 })
176 expect(result.length).to.equal(3) 182 }
177 for (var pod of result) { 183 )
178 expect(pod.url).not.equal(urls[3]) 184 })
179 }
180 185
181 done() 186 it('Should pod 1 quit friends', function (done) {
182 }) 187 this.timeout(25000)
183 } 188
184 ) 189 async.series([
185 }) 190 // Upload a video on server 3 for aditionnal tests
191 function (next) {
192 uploadVideo(3, next)
193 },
194 function (next) {
195 setTimeout(next, 15000)
196 },
197 function (next) {
198 quitFriends(1, next)
199 },
200 // Remove pod 1 from pod 2
201 function (next) {
202 getVideos(1, function (err, res) {
203 if (err) throw err
204 expect(res.body).to.be.an('array')
205 expect(res.body.length).to.equal(2)
186 206
187 it('Should pod 1 quit friends', function (done) { 207 next()
188 this.timeout(25000) 208 })
189 209 }],
190 async.series([ 210 function (err) {
191 // Upload a video on server 3 for aditionnal tests 211 if (err) throw err
192 function (next) {
193 uploadVideo(3, next)
194 },
195 function (next) {
196 setTimeout(next, 15000)
197 },
198 function (next) {
199 quitFriends(1, next)
200 },
201 // Remove pod 1 from pod 2
202 function (next) {
203 getVideos(1, function (err, res) {
204 if (err) throw err
205 expect(res.body).to.be.an('array')
206 expect(res.body.length).to.equal(2)
207 212
208 next() 213 getVideos(2, function (err, res) {
209 })
210 }],
211 function (err) {
212 if (err) throw err 214 if (err) throw err
215 expect(res.body).to.be.an('array')
216 expect(res.body.length).to.equal(3)
217 done()
218 })
219 }
220 )
221 })
213 222
214 getVideos(2, function (err, res) { 223 it('Should make friends between pod 1 and 2 and exchange their videos', function (done) {
215 if (err) throw err 224 this.timeout(20000)
216 expect(res.body).to.be.an('array') 225 makeFriends(1, function () {
217 expect(res.body.length).to.equal(3) 226 setTimeout(function () {
218 done() 227 getVideos(1, function (err, res) {
219 }) 228 if (err) throw err
220 }
221 )
222 })
223
224 it('Should make friends between pod 1 and 2 and exchange their videos', function (done) {
225 this.timeout(20000)
226 makeFriends(1, function () {
227 setTimeout(function () {
228 getVideos(1, function (err, res) {
229 if (err) throw err
230 229
231 expect(res.body).to.be.an('array') 230 expect(res.body).to.be.an('array')
232 expect(res.body.length).to.equal(5) 231 expect(res.body.length).to.equal(5)
233 232
234 done() 233 done()
235 }) 234 })
236 }, 5000) 235 }, 5000)
237 })
238 }) 236 })
237 })
239 238
240 after(function (done) { 239 after(function (done) {
241 apps.forEach(function (app) { 240 apps.forEach(function (app) {
242 process.kill(-app.pid) 241 process.kill(-app.pid)
243 })
244
245 if (this.ok) {
246 utils.flushTests(done)
247 } else {
248 done()
249 }
250 }) 242 })
243
244 if (this.ok) {
245 utils.flushTests(done)
246 } else {
247 done()
248 }
251 }) 249 })
252})() 250})
diff --git a/tests/api/friendsBasic.js b/tests/api/friendsBasic.js
index dbc918383..328724936 100644
--- a/tests/api/friendsBasic.js
+++ b/tests/api/friendsBasic.js
@@ -1,187 +1,185 @@
1;(function () { 1'use strict'
2 'use strict'
3 2
4 var async = require('async') 3var async = require('async')
5 var chai = require('chai') 4var chai = require('chai')
6 var expect = chai.expect 5var expect = chai.expect
7 var request = require('supertest') 6var request = require('supertest')
8 7
9 var utils = require('./utils') 8var utils = require('./utils')
10 9
11 describe('Test basic friends', function () { 10describe('Test basic friends', function () {
12 var apps = [] 11 var apps = []
13 var urls = [] 12 var urls = []
14 13
15 function testMadeFriends (urls, url_to_test, callback) { 14 function testMadeFriends (urls, url_to_test, callback) {
16 var friends = [] 15 var friends = []
17 for (var i = 0; i < urls.length; i++) { 16 for (var i = 0; i < urls.length; i++) {
18 if (urls[i] === url_to_test) continue 17 if (urls[i] === url_to_test) continue
19 friends.push(urls[i]) 18 friends.push(urls[i])
20 } 19 }
20
21 utils.getFriendsList(url_to_test, function (err, res) {
22 if (err) throw err
23
24 var result = res.body
25 var result_urls = [ result[0].url, result[1].url ]
26 expect(result).to.be.an('array')
27 expect(result.length).to.equal(2)
28 expect(result_urls[0]).to.not.equal(result_urls[1])
21 29
22 utils.getFriendsList(url_to_test, function (err, res) { 30 var error_string = 'Friends url do not correspond for ' + url_to_test
31 expect(friends).to.contain(result_urls[0], error_string)
32 expect(friends).to.contain(result_urls[1], error_string)
33 callback()
34 })
35 }
36
37 // ---------------------------------------------------------------
38
39 before(function (done) {
40 this.timeout(20000)
41 utils.flushAndRunMultipleServers(3, function (apps_run, urls_run) {
42 apps = apps_run
43 urls = urls_run
44 done()
45 })
46 })
47
48 it('Should not have friends', function (done) {
49 async.each(urls, function (url, callback) {
50 utils.getFriendsList(url, function (err, res) {
23 if (err) throw err 51 if (err) throw err
24 52
25 var result = res.body 53 var result = res.body
26 var result_urls = [ result[0].url, result[1].url ]
27 expect(result).to.be.an('array') 54 expect(result).to.be.an('array')
28 expect(result.length).to.equal(2) 55 expect(result.length).to.equal(0)
29 expect(result_urls[0]).to.not.equal(result_urls[1])
30
31 var error_string = 'Friends url do not correspond for ' + url_to_test
32 expect(friends).to.contain(result_urls[0], error_string)
33 expect(friends).to.contain(result_urls[1], error_string)
34 callback() 56 callback()
35 }) 57 })
36 } 58 }, done)
59 })
37 60
38 // --------------------------------------------------------------- 61 it('Should make friends', function (done) {
62 this.timeout(10000)
63
64 var path = '/api/v1/pods/makefriends'
65
66 async.series([
67 // The second pod make friend with the third
68 function (next) {
69 request(urls[1])
70 .get(path)
71 .set('Accept', 'application/json')
72 .expect(204)
73 .end(next)
74 },
75 // Wait for the request between pods
76 function (next) {
77 setTimeout(next, 1000)
78 },
79 // The second pod should have the third as a friend
80 function (next) {
81 utils.getFriendsList(urls[1], function (err, res) {
82 if (err) throw err
39 83
40 before(function (done) { 84 var result = res.body
41 this.timeout(20000) 85 expect(result).to.be.an('array')
42 utils.flushAndRunMultipleServers(3, function (apps_run, urls_run) { 86 expect(result.length).to.equal(1)
43 apps = apps_run 87 expect(result[0].url).to.be.equal(urls[2])
44 urls = urls_run
45 done()
46 })
47 })
48 88
49 it('Should not have friends', function (done) { 89 next()
50 async.each(urls, function (url, callback) { 90 })
51 utils.getFriendsList(url, function (err, res) { 91 },
92 // Same here, the third pod should have the second pod as a friend
93 function (next) {
94 utils.getFriendsList(urls[2], function (err, res) {
52 if (err) throw err 95 if (err) throw err
53 96
54 var result = res.body 97 var result = res.body
55 expect(result).to.be.an('array') 98 expect(result).to.be.an('array')
56 expect(result.length).to.equal(0) 99 expect(result.length).to.equal(1)
57 callback() 100 expect(result[0].url).to.be.equal(urls[1])
101
102 next()
58 }) 103 })
104 },
105 // Finally the first pod make friend with the second pod
106 function (next) {
107 request(urls[0])
108 .get(path)
109 .set('Accept', 'application/json')
110 .expect(204)
111 .end(next)
112 },
113 // Wait for the request between pods
114 function (next) {
115 setTimeout(next, 1000)
116 }
117 ],
118 // Now each pod should be friend with the other ones
119 function (err) {
120 if (err) throw err
121 async.each(urls, function (url, callback) {
122 testMadeFriends(urls, url, callback)
59 }, done) 123 }, done)
60 }) 124 })
125 })
61 126
62 it('Should make friends', function (done) { 127 it('Should not be allowed to make friend again', function (done) {
63 this.timeout(10000) 128 utils.makeFriends(urls[1], 409, done)
64 129 })
65 var path = '/api/v1/pods/makefriends'
66
67 async.series([
68 // The second pod make friend with the third
69 function (next) {
70 request(urls[1])
71 .get(path)
72 .set('Accept', 'application/json')
73 .expect(204)
74 .end(next)
75 },
76 // Wait for the request between pods
77 function (next) {
78 setTimeout(next, 1000)
79 },
80 // The second pod should have the third as a friend
81 function (next) {
82 utils.getFriendsList(urls[1], function (err, res) {
83 if (err) throw err
84 130
85 var result = res.body 131 it('Should quit friends of pod 2', function (done) {
86 expect(result).to.be.an('array') 132 async.series([
87 expect(result.length).to.equal(1) 133 // Pod 1 quit friends
88 expect(result[0].url).to.be.equal(urls[2]) 134 function (next) {
135 utils.quitFriends(urls[1], next)
136 },
137 // Pod 1 should not have friends anymore
138 function (next) {
139 utils.getFriendsList(urls[1], function (err, res) {
140 if (err) throw err
89 141
90 next() 142 var result = res.body
91 }) 143 expect(result).to.be.an('array')
92 }, 144 expect(result.length).to.equal(0)
93 // Same here, the third pod should have the second pod as a friend 145
94 function (next) { 146 next()
95 utils.getFriendsList(urls[2], function (err, res) { 147 })
148 },
149 // Other pods shouldn't have pod 1 too
150 function (next) {
151 async.each([ urls[0], urls[2] ], function (url, callback) {
152 utils.getFriendsList(url, function (err, res) {
96 if (err) throw err 153 if (err) throw err
97 154
98 var result = res.body 155 var result = res.body
99 expect(result).to.be.an('array') 156 expect(result).to.be.an('array')
100 expect(result.length).to.equal(1) 157 expect(result.length).to.equal(1)
101 expect(result[0].url).to.be.equal(urls[1]) 158 expect(result[0].url).not.to.be.equal(urls[1])
102 159 callback()
103 next()
104 }) 160 })
105 }, 161 }, next)
106 // Finally the first pod make friend with the second pod 162 }
107 function (next) { 163 ], done)
108 request(urls[0]) 164 })
109 .get(path)
110 .set('Accept', 'application/json')
111 .expect(204)
112 .end(next)
113 },
114 // Wait for the request between pods
115 function (next) {
116 setTimeout(next, 1000)
117 }
118 ],
119 // Now each pod should be friend with the other ones
120 function (err) {
121 if (err) throw err
122 async.each(urls, function (url, callback) {
123 testMadeFriends(urls, url, callback)
124 }, done)
125 })
126 })
127
128 it('Should not be allowed to make friend again', function (done) {
129 utils.makeFriends(urls[1], 409, done)
130 })
131
132 it('Should quit friends of pod 2', function (done) {
133 async.series([
134 // Pod 1 quit friends
135 function (next) {
136 utils.quitFriends(urls[1], next)
137 },
138 // Pod 1 should not have friends anymore
139 function (next) {
140 utils.getFriendsList(urls[1], function (err, res) {
141 if (err) throw err
142
143 var result = res.body
144 expect(result).to.be.an('array')
145 expect(result.length).to.equal(0)
146 165
147 next() 166 it('Should allow pod 2 to make friend again', function (done) {
148 }) 167 utils.makeFriends(urls[1], function () {
149 }, 168 async.each(urls, function (url, callback) {
150 // Other pods shouldn't have pod 1 too 169 testMadeFriends(urls, url, callback)
151 function (next) { 170 }, done)
152 async.each([ urls[0], urls[2] ], function (url, callback) {
153 utils.getFriendsList(url, function (err, res) {
154 if (err) throw err
155
156 var result = res.body
157 expect(result).to.be.an('array')
158 expect(result.length).to.equal(1)
159 expect(result[0].url).not.to.be.equal(urls[1])
160 callback()
161 })
162 }, next)
163 }
164 ], done)
165 }) 171 })
172 })
166 173
167 it('Should allow pod 2 to make friend again', function (done) { 174 after(function (done) {
168 utils.makeFriends(urls[1], function () { 175 apps.forEach(function (app) {
169 async.each(urls, function (url, callback) { 176 process.kill(-app.pid)
170 testMadeFriends(urls, url, callback)
171 }, done)
172 })
173 }) 177 })
174 178
175 after(function (done) { 179 if (this.ok) {
176 apps.forEach(function (app) { 180 utils.flushTests(done)
177 process.kill(-app.pid) 181 } else {
178 }) 182 done()
179 183 }
180 if (this.ok) {
181 utils.flushTests(done)
182 } else {
183 done()
184 }
185 })
186 }) 184 })
187})() 185})
diff --git a/tests/api/index.js b/tests/api/index.js
index 3bdcdae2d..9c4fdd48a 100644
--- a/tests/api/index.js
+++ b/tests/api/index.js
@@ -1,10 +1,8 @@
1;(function () { 1'use strict'
2 'use strict'
3 2
4 // Order of the tests we want to execute 3// Order of the tests we want to execute
5 require('./checkParams') 4require('./checkParams')
6 require('./friendsBasic') 5require('./friendsBasic')
7 require('./singlePod') 6require('./singlePod')
8 require('./multiplePods') 7require('./multiplePods')
9 require('./friendsAdvanced') 8require('./friendsAdvanced')
10})()
diff --git a/tests/api/multiplePods.js b/tests/api/multiplePods.js
index 7949da80a..9fdd0f308 100644
--- a/tests/api/multiplePods.js
+++ b/tests/api/multiplePods.js
@@ -1,330 +1,328 @@
1;(function () { 1'use strict'
2 'use strict' 2
3var async = require('async')
4var chai = require('chai')
5var expect = chai.expect
6var pathUtils = require('path')
7
8var utils = require('./utils')
9var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
10webtorrent.silent = true
11
12describe('Test multiple pods', function () {
13 var apps = []
14 var urls = []
15 var to_remove = []
16
17 before(function (done) {
18 this.timeout(30000)
19
20 async.series([
21 // Run servers
22 function (next) {
23 utils.flushAndRunMultipleServers(3, function (apps_run, urls_run) {
24 apps = apps_run
25 urls = urls_run
26 next()
27 })
28 },
29 // The second pod make friend with the third
30 function (next) {
31 utils.makeFriends(urls[1], next)
32 },
33 // Wait for the request between pods
34 function (next) {
35 setTimeout(next, 10000)
36 },
37 // Pod 1 make friends too
38 function (next) {
39 utils.makeFriends(urls[0], next)
40 },
41 function (next) {
42 webtorrent.create({ host: 'client', port: '1' }, next)
43 }
44 ], done)
45 })
3 46
4 var async = require('async') 47 it('Should not have videos for all pods', function (done) {
5 var chai = require('chai') 48 async.each(urls, function (url, callback) {
6 var expect = chai.expect 49 utils.getVideosList(url, function (err, res) {
7 var pathUtils = require('path') 50 if (err) throw err
8 51
9 var utils = require('./utils') 52 expect(res.body).to.be.an('array')
10 var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) 53 expect(res.body.length).to.equal(0)
11 webtorrent.silent = true
12 54
13 describe('Test multiple pods', function () { 55 callback()
14 var apps = [] 56 })
15 var urls = [] 57 }, done)
16 var to_remove = [] 58 })
17 59
18 before(function (done) { 60 describe('Should upload the video and propagate on each pod', function () {
19 this.timeout(30000) 61 it('Should upload the video on pod 1 and propagate on each pod', function (done) {
62 this.timeout(15000)
20 63
21 async.series([ 64 async.series([
22 // Run servers
23 function (next) {
24 utils.flushAndRunMultipleServers(3, function (apps_run, urls_run) {
25 apps = apps_run
26 urls = urls_run
27 next()
28 })
29 },
30 // The second pod make friend with the third
31 function (next) { 65 function (next) {
32 utils.makeFriends(urls[1], next) 66 utils.uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', next)
33 }, 67 },
34 // Wait for the request between pods
35 function (next) { 68 function (next) {
36 setTimeout(next, 10000) 69 setTimeout(next, 11000)
37 }, 70 }],
38 // Pod 1 make friends too 71 // All pods should have this video
72 function (err) {
73 if (err) throw err
74
75 async.each(urls, function (url, callback) {
76 var base_magnet = null
77
78 utils.getVideosList(url, function (err, res) {
79 if (err) throw err
80
81 var videos = res.body
82 expect(videos).to.be.an('array')
83 expect(videos.length).to.equal(1)
84 var video = videos[0]
85 expect(video.name).to.equal('my super name for pod 1')
86 expect(video.description).to.equal('my super description for pod 1')
87 expect(video.podUrl).to.equal('http://localhost:9001')
88 expect(video.magnetUri).to.exist
89
90 // All pods should have the same magnet Uri
91 if (base_magnet === null) {
92 base_magnet = video.magnetUri
93 } else {
94 expect(video.magnetUri).to.equal.magnetUri
95 }
96
97 callback()
98 })
99 }, done)
100 }
101 )
102 })
103
104 it('Should upload the video on pod 2 and propagate on each pod', function (done) {
105 this.timeout(15000)
106
107 async.series([
39 function (next) { 108 function (next) {
40 utils.makeFriends(urls[0], next) 109 utils.uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next)
41 }, 110 },
42 function (next) { 111 function (next) {
43 webtorrent.create({ host: 'client', port: '1' }, next) 112 setTimeout(next, 11000)
113 }],
114 // All pods should have this video
115 function (err) {
116 if (err) throw err
117
118 async.each(urls, function (url, callback) {
119 var base_magnet = null
120
121 utils.getVideosList(url, function (err, res) {
122 if (err) throw err
123
124 var videos = res.body
125 expect(videos).to.be.an('array')
126 expect(videos.length).to.equal(2)
127 var video = videos[1]
128 expect(video.name).to.equal('my super name for pod 2')
129 expect(video.description).to.equal('my super description for pod 2')
130 expect(video.podUrl).to.equal('http://localhost:9002')
131 expect(video.magnetUri).to.exist
132
133 // All pods should have the same magnet Uri
134 if (base_magnet === null) {
135 base_magnet = video.magnetUri
136 } else {
137 expect(video.magnetUri).to.equal.magnetUri
138 }
139
140 callback()
141 })
142 }, done)
44 } 143 }
45 ], done) 144 )
46 }) 145 })
47 146
48 it('Should not have videos for all pods', function (done) { 147 it('Should upload two videos on pod 3 and propagate on each pod', function (done) {
49 async.each(urls, function (url, callback) { 148 this.timeout(30000)
50 utils.getVideosList(url, function (err, res) {
51 if (err) throw err
52 149
53 expect(res.body).to.be.an('array') 150 async.series([
54 expect(res.body.length).to.equal(0) 151 function (next) {
152 utils.uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next)
153 },
154 function (next) {
155 utils.uploadVideo(urls[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', next)
156 },
157 function (next) {
158 setTimeout(next, 22000)
159 }],
160 function (err) {
161 if (err) throw err
55 162
56 callback() 163 var base_magnet = null
57 }) 164 // All pods should have this video
58 }, done) 165 async.each(urls, function (url, callback) {
166 utils.getVideosList(url, function (err, res) {
167 if (err) throw err
168
169 var videos = res.body
170 expect(videos).to.be.an('array')
171 expect(videos.length).to.equal(4)
172 var video = videos[2]
173 expect(video.name).to.equal('my super name for pod 3')
174 expect(video.description).to.equal('my super description for pod 3')
175 expect(video.podUrl).to.equal('http://localhost:9003')
176 expect(video.magnetUri).to.exist
177
178 video = videos[3]
179 expect(video.name).to.equal('my super name for pod 3-2')
180 expect(video.description).to.equal('my super description for pod 3-2')
181 expect(video.podUrl).to.equal('http://localhost:9003')
182 expect(video.magnetUri).to.exist
183
184 // All pods should have the same magnet Uri
185 if (base_magnet === null) {
186 base_magnet = video.magnetUri
187 } else {
188 expect(video.magnetUri).to.equal.magnetUri
189 }
190
191 callback()
192 })
193 }, done)
194 }
195 )
59 }) 196 })
197 })
60 198
61 describe('Should upload the video and propagate on each pod', function () { 199 describe('Should seed the uploaded video', function () {
62 it('Should upload the video on pod 1 and propagate on each pod', function (done) { 200 it('Should add the file 1 by asking pod 3', function (done) {
63 this.timeout(15000) 201 // Yes, this could be long
64 202 this.timeout(200000)
65 async.series([
66 function (next) {
67 utils.uploadVideo(urls[0], 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', next)
68 },
69 function (next) {
70 setTimeout(next, 11000)
71 }],
72 // All pods should have this video
73 function (err) {
74 if (err) throw err
75
76 async.each(urls, function (url, callback) {
77 var base_magnet = null
78
79 utils.getVideosList(url, function (err, res) {
80 if (err) throw err
81
82 var videos = res.body
83 expect(videos).to.be.an('array')
84 expect(videos.length).to.equal(1)
85 var video = videos[0]
86 expect(video.name).to.equal('my super name for pod 1')
87 expect(video.description).to.equal('my super description for pod 1')
88 expect(video.podUrl).to.equal('http://localhost:9001')
89 expect(video.magnetUri).to.exist
90
91 // All pods should have the same magnet Uri
92 if (base_magnet === null) {
93 base_magnet = video.magnetUri
94 } else {
95 expect(video.magnetUri).to.equal.magnetUri
96 }
97
98 callback()
99 })
100 }, done)
101 }
102 )
103 })
104 203
105 it('Should upload the video on pod 2 and propagate on each pod', function (done) { 204 utils.getVideosList(urls[2], function (err, res) {
106 this.timeout(15000) 205 if (err) throw err
107 206
108 async.series([ 207 var video = res.body[0]
109 function (next) { 208 to_remove.push(res.body[2]._id)
110 utils.uploadVideo(urls[1], 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next) 209 to_remove.push(res.body[3]._id)
111 },
112 function (next) {
113 setTimeout(next, 11000)
114 }],
115 // All pods should have this video
116 function (err) {
117 if (err) throw err
118
119 async.each(urls, function (url, callback) {
120 var base_magnet = null
121
122 utils.getVideosList(url, function (err, res) {
123 if (err) throw err
124
125 var videos = res.body
126 expect(videos).to.be.an('array')
127 expect(videos.length).to.equal(2)
128 var video = videos[1]
129 expect(video.name).to.equal('my super name for pod 2')
130 expect(video.description).to.equal('my super description for pod 2')
131 expect(video.podUrl).to.equal('http://localhost:9002')
132 expect(video.magnetUri).to.exist
133
134 // All pods should have the same magnet Uri
135 if (base_magnet === null) {
136 base_magnet = video.magnetUri
137 } else {
138 expect(video.magnetUri).to.equal.magnetUri
139 }
140
141 callback()
142 })
143 }, done)
144 }
145 )
146 })
147 210
148 it('Should upload two videos on pod 3 and propagate on each pod', function (done) { 211 webtorrent.add(video.magnetUri, function (torrent) {
149 this.timeout(30000) 212 expect(torrent.files).to.exist
150 213 expect(torrent.files.length).to.equal(1)
151 async.series([ 214 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
152 function (next) {
153 utils.uploadVideo(urls[2], 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next)
154 },
155 function (next) {
156 utils.uploadVideo(urls[2], 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', next)
157 },
158 function (next) {
159 setTimeout(next, 22000)
160 }],
161 function (err) {
162 if (err) throw err
163 215
164 var base_magnet = null 216 done()
165 // All pods should have this video 217 })
166 async.each(urls, function (url, callback) {
167 utils.getVideosList(url, function (err, res) {
168 if (err) throw err
169
170 var videos = res.body
171 expect(videos).to.be.an('array')
172 expect(videos.length).to.equal(4)
173 var video = videos[2]
174 expect(video.name).to.equal('my super name for pod 3')
175 expect(video.description).to.equal('my super description for pod 3')
176 expect(video.podUrl).to.equal('http://localhost:9003')
177 expect(video.magnetUri).to.exist
178
179 video = videos[3]
180 expect(video.name).to.equal('my super name for pod 3-2')
181 expect(video.description).to.equal('my super description for pod 3-2')
182 expect(video.podUrl).to.equal('http://localhost:9003')
183 expect(video.magnetUri).to.exist
184
185 // All pods should have the same magnet Uri
186 if (base_magnet === null) {
187 base_magnet = video.magnetUri
188 } else {
189 expect(video.magnetUri).to.equal.magnetUri
190 }
191
192 callback()
193 })
194 }, done)
195 }
196 )
197 }) 218 })
198 }) 219 })
199 220
200 describe('Should seed the uploaded video', function () { 221 it('Should add the file 2 by asking pod 1', function (done) {
201 it('Should add the file 1 by asking pod 3', function (done) { 222 // Yes, this could be long
202 // Yes, this could be long 223 this.timeout(200000)
203 this.timeout(200000)
204 224
205 utils.getVideosList(urls[2], function (err, res) { 225 utils.getVideosList(urls[0], function (err, res) {
206 if (err) throw err 226 if (err) throw err
207 227
208 var video = res.body[0] 228 var video = res.body[1]
209 to_remove.push(res.body[2]._id)
210 to_remove.push(res.body[3]._id)
211 229
212 webtorrent.add(video.magnetUri, function (torrent) { 230 webtorrent.add(video.magnetUri, function (torrent) {
213 expect(torrent.files).to.exist 231 expect(torrent.files).to.exist
214 expect(torrent.files.length).to.equal(1) 232 expect(torrent.files.length).to.equal(1)
215 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 233 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
216 234
217 done() 235 done()
218 })
219 }) 236 })
220 }) 237 })
238 })
221 239
222 it('Should add the file 2 by asking pod 1', function (done) { 240 it('Should add the file 3 by asking pod 2', function (done) {
223 // Yes, this could be long 241 // Yes, this could be long
224 this.timeout(200000) 242 this.timeout(200000)
225 243
226 utils.getVideosList(urls[0], function (err, res) { 244 utils.getVideosList(urls[1], function (err, res) {
227 if (err) throw err 245 if (err) throw err
228 246
229 var video = res.body[1] 247 var video = res.body[2]
230 248
231 webtorrent.add(video.magnetUri, function (torrent) { 249 webtorrent.add(video.magnetUri, function (torrent) {
232 expect(torrent.files).to.exist 250 expect(torrent.files).to.exist
233 expect(torrent.files.length).to.equal(1) 251 expect(torrent.files.length).to.equal(1)
234 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 252 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
235 253
236 done() 254 done()
237 })
238 }) 255 })
239 }) 256 })
257 })
240 258
241 it('Should add the file 3 by asking pod 2', function (done) { 259 it('Should add the file 3-2 by asking pod 1', function (done) {
242 // Yes, this could be long 260 // Yes, this could be long
243 this.timeout(200000) 261 this.timeout(200000)
244 262
245 utils.getVideosList(urls[1], function (err, res) { 263 utils.getVideosList(urls[0], function (err, res) {
246 if (err) throw err 264 if (err) throw err
247 265
248 var video = res.body[2] 266 var video = res.body[3]
249 267
250 webtorrent.add(video.magnetUri, function (torrent) { 268 webtorrent.add(video.magnetUri, function (torrent) {
251 expect(torrent.files).to.exist 269 expect(torrent.files).to.exist
252 expect(torrent.files.length).to.equal(1) 270 expect(torrent.files.length).to.equal(1)
253 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 271 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
254 272
255 done() 273 done()
256 })
257 }) 274 })
258 }) 275 })
276 })
259 277
260 it('Should add the file 3-2 by asking pod 1', function (done) { 278 it('Should remove the file 3 and 3-2 by asking pod 3', function (done) {
261 // Yes, this could be long 279 this.timeout(15000)
262 this.timeout(200000)
263 280
264 utils.getVideosList(urls[0], function (err, res) { 281 async.series([
282 function (next) {
283 utils.removeVideo(urls[2], to_remove[0], next)
284 },
285 function (next) {
286 utils.removeVideo(urls[2], to_remove[1], next)
287 }],
288 function (err) {
265 if (err) throw err 289 if (err) throw err
290 setTimeout(done, 11000)
291 }
292 )
293 })
266 294
267 var video = res.body[3] 295 it('Should have videos 1 and 3 on each pod', function (done) {
296 async.each(urls, function (url, callback) {
297 utils.getVideosList(url, function (err, res) {
298 if (err) throw err
268 299
269 webtorrent.add(video.magnetUri, function (torrent) { 300 var videos = res.body
270 expect(torrent.files).to.exist 301 expect(videos).to.be.an('array')
271 expect(torrent.files.length).to.equal(1) 302 expect(videos.length).to.equal(2)
272 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 303 expect(videos[0]._id).not.to.equal(videos[1]._id)
304 expect(videos[0]._id).not.to.equal(to_remove[0])
305 expect(videos[1]._id).not.to.equal(to_remove[0])
306 expect(videos[0]._id).not.to.equal(to_remove[1])
307 expect(videos[1]._id).not.to.equal(to_remove[1])
273 308
274 done() 309 callback()
275 })
276 }) 310 })
277 }) 311 }, done)
278
279 it('Should remove the file 3 and 3-2 by asking pod 3', function (done) {
280 this.timeout(15000)
281
282 async.series([
283 function (next) {
284 utils.removeVideo(urls[2], to_remove[0], next)
285 },
286 function (next) {
287 utils.removeVideo(urls[2], to_remove[1], next)
288 }],
289 function (err) {
290 if (err) throw err
291 setTimeout(done, 11000)
292 }
293 )
294 })
295
296 it('Should have videos 1 and 3 on each pod', function (done) {
297 async.each(urls, function (url, callback) {
298 utils.getVideosList(url, function (err, res) {
299 if (err) throw err
300
301 var videos = res.body
302 expect(videos).to.be.an('array')
303 expect(videos.length).to.equal(2)
304 expect(videos[0]._id).not.to.equal(videos[1]._id)
305 expect(videos[0]._id).not.to.equal(to_remove[0])
306 expect(videos[1]._id).not.to.equal(to_remove[0])
307 expect(videos[0]._id).not.to.equal(to_remove[1])
308 expect(videos[1]._id).not.to.equal(to_remove[1])
309
310 callback()
311 })
312 }, done)
313 })
314 }) 312 })
313 })
315 314
316 after(function (done) { 315 after(function (done) {
317 apps.forEach(function (app) { 316 apps.forEach(function (app) {
318 process.kill(-app.pid) 317 process.kill(-app.pid)
319 })
320 process.kill(-webtorrent.app.pid)
321
322 // Keep the logs if the test failed
323 if (this.ok) {
324 utils.flushTests(done)
325 } else {
326 done()
327 }
328 }) 318 })
319 process.kill(-webtorrent.app.pid)
320
321 // Keep the logs if the test failed
322 if (this.ok) {
323 utils.flushTests(done)
324 } else {
325 done()
326 }
329 }) 327 })
330})() 328})
diff --git a/tests/api/singlePod.js b/tests/api/singlePod.js
index f33aa8c7a..3dd72c01b 100644
--- a/tests/api/singlePod.js
+++ b/tests/api/singlePod.js
@@ -1,148 +1,146 @@
1;(function () { 1'use strict'
2 'use strict' 2
3 3var async = require('async')
4 var async = require('async') 4var chai = require('chai')
5 var chai = require('chai') 5var expect = chai.expect
6 var expect = chai.expect 6var fs = require('fs')
7 var fs = require('fs') 7var pathUtils = require('path')
8 var pathUtils = require('path') 8
9 9var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
10 var webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent')) 10webtorrent.silent = true
11 webtorrent.silent = true 11
12 12var utils = require('./utils')
13 var utils = require('./utils') 13
14 14describe('Test a single pod', function () {
15 describe('Test a single pod', function () { 15 var app = null
16 var app = null 16 var url = ''
17 var url = '' 17 var video_id = -1
18 var video_id = -1 18
19 19 before(function (done) {
20 before(function (done) { 20 this.timeout(20000)
21 this.timeout(20000) 21
22 22 async.series([
23 async.series([ 23 function (next) {
24 function (next) { 24 utils.flushTests(next)
25 utils.flushTests(next) 25 },
26 }, 26 function (next) {
27 function (next) { 27 utils.runServer(1, function (app1, url1) {
28 utils.runServer(1, function (app1, url1) { 28 app = app1
29 app = app1 29 url = url1
30 url = url1 30 next()
31 next() 31 })
32 }) 32 },
33 }, 33 function (next) {
34 function (next) { 34 webtorrent.create({ host: 'client', port: '1' }, next)
35 webtorrent.create({ host: 'client', port: '1' }, next) 35 }
36 } 36 ], done)
37 ], done) 37 })
38 })
39 38
40 it('Should not have videos', function (done) { 39 it('Should not have videos', function (done) {
41 utils.getVideosList(url, function (err, res) { 40 utils.getVideosList(url, function (err, res) {
42 if (err) throw err 41 if (err) throw err
43 42
44 expect(res.body).to.be.an('array') 43 expect(res.body).to.be.an('array')
45 expect(res.body.length).to.equal(0) 44 expect(res.body.length).to.equal(0)
46 45
47 done() 46 done()
48 })
49 }) 47 })
48 })
50 49
51 it('Should upload the video', function (done) { 50 it('Should upload the video', function (done) {
52 this.timeout(5000) 51 this.timeout(5000)
53 utils.uploadVideo(url, 'my super name', 'my super description', 'video_short.webm', done) 52 utils.uploadVideo(url, 'my super name', 'my super description', 'video_short.webm', done)
54 }) 53 })
55 54
56 it('Should seed the uploaded video', function (done) { 55 it('Should seed the uploaded video', function (done) {
57 // Yes, this could be long 56 // Yes, this could be long
58 this.timeout(60000) 57 this.timeout(60000)
59 58
60 utils.getVideosList(url, function (err, res) { 59 utils.getVideosList(url, function (err, res) {
61 if (err) throw err 60 if (err) throw err
62 61
63 expect(res.body).to.be.an('array') 62 expect(res.body).to.be.an('array')
64 expect(res.body.length).to.equal(1) 63 expect(res.body.length).to.equal(1)
65 64
66 var video = res.body[0] 65 var video = res.body[0]
67 expect(video.name).to.equal('my super name') 66 expect(video.name).to.equal('my super name')
68 expect(video.description).to.equal('my super description') 67 expect(video.description).to.equal('my super description')
69 expect(video.podUrl).to.equal('http://localhost:9001') 68 expect(video.podUrl).to.equal('http://localhost:9001')
70 expect(video.magnetUri).to.exist 69 expect(video.magnetUri).to.exist
71 70
72 video_id = video._id 71 video_id = video._id
73 72
74 webtorrent.add(video.magnetUri, function (torrent) { 73 webtorrent.add(video.magnetUri, function (torrent) {
75 expect(torrent.files).to.exist 74 expect(torrent.files).to.exist
76 expect(torrent.files.length).to.equal(1) 75 expect(torrent.files.length).to.equal(1)
77 expect(torrent.files[0].path).to.exist.and.to.not.equal('') 76 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
78 77
79 done() 78 done()
80 })
81 }) 79 })
82 }) 80 })
81 })
83 82
84 it('Should search the video', function (done) { 83 it('Should search the video', function (done) {
85 utils.searchVideo(url, 'my', function (err, res) { 84 utils.searchVideo(url, 'my', function (err, res) {
86 if (err) throw err 85 if (err) throw err
87 86
88 expect(res.body).to.be.an('array') 87 expect(res.body).to.be.an('array')
89 expect(res.body.length).to.equal(1) 88 expect(res.body.length).to.equal(1)
90 89
91 var video = res.body[0] 90 var video = res.body[0]
92 expect(video.name).to.equal('my super name') 91 expect(video.name).to.equal('my super name')
93 expect(video.description).to.equal('my super description') 92 expect(video.description).to.equal('my super description')
94 expect(video.podUrl).to.equal('http://localhost:9001') 93 expect(video.podUrl).to.equal('http://localhost:9001')
95 expect(video.magnetUri).to.exist 94 expect(video.magnetUri).to.exist
96 95
97 done() 96 done()
98 })
99 }) 97 })
98 })
100 99
101 it('Should not find a search', function (done) { 100 it('Should not find a search', function (done) {
102 utils.searchVideo(url, 'hello', function (err, res) { 101 utils.searchVideo(url, 'hello', function (err, res) {
103 if (err) throw err 102 if (err) throw err
104 103
105 expect(res.body).to.be.an('array') 104 expect(res.body).to.be.an('array')
106 expect(res.body.length).to.equal(0) 105 expect(res.body.length).to.equal(0)
107 106
108 done() 107 done()
109 })
110 }) 108 })
109 })
111 110
112 it('Should remove the video', function (done) { 111 it('Should remove the video', function (done) {
113 utils.removeVideo(url, video_id, function (err) { 112 utils.removeVideo(url, video_id, function (err) {
114 if (err) throw err 113 if (err) throw err
115 114
116 fs.readdir(pathUtils.join(__dirname, '../../test1/uploads/'), function (err, files) { 115 fs.readdir(pathUtils.join(__dirname, '../../test1/uploads/'), function (err, files) {
117 if (err) throw err 116 if (err) throw err
118 117
119 expect(files.length).to.equal(0) 118 expect(files.length).to.equal(0)
120 done() 119 done()
121 })
122 }) 120 })
123 }) 121 })
122 })
124 123
125 it('Should not have videos', function (done) { 124 it('Should not have videos', function (done) {
126 utils.getVideosList(url, function (err, res) { 125 utils.getVideosList(url, function (err, res) {
127 if (err) throw err 126 if (err) throw err
128 127
129 expect(res.body).to.be.an('array') 128 expect(res.body).to.be.an('array')
130 expect(res.body.length).to.equal(0) 129 expect(res.body.length).to.equal(0)
131 130
132 done() 131 done()
133 })
134 }) 132 })
133 })
135 134
136 after(function (done) { 135 after(function (done) {
137 process.kill(-app.pid) 136 process.kill(-app.pid)
138 process.kill(-webtorrent.app.pid) 137 process.kill(-webtorrent.app.pid)
139 138
140 // Keep the logs if the test failed 139 // Keep the logs if the test failed
141 if (this.ok) { 140 if (this.ok) {
142 utils.flushTests(done) 141 utils.flushTests(done)
143 } else { 142 } else {
144 done() 143 done()
145 } 144 }
146 })
147 }) 145 })
148})() 146})
diff --git a/tests/api/utils.js b/tests/api/utils.js
index b71e943ed..47b706294 100644
--- a/tests/api/utils.js
+++ b/tests/api/utils.js
@@ -1,187 +1,185 @@
1;(function () { 1'use strict'
2 'use strict' 2
3 3var child_process = require('child_process')
4 var child_process = require('child_process') 4var exec = child_process.exec
5 var exec = child_process.exec 5var fork = child_process.fork
6 var fork = child_process.fork 6var pathUtils = require('path')
7 var pathUtils = require('path') 7var request = require('supertest')
8 var request = require('supertest') 8
9 9var testUtils = {
10 var testUtils = { 10 flushTests: flushTests,
11 flushTests: flushTests, 11 getFriendsList: getFriendsList,
12 getFriendsList: getFriendsList, 12 getVideosList: getVideosList,
13 getVideosList: getVideosList, 13 makeFriends: makeFriends,
14 makeFriends: makeFriends, 14 quitFriends: quitFriends,
15 quitFriends: quitFriends, 15 removeVideo: removeVideo,
16 removeVideo: removeVideo, 16 flushAndRunMultipleServers: flushAndRunMultipleServers,
17 flushAndRunMultipleServers: flushAndRunMultipleServers, 17 runServer: runServer,
18 runServer: runServer, 18 searchVideo: searchVideo,
19 searchVideo: searchVideo, 19 uploadVideo: uploadVideo
20 uploadVideo: uploadVideo 20}
21
22// ---------------------- Export functions --------------------
23
24function flushTests (callback) {
25 exec(pathUtils.join(__dirname, '../../scripts/clean_test.sh'), callback)
26}
27
28function getFriendsList (url, end) {
29 var path = '/api/v1/pods/'
30
31 request(url)
32 .get(path)
33 .set('Accept', 'application/json')
34 .expect(200)
35 .expect('Content-Type', /json/)
36 .end(end)
37}
38
39function getVideosList (url, end) {
40 var path = '/api/v1/videos'
41
42 request(url)
43 .get(path)
44 .set('Accept', 'application/json')
45 .expect(200)
46 .expect('Content-Type', /json/)
47 .end(end)
48}
49
50function makeFriends (url, expected_status, callback) {
51 if (!callback) {
52 callback = expected_status
53 expected_status = 204
21 } 54 }
22 55
23 // ---------------------- Export functions -------------------- 56 var path = '/api/v1/pods/makefriends'
24 57
25 function flushTests (callback) { 58 // The first pod make friend with the third
26 exec(pathUtils.join(__dirname, '../../scripts/clean_test.sh'), callback) 59 request(url)
27 } 60 .get(path)
28 61 .set('Accept', 'application/json')
29 function getFriendsList (url, end) { 62 .expect(expected_status)
30 var path = '/api/v1/pods/' 63 .end(function (err, res) {
31 64 if (err) throw err
32 request(url)
33 .get(path)
34 .set('Accept', 'application/json')
35 .expect(200)
36 .expect('Content-Type', /json/)
37 .end(end)
38 }
39
40 function getVideosList (url, end) {
41 var path = '/api/v1/videos'
42
43 request(url)
44 .get(path)
45 .set('Accept', 'application/json')
46 .expect(200)
47 .expect('Content-Type', /json/)
48 .end(end)
49 }
50
51 function makeFriends (url, expected_status, callback) {
52 if (!callback) {
53 callback = expected_status
54 expected_status = 204
55 }
56
57 var path = '/api/v1/pods/makefriends'
58
59 // The first pod make friend with the third
60 request(url)
61 .get(path)
62 .set('Accept', 'application/json')
63 .expect(expected_status)
64 .end(function (err, res) {
65 if (err) throw err
66
67 // Wait for the request between pods
68 setTimeout(callback, 1000)
69 })
70 }
71
72 function quitFriends (url, callback) {
73 var path = '/api/v1/pods/quitfriends'
74 65
75 // The first pod make friend with the third 66 // Wait for the request between pods
76 request(url) 67 setTimeout(callback, 1000)
77 .get(path)
78 .set('Accept', 'application/json')
79 .expect(204)
80 .end(function (err, res) {
81 if (err) throw err
82
83 // Wait for the request between pods
84 setTimeout(callback, 1000)
85 })
86 }
87
88 function removeVideo (url, id, end) {
89 var path = '/api/v1/videos'
90
91 request(url)
92 .delete(path + '/' + id)
93 .set('Accept', 'application/json')
94 .expect(204)
95 .end(end)
96 }
97
98 function flushAndRunMultipleServers (total_servers, serversRun) {
99 var apps = []
100 var urls = []
101 var i = 0
102
103 function anotherServerDone (number, app, url) {
104 apps[number - 1] = app
105 urls[number - 1] = url
106 i++
107 if (i === total_servers) {
108 serversRun(apps, urls)
109 }
110 }
111
112 flushTests(function () {
113 for (var j = 1; j <= total_servers; j++) {
114 (function (k) { // TODO: ES6 with let
115 // For the virtual buffer
116 setTimeout(function () {
117 runServer(k, function (app, url) {
118 anotherServerDone(k, app, url)
119 })
120 }, 1000 * k)
121 })(j)
122 }
123 }) 68 })
124 } 69}
125 70
126 function runServer (number, callback) { 71function quitFriends (url, callback) {
127 var port = 9000 + number 72 var path = '/api/v1/pods/quitfriends'
128 var server_run_string = {
129 'Connected to mongodb': false,
130 'Server listening on port': false
131 }
132 73
133 // Share the environment 74 // The first pod make friend with the third
134 var env = Object.create(process.env) 75 request(url)
135 env.NODE_ENV = 'test' 76 .get(path)
136 env.NODE_APP_INSTANCE = number 77 .set('Accept', 'application/json')
137 var options = { 78 .expect(204)
138 silent: true, 79 .end(function (err, res) {
139 env: env, 80 if (err) throw err
140 detached: true
141 }
142
143 var app = fork(pathUtils.join(__dirname, '../../server.js'), [], options)
144 app.stdout.on('data', function onStdout (data) {
145 var dont_continue = false
146 // Check if all required sentences are here
147 for (var key of Object.keys(server_run_string)) {
148 if (data.toString().indexOf(key) !== -1) server_run_string[key] = true
149 if (server_run_string[key] === false) dont_continue = true
150 }
151 81
152 // If no, there is maybe one thing not already initialized (mongodb...) 82 // Wait for the request between pods
153 if (dont_continue === true) return 83 setTimeout(callback, 1000)
154
155 app.stdout.removeListener('data', onStdout)
156 callback(app, 'http://localhost:' + port)
157 }) 84 })
85}
86
87function removeVideo (url, id, end) {
88 var path = '/api/v1/videos'
89
90 request(url)
91 .delete(path + '/' + id)
92 .set('Accept', 'application/json')
93 .expect(204)
94 .end(end)
95}
96
97function flushAndRunMultipleServers (total_servers, serversRun) {
98 var apps = []
99 var urls = []
100 var i = 0
101
102 function anotherServerDone (number, app, url) {
103 apps[number - 1] = app
104 urls[number - 1] = url
105 i++
106 if (i === total_servers) {
107 serversRun(apps, urls)
108 }
158 } 109 }
159 110
160 function searchVideo (url, search, end) { 111 flushTests(function () {
161 var path = '/api/v1/videos' 112 for (var j = 1; j <= total_servers; j++) {
162 113 (function (k) { // TODO: ES6 with let
163 request(url) 114 // For the virtual buffer
164 .get(path + '/search/' + search) 115 setTimeout(function () {
165 .set('Accept', 'application/json') 116 runServer(k, function (app, url) {
166 .expect(200) 117 anotherServerDone(k, app, url)
167 .expect('Content-Type', /json/) 118 })
168 .end(end) 119 }, 1000 * k)
120 })(j)
121 }
122 })
123}
124
125function runServer (number, callback) {
126 var port = 9000 + number
127 var server_run_string = {
128 'Connected to mongodb': false,
129 'Server listening on port': false
169 } 130 }
170 131
171 function uploadVideo (url, name, description, fixture, end) { 132 // Share the environment
172 var path = '/api/v1/videos' 133 var env = Object.create(process.env)
173 134 env.NODE_ENV = 'test'
174 request(url) 135 env.NODE_APP_INSTANCE = number
175 .post(path) 136 var options = {
176 .set('Accept', 'application/json') 137 silent: true,
177 .field('name', name) 138 env: env,
178 .field('description', description) 139 detached: true
179 .attach('input_video', pathUtils.join(__dirname, 'fixtures', fixture))
180 .expect(201)
181 .end(end)
182 } 140 }
183 141
184 // --------------------------------------------------------------------------- 142 var app = fork(pathUtils.join(__dirname, '../../server.js'), [], options)
143 app.stdout.on('data', function onStdout (data) {
144 var dont_continue = false
145 // Check if all required sentences are here
146 for (var key of Object.keys(server_run_string)) {
147 if (data.toString().indexOf(key) !== -1) server_run_string[key] = true
148 if (server_run_string[key] === false) dont_continue = true
149 }
185 150
186 module.exports = testUtils 151 // If no, there is maybe one thing not already initialized (mongodb...)
187})() 152 if (dont_continue === true) return
153
154 app.stdout.removeListener('data', onStdout)
155 callback(app, 'http://localhost:' + port)
156 })
157}
158
159function searchVideo (url, search, end) {
160 var path = '/api/v1/videos'
161
162 request(url)
163 .get(path + '/search/' + search)
164 .set('Accept', 'application/json')
165 .expect(200)
166 .expect('Content-Type', /json/)
167 .end(end)
168}
169
170function uploadVideo (url, name, description, fixture, end) {
171 var path = '/api/v1/videos'
172
173 request(url)
174 .post(path)
175 .set('Accept', 'application/json')
176 .field('name', name)
177 .field('description', description)
178 .attach('input_video', pathUtils.join(__dirname, 'fixtures', fixture))
179 .expect(201)
180 .end(end)
181}
182
183// ---------------------------------------------------------------------------
184
185module.exports = testUtils