]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/friendsAdvanced.js
3 const async
= require('async')
4 const chai
= require('chai')
5 const expect
= chai
.expect
7 const utils
= require('./utils')
9 describe('Test advanced friends', function () {
12 function makeFriends (pod_number
, callback
) {
13 return utils
.makeFriends(servers
[pod_number
- 1].url
, callback
)
16 function quitFriends (pod_number
, callback
) {
17 return utils
.quitFriends(servers
[pod_number
- 1].url
, callback
)
20 function getFriendsList (pod_number
, end
) {
21 return utils
.getFriendsList(servers
[pod_number
- 1].url
, end
)
24 function uploadVideo (pod_number
, callback
) {
25 const name
= 'my super video'
26 const description
= 'my super description'
27 const fixture
= 'video_short.webm'
28 const server
= servers
[pod_number
- 1]
30 return utils
.uploadVideo(server
.url
, server
.access_token
, name
, description
, fixture
, callback
)
33 function getVideos (pod_number
, callback
) {
34 return utils
.getVideosList(servers
[pod_number
- 1].url
, callback
)
37 // ---------------------------------------------------------------
39 before(function (done
) {
41 utils
.flushAndRunMultipleServers(6, function (servers_run
, urls_run
) {
44 async
.each(servers
, function (server
, callback_each
) {
45 utils
.loginAndGetAccessToken(server
, function (err
, access_token
) {
46 if (err
) return callback_each(err
)
48 server
.access_token
= access_token
55 it('Should make friends with two pod each in a different group', function (done
) {
59 // Pod 3 makes friend with the first one
63 // Pod 4 makes friend with the second one
67 // Now if the fifth wants to make friends with the third et the first
72 setTimeout(next
, 11000)
77 // It should have 0 friends
78 getFriendsList(5, function (err
, res
) {
81 expect(res
.body
.length
).to
.equal(0)
89 it('Should quit all friends', function (done
) {
102 async
.each([ 1, 2, 3, 4, 5, 6 ], function (i
, callback
) {
103 getFriendsList(i
, function (err
, res
) {
106 expect(res
.body
.length
).to
.equal(0)
115 it('Should make friends with the pods 1, 2, 3', function (done
) {
119 // Pods 1, 2, 3 and 4 become friends
131 servers
[3].app
.kill()
134 // Expulse pod 4 from pod 1 and 2
142 setTimeout(next
, 11000)
151 setTimeout(next
, 20000)
155 utils
.runServer(4, function (server
) {
156 servers
[3].app
= server
.app
161 getFriendsList(4, function (err
, res
) {
164 // Pod 4 didn't know pod 1 and 2 removed it
165 expect(res
.body
.length
).to
.equal(3)
169 // Pod 6 ask pod 1, 2 and 3
176 getFriendsList(6, function (err
, res
) {
179 // Pod 4 should not be our friend
180 const result
= res
.body
181 expect(result
.length
).to
.equal(3)
182 for (const pod
of result
) {
183 expect(pod
.url
).not
.equal(servers
[3].url
)
192 it('Should pod 1 quit friends', function (done
) {
196 // Upload a video on server 3 for aditionnal tests
201 setTimeout(next
, 15000)
206 // Remove pod 1 from pod 2
208 getVideos(1, function (err
, res
) {
210 expect(res
.body
).to
.be
.an('array')
211 expect(res
.body
.length
).to
.equal(2)
219 getVideos(2, function (err
, res
) {
221 expect(res
.body
).to
.be
.an('array')
222 expect(res
.body
.length
).to
.equal(3)
229 it('Should make friends between pod 1 and 2 and exchange their videos', function (done
) {
231 makeFriends(1, function () {
232 setTimeout(function () {
233 getVideos(1, function (err
, res
) {
236 expect(res
.body
).to
.be
.an('array')
237 expect(res
.body
.length
).to
.equal(5)
245 after(function (done
) {
246 servers
.forEach(function (server
) {
247 process
.kill(-server
.app
.pid
)
251 utils
.flushTests(done
)