aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/api
diff options
context:
space:
mode:
Diffstat (limited to 'test/api')
-rw-r--r--test/api/friendsAdvanced.js88
-rw-r--r--test/api/friendsBasic.js90
-rw-r--r--test/api/multiplePods.js4
-rw-r--r--test/api/utils.js28
4 files changed, 170 insertions, 40 deletions
diff --git a/test/api/friendsAdvanced.js b/test/api/friendsAdvanced.js
index a638eb0d4..b24cd39c3 100644
--- a/test/api/friendsAdvanced.js
+++ b/test/api/friendsAdvanced.js
@@ -1,6 +1,7 @@
1;(function () { 1;(function () {
2 'use strict' 2 'use strict'
3 3
4 var async = require('async')
4 var chai = require('chai') 5 var chai = require('chai')
5 var expect = chai.expect 6 var expect = chai.expect
6 7
@@ -10,8 +11,12 @@
10 var apps = [] 11 var apps = []
11 var urls = [] 12 var urls = []
12 13
13 function makeFriend (pod_number, callback) { 14 function makeFriends (pod_number, callback) {
14 return utils.makeFriend(urls[pod_number - 1], callback) 15 return utils.makeFriends(urls[pod_number - 1], callback)
16 }
17
18 function quitFriends (pod_number, callback) {
19 return utils.quitFriends(urls[pod_number - 1], callback)
15 } 20 }
16 21
17 function getFriendsList (pod_number, end) { 22 function getFriendsList (pod_number, end) {
@@ -26,7 +31,11 @@
26 return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback) 31 return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback)
27 } 32 }
28 33
29 beforeEach(function (done) { 34 function getVideos (pod_number, callback) {
35 return utils.getVideosList(urls[pod_number - 1], callback)
36 }
37
38 before(function (done) {
30 this.timeout(30000) 39 this.timeout(30000)
31 utils.runMultipleServers(6, function (apps_run, urls_run) { 40 utils.runMultipleServers(6, function (apps_run, urls_run) {
32 apps = apps_run 41 apps = apps_run
@@ -35,7 +44,7 @@
35 }) 44 })
36 }) 45 })
37 46
38 afterEach(function (done) { 47 after(function (done) {
39 apps.forEach(function (app) { 48 apps.forEach(function (app) {
40 process.kill(-app.pid) 49 process.kill(-app.pid)
41 }) 50 })
@@ -53,11 +62,11 @@
53 this.timeout(20000) 62 this.timeout(20000)
54 63
55 // Pod 3 makes friend with the first one 64 // Pod 3 makes friend with the first one
56 makeFriend(3, function () { 65 makeFriends(3, function () {
57 // Pod 4 makes friend with the second one 66 // Pod 4 makes friend with the second one
58 makeFriend(4, function () { 67 makeFriends(4, function () {
59 // Now if the fifth wants to make friends with the third et the first 68 // Now if the fifth wants to make friends with the third et the first
60 makeFriend(5, function () { 69 makeFriends(5, function () {
61 setTimeout(function () { 70 setTimeout(function () {
62 // It should have 0 friends 71 // It should have 0 friends
63 getFriendsList(5, function (err, res) { 72 getFriendsList(5, function (err, res) {
@@ -73,13 +82,30 @@
73 }) 82 })
74 }) 83 })
75 84
85 it('Should quit all friends', function (done) {
86 this.timeout(10000)
87 quitFriends(1, function () {
88 quitFriends(2, function () {
89 async.each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) {
90 getFriendsList(i, function (err, res) {
91 if (err) throw err
92 expect(res.body.length).to.equal(0)
93 callback()
94 })
95 }, function () {
96 done()
97 })
98 })
99 })
100 })
101
76 it('Should make friends with the pods 1, 2, 3', function (done) { 102 it('Should make friends with the pods 1, 2, 3', function (done) {
77 this.timeout(150000) 103 this.timeout(150000)
78 104
79 // Pods 1, 2, 3 and 4 become friends (yes this is beautiful) 105 // Pods 1, 2, 3 and 4 become friends (yes this is beautiful)
80 makeFriend(2, function () { 106 makeFriends(2, function () {
81 makeFriend(1, function () { 107 makeFriends(1, function () {
82 makeFriend(4, function () { 108 makeFriends(4, function () {
83 // Kill the server 4 109 // Kill the server 4
84 apps[3].kill() 110 apps[3].kill()
85 111
@@ -99,7 +125,7 @@
99 expect(res.body.length).to.equal(3) 125 expect(res.body.length).to.equal(3)
100 126
101 // Pod 6 ask pod 1, 2 and 3 127 // Pod 6 ask pod 1, 2 and 3
102 makeFriend(6, function () { 128 makeFriends(6, function () {
103 getFriendsList(6, function (err, res) { 129 getFriendsList(6, function (err, res) {
104 if (err) throw err 130 if (err) throw err
105 131
@@ -125,5 +151,45 @@
125 }) 151 })
126 }) 152 })
127 }) 153 })
154
155 it('Should pod 1 quit friends', function (done) {
156 this.timeout(25000)
157 // Upload a video on server 3 for aditionnal tests
158 uploadVideo(3, function () {
159 setTimeout(function () {
160 quitFriends(1, function () {
161 // Remove pod 1 from pod 2
162 getVideos(1, function (err, res) {
163 if (err) throw err
164 expect(res.body).to.be.an('array')
165 expect(res.body.length).to.equal(2)
166
167 getVideos(2, function (err, res) {
168 if (err) throw err
169 expect(res.body).to.be.an('array')
170 expect(res.body.length).to.equal(3)
171 done()
172 })
173 })
174 })
175 }, 15000)
176 })
177 })
178
179 it('Should make friends between pod 1 and 2 and exchange their videos', function (done) {
180 this.timeout(20000)
181 makeFriends(1, function () {
182 setTimeout(function () {
183 getVideos(1, function (err, res) {
184 if (err) throw err
185
186 expect(res.body).to.be.an('array')
187 expect(res.body.length).to.equal(5)
188
189 done()
190 })
191 }, 5000)
192 })
193 })
128 }) 194 })
129})() 195})()
diff --git a/test/api/friendsBasic.js b/test/api/friendsBasic.js
index 43ec41633..15b83d421 100644
--- a/test/api/friendsBasic.js
+++ b/test/api/friendsBasic.js
@@ -9,6 +9,29 @@
9 var utils = require('./utils') 9 var utils = require('./utils')
10 10
11 describe('Test basic friends', function () { 11 describe('Test basic friends', function () {
12 function testMadeFriends (urls, url_to_test, callback) {
13 var friends = []
14 for (var i = 0; i < urls.length; i++) {
15 if (urls[i] === url_to_test) continue
16 friends.push(urls[i])
17 }
18
19 utils.getFriendsList(url_to_test, function (err, res) {
20 if (err) throw err
21
22 var result = res.body
23 var result_urls = [ result[0].url, result[1].url ]
24 expect(result).to.be.an('array')
25 expect(result.length).to.equal(2)
26 expect(result_urls[0]).to.not.equal(result_urls[1])
27
28 var error_string = 'Friends url do not correspond for ' + url_to_test
29 expect(friends).to.contain(result_urls[0], error_string)
30 expect(friends).to.contain(result_urls[1], error_string)
31 callback()
32 })
33 }
34
12 var apps = [] 35 var apps = []
13 var urls = [] 36 var urls = []
14 37
@@ -41,29 +64,6 @@
41 it('Should make friends', function (done) { 64 it('Should make friends', function (done) {
42 this.timeout(10000) 65 this.timeout(10000)
43 66
44 function testMadeFriends (urls, url_to_test, callback) {
45 var friends = []
46 for (var i = 0; i < urls.length; i++) {
47 if (urls[i] === url_to_test) continue
48 friends.push(urls[i])
49 }
50
51 utils.getFriendsList(url_to_test, function (err, res) {
52 if (err) throw err
53
54 var result = res.body
55 var result_urls = [ result[0].url, result[1].url ]
56 expect(result).to.be.an('array')
57 expect(result.length).to.equal(2)
58 expect(result_urls[0]).to.not.equal(result_urls[1])
59
60 var error_string = 'Friends url do not correspond for ' + url_to_test
61 expect(friends).to.contain(result_urls[0], error_string)
62 expect(friends).to.contain(result_urls[1], error_string)
63 callback()
64 })
65 }
66
67 var path = '/api/v1/pods/makefriends' 67 var path = '/api/v1/pods/makefriends'
68 68
69 // The second pod make friend with the third 69 // The second pod make friend with the third
@@ -118,8 +118,48 @@
118 }) 118 })
119 }) 119 })
120 120
121 // TODO 121 it('Should not be allowed to make friend again', function (done) {
122 it('Should not be able to make friends again') 122 utils.makeFriends(urls[1], 409, done)
123 })
124
125 it('Should quit friends of pod 2', function (done) {
126 utils.quitFriends(urls[1], function () {
127 utils.getFriendsList(urls[1], function (err, res) {
128 if (err) throw err
129
130 var result = res.body
131 expect(result).to.be.an('array')
132 expect(result.length).to.equal(0)
133
134 // Other pods shouldn't have pod 2 too
135 async.each([ urls[0], urls[2] ], function (url, callback) {
136 utils.getFriendsList(url, function (err, res) {
137 if (err) throw err
138
139 var result = res.body
140 expect(result).to.be.an('array')
141 expect(result.length).to.equal(1)
142 expect(result[0].url).not.to.be.equal(urls[1])
143 callback()
144 })
145 }, function (err) {
146 if (err) throw err
147 done()
148 })
149 })
150 })
151 })
152
153 it('Should allow pod 2 to make friend again', function (done) {
154 utils.makeFriends(urls[1], function () {
155 async.each(urls, function (url, callback) {
156 testMadeFriends(urls, url, callback)
157 }, function (err) {
158 if (err) throw err
159 done()
160 })
161 })
162 })
123 163
124 after(function (done) { 164 after(function (done) {
125 apps.forEach(function (app) { 165 apps.forEach(function (app) {
diff --git a/test/api/multiplePods.js b/test/api/multiplePods.js
index a831e0fa6..531e1ef33 100644
--- a/test/api/multiplePods.js
+++ b/test/api/multiplePods.js
@@ -22,12 +22,12 @@
22 urls = urls_run 22 urls = urls_run
23 23
24 // The second pod make friend with the third 24 // The second pod make friend with the third
25 utils.makeFriend(urls[1], function (err, res) { 25 utils.makeFriends(urls[1], function (err, res) {
26 if (err) throw err 26 if (err) throw err
27 27
28 // Wait for the request between pods 28 // Wait for the request between pods
29 setTimeout(function () { 29 setTimeout(function () {
30 utils.makeFriend(urls[0], function (err, res) { 30 utils.makeFriends(urls[0], function (err, res) {
31 if (err) throw err 31 if (err) throw err
32 32
33 webtorrent.create({ host: 'client', port: '1' }, function () { 33 webtorrent.create({ host: 'client', port: '1' }, function () {
diff --git a/test/api/utils.js b/test/api/utils.js
index 8d059b01c..b00890539 100644
--- a/test/api/utils.js
+++ b/test/api/utils.js
@@ -34,13 +34,36 @@
34 .end(end) 34 .end(end)
35 } 35 }
36 36
37 function makeFriend (url, callback) { 37 function makeFriends (url, expected_status, callback) {
38 if (!callback) {
39 callback = expected_status
40 expected_status = 204
41 }
42
38 var path = '/api/v1/pods/makefriends' 43 var path = '/api/v1/pods/makefriends'
39 44
40 // The first pod make friend with the third 45 // The first pod make friend with the third
41 request(url) 46 request(url)
42 .get(path) 47 .get(path)
43 .set('Accept', 'application/json') 48 .set('Accept', 'application/json')
49 .expect(expected_status)
50 .end(function (err, res) {
51 if (err) throw err
52
53 // Wait for the request between pods
54 setTimeout(function () {
55 callback()
56 }, 1000)
57 })
58 }
59
60 function quitFriends (url, callback) {
61 var path = '/api/v1/pods/quitfriends'
62
63 // The first pod make friend with the third
64 request(url)
65 .get(path)
66 .set('Accept', 'application/json')
44 .expect(204) 67 .expect(204)
45 .end(function (err, res) { 68 .end(function (err, res) {
46 if (err) throw err 69 if (err) throw err
@@ -152,7 +175,8 @@
152 flushTests: flushTests, 175 flushTests: flushTests,
153 getFriendsList: getFriendsList, 176 getFriendsList: getFriendsList,
154 getVideosList: getVideosList, 177 getVideosList: getVideosList,
155 makeFriend: makeFriend, 178 makeFriends: makeFriends,
179 quitFriends: quitFriends,
156 removeVideo: removeVideo, 180 removeVideo: removeVideo,
157 runMultipleServers: runMultipleServers, 181 runMultipleServers: runMultipleServers,
158 runServer: runServer, 182 runServer: runServer,