]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - tests/api/friendsAdvanced.js
4 var async
= require('async')
5 var chai
= require('chai')
6 var expect
= chai
.expect
8 var utils
= require('./utils')
10 describe('Test advanced friends', function () {
14 function makeFriends (pod_number
, callback
) {
15 return utils
.makeFriends(urls
[pod_number
- 1], callback
)
18 function quitFriends (pod_number
, callback
) {
19 return utils
.quitFriends(urls
[pod_number
- 1], callback
)
22 function getFriendsList (pod_number
, end
) {
23 return utils
.getFriendsList(urls
[pod_number
- 1], end
)
26 function uploadVideo (pod_number
, callback
) {
27 var name
= 'my super video'
28 var description
= 'my super description'
29 var fixture
= 'video_short.webm'
31 return utils
.uploadVideo(urls
[pod_number
- 1], name
, description
, fixture
, callback
)
34 function getVideos (pod_number
, callback
) {
35 return utils
.getVideosList(urls
[pod_number
- 1], callback
)
38 // ---------------------------------------------------------------
40 before(function (done
) {
42 utils
.flushAndRunMultipleServers(6, function (apps_run
, urls_run
) {
49 it('Should make friends with two pod each in a different group', function (done
) {
53 // Pod 3 makes friend with the first one
57 // Pod 4 makes friend with the second one
61 // Now if the fifth wants to make friends with the third et the first
66 setTimeout(next
, 11000)
71 // It should have 0 friends
72 getFriendsList(5, function (err
, res
) {
75 expect(res
.body
.length
).to
.equal(0)
83 it('Should quit all friends', function (done
) {
96 async
.each([ 1, 2, 3, 4, 5, 6 ], function (i
, callback
) {
97 getFriendsList(i
, function (err
, res
) {
100 expect(res
.body
.length
).to
.equal(0)
109 it('Should make friends with the pods 1, 2, 3', function (done
) {
113 // Pods 1, 2, 3 and 4 become friends
128 // Expulse pod 4 from pod 1 and 2
136 setTimeout(next
, 11000)
145 setTimeout(next
, 20000)
149 utils
.runServer(4, function (app
, url
) {
155 getFriendsList(4, function (err
, res
) {
158 // Pod 4 didn't know pod 1 and 2 removed it
159 expect(res
.body
.length
).to
.equal(3)
164 // Pod 6 ask pod 1, 2 and 3
171 getFriendsList(6, function (err
, res
) {
174 // Pod 4 should not be our friend
175 var result
= res
.body
176 expect(result
.length
).to
.equal(3)
177 for (var pod
of result
) {
178 expect(pod
.url
).not
.equal(urls
[3])
187 it('Should pod 1 quit friends', function (done
) {
191 // Upload a video on server 3 for aditionnal tests
196 setTimeout(next
, 15000)
201 // Remove pod 1 from pod 2
203 getVideos(1, function (err
, res
) {
205 expect(res
.body
).to
.be
.an('array')
206 expect(res
.body
.length
).to
.equal(2)
214 getVideos(2, function (err
, res
) {
216 expect(res
.body
).to
.be
.an('array')
217 expect(res
.body
.length
).to
.equal(3)
224 it('Should make friends between pod 1 and 2 and exchange their videos', function (done
) {
226 makeFriends(1, function () {
227 setTimeout(function () {
228 getVideos(1, function (err
, res
) {
231 expect(res
.body
).to
.be
.an('array')
232 expect(res
.body
.length
).to
.equal(5)
240 after(function (done
) {
241 apps
.forEach(function (app
) {
242 process
.kill(-app
.pid
)
246 utils
.flushTests(done
)