]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/friends-advanced.js
Server: add video abuse support
[github/Chocobozzz/PeerTube.git] / server / tests / api / friends-advanced.js
CommitLineData
9f10b292 1'use strict'
3bcb78b3 2
f0f5567b 3const chai = require('chai')
1a42c9e2 4const each = require('async/each')
f0f5567b 5const expect = chai.expect
1a42c9e2 6const series = require('async/series')
3bcb78b3 7
8d309058
C
8const loginUtils = require('../utils/login')
9const podsUtils = require('../utils/pods')
10const serversUtils = require('../utils/servers')
11const videosUtils = require('../utils/videos')
3bcb78b3 12
9f10b292 13describe('Test advanced friends', function () {
0c1cbbfe 14 let servers = []
3bcb78b3 15
bc503c2a 16 function makeFriends (podNumber, callback) {
b3b92647 17 const server = servers[podNumber - 1]
8d309058 18 return podsUtils.makeFriends(server.url, server.accessToken, callback)
9f10b292 19 }
45239549 20
bc503c2a 21 function quitFriends (podNumber, callback) {
b3b92647 22 const server = servers[podNumber - 1]
8d309058 23 return podsUtils.quitFriends(server.url, server.accessToken, callback)
9f10b292 24 }
3bcb78b3 25
bc503c2a 26 function getFriendsList (podNumber, end) {
b3b92647 27 const server = servers[podNumber - 1]
8d309058 28 return podsUtils.getFriendsList(server.url, end)
9f10b292 29 }
3bcb78b3 30
bc503c2a 31 function uploadVideo (podNumber, callback) {
f0f5567b
C
32 const name = 'my super video'
33 const description = 'my super description'
be587647 34 const tags = [ 'tag1', 'tag2' ]
f0f5567b 35 const fixture = 'video_short.webm'
bc503c2a 36 const server = servers[podNumber - 1]
3bcb78b3 37
8d309058 38 return videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback)
9f10b292 39 }
3bcb78b3 40
bc503c2a 41 function getVideos (podNumber, callback) {
8d309058 42 return videosUtils.getVideosList(servers[podNumber - 1].url, callback)
9f10b292 43 }
45239549 44
9f10b292 45 // ---------------------------------------------------------------
ee66c593 46
9f10b292
C
47 before(function (done) {
48 this.timeout(30000)
8d309058 49 serversUtils.flushAndRunMultipleServers(6, function (serversRun, urlsRun) {
bc503c2a 50 servers = serversRun
0c1cbbfe 51
1a42c9e2 52 each(servers, function (server, callbackEach) {
8d309058 53 loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
bc503c2a 54 if (err) return callbackEach(err)
0c1cbbfe 55
bc503c2a
C
56 server.accessToken = accessToken
57 callbackEach()
0c1cbbfe
C
58 })
59 }, done)
3bcb78b3 60 })
9f10b292 61 })
3bcb78b3 62
9f10b292
C
63 it('Should make friends with two pod each in a different group', function (done) {
64 this.timeout(20000)
65
1a42c9e2 66 series([
9f10b292
C
67 // Pod 3 makes friend with the first one
68 function (next) {
69 makeFriends(3, next)
70 },
71 // Pod 4 makes friend with the second one
72 function (next) {
73 makeFriends(4, next)
74 },
75 // Now if the fifth wants to make friends with the third et the first
76 function (next) {
77 makeFriends(5, next)
78 },
79 function (next) {
80 setTimeout(next, 11000)
81 }],
82 function (err) {
83 if (err) throw err
84
85 // It should have 0 friends
86 getFriendsList(5, function (err, res) {
ee66c593
C
87 if (err) throw err
88
55fa55a9 89 expect(res.body.data.length).to.equal(0)
9f10b292
C
90
91 done()
92 })
93 }
94 )
95 })
96
97 it('Should quit all friends', function (done) {
98 this.timeout(10000)
99
1a42c9e2 100 series([
9f10b292
C
101 function (next) {
102 quitFriends(1, next)
103 },
104 function (next) {
105 quitFriends(2, next)
106 }],
107 function (err) {
108 if (err) throw err
109
1a42c9e2 110 each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) {
9f10b292 111 getFriendsList(i, function (err, res) {
ee66c593
C
112 if (err) throw err
113
55fa55a9 114 expect(res.body.data.length).to.equal(0)
ee66c593 115
9f10b292 116 callback()
3bcb78b3 117 })
9f10b292
C
118 }, done)
119 }
120 )
121 })
3bcb78b3 122
9f10b292
C
123 it('Should make friends with the pods 1, 2, 3', function (done) {
124 this.timeout(150000)
125
1a42c9e2 126 series([
9f10b292
C
127 // Pods 1, 2, 3 and 4 become friends
128 function (next) {
129 makeFriends(2, next)
130 },
131 function (next) {
132 makeFriends(1, next)
133 },
134 function (next) {
135 makeFriends(4, next)
136 },
528a9efa
C
137 // Check the pods 1, 2, 3 and 4 are friends
138 function (next) {
1a42c9e2 139 each([ 1, 2, 3, 4 ], function (i, callback) {
528a9efa
C
140 getFriendsList(i, function (err, res) {
141 if (err) throw err
142
55fa55a9 143 expect(res.body.data.length).to.equal(3)
528a9efa
C
144
145 callback()
146 })
147 }, next)
148 },
9f10b292
C
149 // Kill pod 4
150 function (next) {
0c1cbbfe 151 servers[3].app.kill()
9f10b292
C
152 next()
153 },
154 // Expulse pod 4 from pod 1 and 2
155 function (next) {
156 uploadVideo(1, next)
157 },
158 function (next) {
159 uploadVideo(2, next)
160 },
161 function (next) {
162 setTimeout(next, 11000)
163 },
164 function (next) {
165 uploadVideo(1, next)
166 },
167 function (next) {
168 uploadVideo(2, next)
169 },
170 function (next) {
528a9efa 171 setTimeout(next, 11000)
9f10b292
C
172 },
173 // Rerun server 4
174 function (next) {
8d309058 175 serversUtils.runServer(4, function (server) {
0c1cbbfe 176 servers[3].app = server.app
9f10b292
C
177 next()
178 })
179 },
180 function (next) {
181 getFriendsList(4, function (err, res) {
ee66c593
C
182 if (err) throw err
183
9f10b292 184 // Pod 4 didn't know pod 1 and 2 removed it
55fa55a9 185 expect(res.body.data.length).to.equal(3)
ee66c593 186 next()
9f10b292
C
187 })
188 },
189 // Pod 6 ask pod 1, 2 and 3
190 function (next) {
191 makeFriends(6, next)
528a9efa
C
192 },
193 function (next) {
194 setTimeout(next, 11000)
9f10b292
C
195 }],
196 function (err) {
197 if (err) throw err
198
199 getFriendsList(6, function (err, res) {
ee66c593
C
200 if (err) throw err
201
9f10b292 202 // Pod 4 should not be our friend
55fa55a9 203 const result = res.body.data
9f10b292 204 expect(result.length).to.equal(3)
f0f5567b 205 for (const pod of result) {
a4254ea1 206 expect(pod.host).not.equal(servers[3].host)
9f10b292 207 }
ee66c593 208
9f10b292
C
209 done()
210 })
211 }
212 )
213 })
ee66c593 214
9f10b292
C
215 it('Should pod 1 quit friends', function (done) {
216 this.timeout(25000)
217
1a42c9e2 218 series([
9f10b292
C
219 // Upload a video on server 3 for aditionnal tests
220 function (next) {
221 uploadVideo(3, next)
222 },
223 function (next) {
224 setTimeout(next, 15000)
225 },
226 function (next) {
227 quitFriends(1, next)
228 },
229 // Remove pod 1 from pod 2
230 function (next) {
231 getVideos(1, function (err, res) {
232 if (err) throw err
68ce3ae0
C
233
234 const videos = res.body.data
235 expect(videos).to.be.an('array')
236 expect(videos.length).to.equal(2)
45239549 237
9f10b292
C
238 next()
239 })
240 }],
241 function (err) {
242 if (err) throw err
ee66c593 243
9f10b292 244 getVideos(2, function (err, res) {
ee66c593 245 if (err) throw err
68ce3ae0
C
246
247 const videos = res.body.data
248 expect(videos).to.be.an('array')
249 expect(videos.length).to.equal(3)
9f10b292
C
250 done()
251 })
252 }
253 )
254 })
ee66c593 255
9f10b292
C
256 it('Should make friends between pod 1 and 2 and exchange their videos', function (done) {
257 this.timeout(20000)
258 makeFriends(1, function () {
259 setTimeout(function () {
260 getVideos(1, function (err, res) {
261 if (err) throw err
45239549 262
68ce3ae0
C
263 const videos = res.body.data
264 expect(videos).to.be.an('array')
265 expect(videos.length).to.equal(5)
45239549 266
9f10b292
C
267 done()
268 })
528a9efa 269 }, 11000)
45239549 270 })
9f10b292 271 })
ee66c593 272
9f10b292 273 after(function (done) {
0c1cbbfe
C
274 servers.forEach(function (server) {
275 process.kill(-server.app.pid)
ee66c593 276 })
9f10b292
C
277
278 if (this.ok) {
8d309058 279 serversUtils.flushTests(done)
9f10b292
C
280 } else {
281 done()
282 }
3bcb78b3 283 })
9f10b292 284})