diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-01-30 17:05:22 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-01-30 17:05:22 +0100 |
commit | cda021079ff455cc0fd0eb95a5395fa808ab63d1 (patch) | |
tree | 056716de7460462b74b861051a5e9da6e2633fce /tests/api/friendsBasic.js | |
parent | 86435b9baedfe300a28ea4545511c1b50d4119f6 (diff) | |
download | PeerTube-cda021079ff455cc0fd0eb95a5395fa808ab63d1.tar.gz PeerTube-cda021079ff455cc0fd0eb95a5395fa808ab63d1.tar.zst PeerTube-cda021079ff455cc0fd0eb95a5395fa808ab63d1.zip |
New directory organization
Diffstat (limited to 'tests/api/friendsBasic.js')
-rw-r--r-- | tests/api/friendsBasic.js | 187 |
1 files changed, 187 insertions, 0 deletions
diff --git a/tests/api/friendsBasic.js b/tests/api/friendsBasic.js new file mode 100644 index 000000000..dbc918383 --- /dev/null +++ b/tests/api/friendsBasic.js | |||
@@ -0,0 +1,187 @@ | |||
1 | ;(function () { | ||
2 | 'use strict' | ||
3 | |||
4 | var async = require('async') | ||
5 | var chai = require('chai') | ||
6 | var expect = chai.expect | ||
7 | var request = require('supertest') | ||
8 | |||
9 | var utils = require('./utils') | ||
10 | |||
11 | describe('Test basic friends', function () { | ||
12 | var apps = [] | ||
13 | var urls = [] | ||
14 | |||
15 | function testMadeFriends (urls, url_to_test, callback) { | ||
16 | var friends = [] | ||
17 | for (var i = 0; i < urls.length; i++) { | ||
18 | if (urls[i] === url_to_test) continue | ||
19 | friends.push(urls[i]) | ||
20 | } | ||
21 | |||
22 | utils.getFriendsList(url_to_test, function (err, res) { | ||
23 | if (err) throw err | ||
24 | |||
25 | var result = res.body | ||
26 | var result_urls = [ result[0].url, result[1].url ] | ||
27 | expect(result).to.be.an('array') | ||
28 | expect(result.length).to.equal(2) | ||
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() | ||
35 | }) | ||
36 | } | ||
37 | |||
38 | // --------------------------------------------------------------- | ||
39 | |||
40 | before(function (done) { | ||
41 | this.timeout(20000) | ||
42 | utils.flushAndRunMultipleServers(3, function (apps_run, urls_run) { | ||
43 | apps = apps_run | ||
44 | urls = urls_run | ||
45 | done() | ||
46 | }) | ||
47 | }) | ||
48 | |||
49 | it('Should not have friends', function (done) { | ||
50 | async.each(urls, function (url, callback) { | ||
51 | utils.getFriendsList(url, function (err, res) { | ||
52 | if (err) throw err | ||
53 | |||
54 | var result = res.body | ||
55 | expect(result).to.be.an('array') | ||
56 | expect(result.length).to.equal(0) | ||
57 | callback() | ||
58 | }) | ||
59 | }, done) | ||
60 | }) | ||
61 | |||
62 | it('Should make friends', function (done) { | ||
63 | this.timeout(10000) | ||
64 | |||
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 | |||
85 | var result = res.body | ||
86 | expect(result).to.be.an('array') | ||
87 | expect(result.length).to.equal(1) | ||
88 | expect(result[0].url).to.be.equal(urls[2]) | ||
89 | |||
90 | next() | ||
91 | }) | ||
92 | }, | ||
93 | // Same here, the third pod should have the second pod as a friend | ||
94 | function (next) { | ||
95 | utils.getFriendsList(urls[2], function (err, res) { | ||
96 | if (err) throw err | ||
97 | |||
98 | var result = res.body | ||
99 | expect(result).to.be.an('array') | ||
100 | expect(result.length).to.equal(1) | ||
101 | expect(result[0].url).to.be.equal(urls[1]) | ||
102 | |||
103 | next() | ||
104 | }) | ||
105 | }, | ||
106 | // Finally the first pod make friend with the second pod | ||
107 | function (next) { | ||
108 | request(urls[0]) | ||
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 | |||
147 | next() | ||
148 | }) | ||
149 | }, | ||
150 | // Other pods shouldn't have pod 1 too | ||
151 | function (next) { | ||
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 | }) | ||
166 | |||
167 | it('Should allow pod 2 to make friend again', function (done) { | ||
168 | utils.makeFriends(urls[1], function () { | ||
169 | async.each(urls, function (url, callback) { | ||
170 | testMadeFriends(urls, url, callback) | ||
171 | }, done) | ||
172 | }) | ||
173 | }) | ||
174 | |||
175 | after(function (done) { | ||
176 | apps.forEach(function (app) { | ||
177 | process.kill(-app.pid) | ||
178 | }) | ||
179 | |||
180 | if (this.ok) { | ||
181 | utils.flushTests(done) | ||
182 | } else { | ||
183 | done() | ||
184 | } | ||
185 | }) | ||
186 | }) | ||
187 | })() | ||