diff options
Diffstat (limited to 'test/api/friendsBasic.js')
-rw-r--r-- | test/api/friendsBasic.js | 90 |
1 files changed, 65 insertions, 25 deletions
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) { |