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