]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - test/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 before(function (done
) {
40 utils
.runMultipleServers(6, function (apps_run
, urls_run
) {
47 after(function (done
) {
48 apps
.forEach(function (app
) {
49 process
.kill(-app
.pid
)
53 utils
.flushTests(function () {
61 it('Should make friends with two pod each in a different group', function (done
) {
64 // Pod 3 makes friend with the first one
65 makeFriends(3, function () {
66 // Pod 4 makes friend with the second one
67 makeFriends(4, function () {
68 // Now if the fifth wants to make friends with the third et the first
69 makeFriends(5, function () {
70 setTimeout(function () {
71 // It should have 0 friends
72 getFriendsList(5, function (err
, res
) {
75 expect(res
.body
.length
).to
.equal(0)
85 it('Should quit all friends', function (done
) {
87 quitFriends(1, function () {
88 quitFriends(2, function () {
89 async
.each([ 1, 2, 3, 4, 5, 6 ], function (i
, callback
) {
90 getFriendsList(i
, function (err
, res
) {
92 expect(res
.body
.length
).to
.equal(0)
102 it('Should make friends with the pods 1, 2, 3', function (done
) {
105 // Pods 1, 2, 3 and 4 become friends (yes this is beautiful)
106 makeFriends(2, function () {
107 makeFriends(1, function () {
108 makeFriends(4, function () {
112 // Expulse pod 4 from pod 1 and 2
113 uploadVideo(1, function () {
114 uploadVideo(2, function () {
115 setTimeout(function () {
116 uploadVideo(1, function () {
117 uploadVideo(2, function () {
118 setTimeout(function () {
120 utils
.runServer(4, function (app
, url
) {
122 getFriendsList(4, function (err
, res
) {
124 // Pod 4 didn't know pod 1 and 2 removed it
125 expect(res
.body
.length
).to
.equal(3)
127 // Pod 6 ask pod 1, 2 and 3
128 makeFriends(6, function () {
129 getFriendsList(6, function (err
, res
) {
132 // Pod 4 should not be our friend
133 var result
= res
.body
134 expect(result
.length
).to
.equal(3)
135 for (var pod
of result
) {
136 expect(pod
.url
).not
.equal(urls
[3])
155 it('Should pod 1 quit friends', function (done
) {
157 // Upload a video on server 3 for aditionnal tests
158 uploadVideo(3, function () {
159 setTimeout(function () {
160 quitFriends(1, function () {
161 // Remove pod 1 from pod 2
162 getVideos(1, function (err
, res
) {
164 expect(res
.body
).to
.be
.an('array')
165 expect(res
.body
.length
).to
.equal(2)
167 getVideos(2, function (err
, res
) {
169 expect(res
.body
).to
.be
.an('array')
170 expect(res
.body
.length
).to
.equal(3)
179 it('Should make friends between pod 1 and 2 and exchange their videos', function (done
) {
181 makeFriends(1, function () {
182 setTimeout(function () {
183 getVideos(1, function (err
, res
) {
186 expect(res
.body
).to
.be
.an('array')
187 expect(res
.body
.length
).to
.equal(5)