diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-04-14 22:06:11 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-04-14 22:06:11 +0200 |
commit | 0c1cbbfe29d91c95f9c574b57adf067654b8b5b4 (patch) | |
tree | b61e48caedea8881cbfd1159295f6c311b35be90 /server/tests/api/friendsBasic.js | |
parent | c9bf7d30bd688e84b12dca03029dde6e9645a997 (diff) | |
download | PeerTube-0c1cbbfe29d91c95f9c574b57adf067654b8b5b4.tar.gz PeerTube-0c1cbbfe29d91c95f9c574b57adf067654b8b5b4.tar.zst PeerTube-0c1cbbfe29d91c95f9c574b57adf067654b8b5b4.zip |
Add authentications for routes that need it and adapts the tests
Diffstat (limited to 'server/tests/api/friendsBasic.js')
-rw-r--r-- | server/tests/api/friendsBasic.js | 60 |
1 files changed, 29 insertions, 31 deletions
diff --git a/server/tests/api/friendsBasic.js b/server/tests/api/friendsBasic.js index 62eac51ec..49e51804f 100644 --- a/server/tests/api/friendsBasic.js +++ b/server/tests/api/friendsBasic.js | |||
@@ -8,17 +8,16 @@ const request = require('supertest') | |||
8 | const utils = require('./utils') | 8 | const utils = require('./utils') |
9 | 9 | ||
10 | describe('Test basic friends', function () { | 10 | describe('Test basic friends', function () { |
11 | let apps = [] | 11 | let servers = [] |
12 | let urls = [] | ||
13 | 12 | ||
14 | function testMadeFriends (urls, url_to_test, callback) { | 13 | function testMadeFriends (servers, server_to_test, callback) { |
15 | const friends = [] | 14 | const friends = [] |
16 | for (let i = 0; i < urls.length; i++) { | 15 | for (let i = 0; i < servers.length; i++) { |
17 | if (urls[i] === url_to_test) continue | 16 | if (servers[i].url === server_to_test.url) continue |
18 | friends.push(urls[i]) | 17 | friends.push(servers[i].url) |
19 | } | 18 | } |
20 | 19 | ||
21 | utils.getFriendsList(url_to_test, function (err, res) { | 20 | utils.getFriendsList(server_to_test.url, function (err, res) { |
22 | if (err) throw err | 21 | if (err) throw err |
23 | 22 | ||
24 | const result = res.body | 23 | const result = res.body |
@@ -27,7 +26,7 @@ describe('Test basic friends', function () { | |||
27 | expect(result.length).to.equal(2) | 26 | expect(result.length).to.equal(2) |
28 | expect(result_urls[0]).to.not.equal(result_urls[1]) | 27 | expect(result_urls[0]).to.not.equal(result_urls[1]) |
29 | 28 | ||
30 | const error_string = 'Friends url do not correspond for ' + url_to_test | 29 | const error_string = 'Friends url do not correspond for ' + server_to_test.url |
31 | expect(friends).to.contain(result_urls[0], error_string) | 30 | expect(friends).to.contain(result_urls[0], error_string) |
32 | expect(friends).to.contain(result_urls[1], error_string) | 31 | expect(friends).to.contain(result_urls[1], error_string) |
33 | callback() | 32 | callback() |
@@ -38,16 +37,15 @@ describe('Test basic friends', function () { | |||
38 | 37 | ||
39 | before(function (done) { | 38 | before(function (done) { |
40 | this.timeout(20000) | 39 | this.timeout(20000) |
41 | utils.flushAndRunMultipleServers(3, function (apps_run, urls_run) { | 40 | utils.flushAndRunMultipleServers(3, function (servers_run, urls_run) { |
42 | apps = apps_run | 41 | servers = servers_run |
43 | urls = urls_run | ||
44 | done() | 42 | done() |
45 | }) | 43 | }) |
46 | }) | 44 | }) |
47 | 45 | ||
48 | it('Should not have friends', function (done) { | 46 | it('Should not have friends', function (done) { |
49 | async.each(urls, function (url, callback) { | 47 | async.each(servers, function (server, callback) { |
50 | utils.getFriendsList(url, function (err, res) { | 48 | utils.getFriendsList(server.url, function (err, res) { |
51 | if (err) throw err | 49 | if (err) throw err |
52 | 50 | ||
53 | const result = res.body | 51 | const result = res.body |
@@ -66,7 +64,7 @@ describe('Test basic friends', function () { | |||
66 | async.series([ | 64 | async.series([ |
67 | // The second pod make friend with the third | 65 | // The second pod make friend with the third |
68 | function (next) { | 66 | function (next) { |
69 | request(urls[1]) | 67 | request(servers[1].url) |
70 | .get(path) | 68 | .get(path) |
71 | .set('Accept', 'application/json') | 69 | .set('Accept', 'application/json') |
72 | .expect(204) | 70 | .expect(204) |
@@ -78,33 +76,33 @@ describe('Test basic friends', function () { | |||
78 | }, | 76 | }, |
79 | // The second pod should have the third as a friend | 77 | // The second pod should have the third as a friend |
80 | function (next) { | 78 | function (next) { |
81 | utils.getFriendsList(urls[1], function (err, res) { | 79 | utils.getFriendsList(servers[1].url, function (err, res) { |
82 | if (err) throw err | 80 | if (err) throw err |
83 | 81 | ||
84 | const result = res.body | 82 | const result = res.body |
85 | expect(result).to.be.an('array') | 83 | expect(result).to.be.an('array') |
86 | expect(result.length).to.equal(1) | 84 | expect(result.length).to.equal(1) |
87 | expect(result[0].url).to.be.equal(urls[2]) | 85 | expect(result[0].url).to.be.equal(servers[2].url) |
88 | 86 | ||
89 | next() | 87 | next() |
90 | }) | 88 | }) |
91 | }, | 89 | }, |
92 | // Same here, the third pod should have the second pod as a friend | 90 | // Same here, the third pod should have the second pod as a friend |
93 | function (next) { | 91 | function (next) { |
94 | utils.getFriendsList(urls[2], function (err, res) { | 92 | utils.getFriendsList(servers[2].url, function (err, res) { |
95 | if (err) throw err | 93 | if (err) throw err |
96 | 94 | ||
97 | const result = res.body | 95 | const result = res.body |
98 | expect(result).to.be.an('array') | 96 | expect(result).to.be.an('array') |
99 | expect(result.length).to.equal(1) | 97 | expect(result.length).to.equal(1) |
100 | expect(result[0].url).to.be.equal(urls[1]) | 98 | expect(result[0].url).to.be.equal(servers[1].url) |
101 | 99 | ||
102 | next() | 100 | next() |
103 | }) | 101 | }) |
104 | }, | 102 | }, |
105 | // Finally the first pod make friend with the second pod | 103 | // Finally the first pod make friend with the second pod |
106 | function (next) { | 104 | function (next) { |
107 | request(urls[0]) | 105 | request(servers[0].url) |
108 | .get(path) | 106 | .get(path) |
109 | .set('Accept', 'application/json') | 107 | .set('Accept', 'application/json') |
110 | .expect(204) | 108 | .expect(204) |
@@ -118,25 +116,25 @@ describe('Test basic friends', function () { | |||
118 | // Now each pod should be friend with the other ones | 116 | // Now each pod should be friend with the other ones |
119 | function (err) { | 117 | function (err) { |
120 | if (err) throw err | 118 | if (err) throw err |
121 | async.each(urls, function (url, callback) { | 119 | async.each(servers, function (server, callback) { |
122 | testMadeFriends(urls, url, callback) | 120 | testMadeFriends(servers, server, callback) |
123 | }, done) | 121 | }, done) |
124 | }) | 122 | }) |
125 | }) | 123 | }) |
126 | 124 | ||
127 | it('Should not be allowed to make friend again', function (done) { | 125 | it('Should not be allowed to make friend again', function (done) { |
128 | utils.makeFriends(urls[1], 409, done) | 126 | utils.makeFriends(servers[1].url, 409, done) |
129 | }) | 127 | }) |
130 | 128 | ||
131 | it('Should quit friends of pod 2', function (done) { | 129 | it('Should quit friends of pod 2', function (done) { |
132 | async.series([ | 130 | async.series([ |
133 | // Pod 1 quit friends | 131 | // Pod 1 quit friends |
134 | function (next) { | 132 | function (next) { |
135 | utils.quitFriends(urls[1], next) | 133 | utils.quitFriends(servers[1].url, next) |
136 | }, | 134 | }, |
137 | // Pod 1 should not have friends anymore | 135 | // Pod 1 should not have friends anymore |
138 | function (next) { | 136 | function (next) { |
139 | utils.getFriendsList(urls[1], function (err, res) { | 137 | utils.getFriendsList(servers[1].url, function (err, res) { |
140 | if (err) throw err | 138 | if (err) throw err |
141 | 139 | ||
142 | const result = res.body | 140 | const result = res.body |
@@ -148,14 +146,14 @@ describe('Test basic friends', function () { | |||
148 | }, | 146 | }, |
149 | // Other pods shouldn't have pod 1 too | 147 | // Other pods shouldn't have pod 1 too |
150 | function (next) { | 148 | function (next) { |
151 | async.each([ urls[0], urls[2] ], function (url, callback) { | 149 | async.each([ servers[0].url, servers[2].url ], function (url, callback) { |
152 | utils.getFriendsList(url, function (err, res) { | 150 | utils.getFriendsList(url, function (err, res) { |
153 | if (err) throw err | 151 | if (err) throw err |
154 | 152 | ||
155 | const result = res.body | 153 | const result = res.body |
156 | expect(result).to.be.an('array') | 154 | expect(result).to.be.an('array') |
157 | expect(result.length).to.equal(1) | 155 | expect(result.length).to.equal(1) |
158 | expect(result[0].url).not.to.be.equal(urls[1]) | 156 | expect(result[0].url).not.to.be.equal(servers[1].url) |
159 | callback() | 157 | callback() |
160 | }) | 158 | }) |
161 | }, next) | 159 | }, next) |
@@ -164,16 +162,16 @@ describe('Test basic friends', function () { | |||
164 | }) | 162 | }) |
165 | 163 | ||
166 | it('Should allow pod 2 to make friend again', function (done) { | 164 | it('Should allow pod 2 to make friend again', function (done) { |
167 | utils.makeFriends(urls[1], function () { | 165 | utils.makeFriends(servers[1].url, function () { |
168 | async.each(urls, function (url, callback) { | 166 | async.each(servers, function (server, callback) { |
169 | testMadeFriends(urls, url, callback) | 167 | testMadeFriends(servers, server, callback) |
170 | }, done) | 168 | }, done) |
171 | }) | 169 | }) |
172 | }) | 170 | }) |
173 | 171 | ||
174 | after(function (done) { | 172 | after(function (done) { |
175 | apps.forEach(function (app) { | 173 | servers.forEach(function (server) { |
176 | process.kill(-app.pid) | 174 | process.kill(-server.app.pid) |
177 | }) | 175 | }) |
178 | 176 | ||
179 | if (this.ok) { | 177 | if (this.ok) { |