]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/friends-advanced.js
1 /* eslint-disable no-unused-expressions */
5 const chai
= require('chai')
6 const each
= require('async/each')
7 const expect
= chai
.expect
8 const series
= require('async/series')
10 const loginUtils
= require('../utils/login')
11 const podsUtils
= require('../utils/pods')
12 const serversUtils
= require('../utils/servers')
13 const videosUtils
= require('../utils/videos')
15 describe('Test advanced friends', function () {
18 function makeFriends (podNumber
, callback
) {
19 const server
= servers
[podNumber
- 1]
20 return podsUtils
.makeFriends(server
.url
, server
.accessToken
, callback
)
23 function quitFriends (podNumber
, callback
) {
24 const server
= servers
[podNumber
- 1]
25 return podsUtils
.quitFriends(server
.url
, server
.accessToken
, callback
)
28 function removeFriend (podNumber
, podNumberToRemove
, callback
) {
29 const server
= servers
[podNumber
- 1]
30 const serverToRemove
= servers
[podNumberToRemove
- 1]
32 getFriendsList(podNumber
, function (err
, res
) {
35 let friendsList
= res
.body
.data
36 let podToRemove
= friendsList
.find((friend
) => (friend
.host
=== serverToRemove
.host
))
38 return podsUtils
.quitOneFriend(server
.url
, server
.accessToken
, podToRemove
.id
, callback
)
42 function getFriendsList (podNumber
, end
) {
43 const server
= servers
[podNumber
- 1]
44 return podsUtils
.getFriendsList(server
.url
, end
)
47 function uploadVideo (podNumber
, callback
) {
48 const videoAttributes
= {
49 tags: [ 'tag1', 'tag2' ]
51 const server
= servers
[podNumber
- 1]
53 return videosUtils
.uploadVideo(server
.url
, server
.accessToken
, videoAttributes
, callback
)
56 function getVideos (podNumber
, callback
) {
57 return videosUtils
.getVideosList(servers
[podNumber
- 1].url
, callback
)
60 // ---------------------------------------------------------------
62 before(function (done
) {
64 serversUtils
.flushAndRunMultipleServers(6, function (serversRun
, urlsRun
) {
67 each(servers
, function (server
, callbackEach
) {
68 loginUtils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
69 if (err
) return callbackEach(err
)
71 server
.accessToken
= accessToken
78 it('Should make friends with two pod each in a different group', function (done
) {
82 // Pod 3 makes friend with the first one
86 // Pod 4 makes friend with the second one
90 // Now if the fifth wants to make friends with the third et the first
95 setTimeout(next
, 11000)
100 // It should have 0 friends
101 getFriendsList(5, function (err
, res
) {
104 expect(res
.body
.data
.length
).to
.equal(0)
112 it('Should quit all friends', function (done
) {
125 each([ 1, 2, 3, 4, 5, 6 ], function (i
, callback
) {
126 getFriendsList(i
, function (err
, res
) {
129 expect(res
.body
.data
.length
).to
.equal(0)
138 it('Should make friends with the pods 1, 2, 3', function (done
) {
142 // Pods 1, 2, 3 and 4 become friends
152 // Check the pods 1, 2, 3 and 4 are friends
154 each([ 1, 2, 3, 4 ], function (i
, callback
) {
155 getFriendsList(i
, function (err
, res
) {
158 expect(res
.body
.data
.length
).to
.equal(3)
166 servers
[3].app
.kill()
169 // Expulse pod 4 from pod 1 and 2
177 setTimeout(next
, 11000)
186 setTimeout(next
, 22000)
188 // Check the pods 1, 2 expulsed pod 4
190 each([ 1, 2 ], function (i
, callback
) {
191 getFriendsList(i
, function (err
, res
) {
194 // Pod 4 should not be our friend
195 const result
= res
.body
.data
196 expect(result
.length
).to
.equal(2)
197 for (const pod
of result
) {
198 expect(pod
.host
).not
.equal(servers
[3].host
)
207 serversUtils
.runServer(4, function (server
) {
208 servers
[3].app
= server
.app
213 getFriendsList(4, function (err
, res
) {
216 // Pod 4 didn't know pod 1 and 2 removed it
217 expect(res
.body
.data
.length
).to
.equal(3)
221 // Pod 6 asks pod 1, 2 and 3
226 setTimeout(next
, 11000)
231 getFriendsList(6, function (err
, res
) {
234 // Pod 4 should not be our friend
235 const result
= res
.body
.data
236 expect(result
.length
).to
.equal(3)
237 for (const pod
of result
) {
238 expect(pod
.host
).not
.equal(servers
[3].host
)
247 it('Should pod 1 quit friends', function (done
) {
251 // Upload a video on server 3 for aditionnal tests
256 setTimeout(next
, 15000)
261 // Remove pod 1 from pod 2
263 getVideos(1, function (err
, res
) {
266 const videos
= res
.body
.data
267 expect(videos
).to
.be
.an('array')
268 expect(videos
.length
).to
.equal(2)
276 getVideos(2, function (err
, res
) {
279 const videos
= res
.body
.data
280 expect(videos
).to
.be
.an('array')
281 expect(videos
.length
).to
.equal(3)
288 it('Should make friends between pod 1 and 2 and exchange their videos', function (done
) {
290 makeFriends(1, function () {
291 setTimeout(function () {
292 getVideos(1, function (err
, res
) {
295 const videos
= res
.body
.data
296 expect(videos
).to
.be
.an('array')
297 expect(videos
.length
).to
.equal(5)
305 it('Should allow pod 6 to quit pod 1 & 2 and be friend with pod 3', function (done
) {
309 // Pod 3 should have 4 friends
311 getFriendsList(3, function (err
, res
) {
314 const friendsList
= res
.body
.data
315 expect(friendsList
).to
.be
.an('array')
316 expect(friendsList
.length
).to
.equal(4)
321 // Pod 1, 2, 6 should have 3 friends each
323 each([ 1, 2, 6 ], function (i
, callback
) {
324 getFriendsList(i
, function (err
, res
) {
327 const friendsList
= res
.body
.data
328 expect(friendsList
).to
.be
.an('array')
329 expect(friendsList
.length
).to
.equal(3)
336 removeFriend(6, 1, next
)
339 removeFriend(6, 2, next
)
341 // Pod 6 should now have only 1 friend (and it should be Pod 3)
343 getFriendsList(6, function (err
, res
) {
346 const friendsList
= res
.body
.data
347 expect(friendsList
).to
.be
.an('array')
348 expect(friendsList
.length
).to
.equal(1)
349 expect(friendsList
[0].host
).to
.equal(servers
[2].host
)
354 // Pod 1 & 2 should not know friend 6 anymore
356 each([ 1, 2 ], function (i
, callback
) {
357 getFriendsList(i
, function (err
, res
) {
360 const friendsList
= res
.body
.data
361 expect(friendsList
).to
.be
.an('array')
362 expect(friendsList
.length
).to
.equal(2)
368 // Pod 3 should know every pod
370 getFriendsList(3, function (err
, res
) {
373 const friendsList
= res
.body
.data
374 expect(friendsList
).to
.be
.an('array')
375 expect(friendsList
.length
).to
.equal(4)
383 after(function (done
) {
384 servers
.forEach(function (server
) {
385 process
.kill(-server
.app
.pid
)
389 serversUtils
.flushTests(done
)