diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-02-07 11:23:23 +0100 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-02-07 11:23:23 +0100 |
commit | 9f10b2928df655c3672d9607e864e667d4bc903a (patch) | |
tree | 7743911b974b3a7fb0d4c7cec2a723942466b7f1 /tests/api/friendsBasic.js | |
parent | d7c01e7793d813d804a3b5716d8288f9dcf71a16 (diff) | |
download | PeerTube-9f10b2928df655c3672d9607e864e667d4bc903a.tar.gz PeerTube-9f10b2928df655c3672d9607e864e667d4bc903a.tar.zst PeerTube-9f10b2928df655c3672d9607e864e667d4bc903a.zip |
Remove useless anonymous functions of files
Diffstat (limited to 'tests/api/friendsBasic.js')
-rw-r--r-- | tests/api/friendsBasic.js | 300 |
1 files changed, 149 insertions, 151 deletions
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') | 3 | var async = require('async') |
5 | var chai = require('chai') | 4 | var chai = require('chai') |
6 | var expect = chai.expect | 5 | var expect = chai.expect |
7 | var request = require('supertest') | 6 | var request = require('supertest') |
8 | 7 | ||
9 | var utils = require('./utils') | 8 | var utils = require('./utils') |
10 | 9 | ||
11 | describe('Test basic friends', function () { | 10 | describe('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 | }) |