]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/friendsAdvanced.js
3 const chai
= require('chai')
4 const each
= require('async/each')
5 const expect
= chai
.expect
6 const series
= require('async/series')
8 const utils
= require('./utils')
10 describe('Test advanced friends', function () {
13 function makeFriends (podNumber
, callback
) {
14 const server
= servers
[podNumber
- 1]
15 return utils
.makeFriends(server
.url
, server
.accessToken
, callback
)
18 function quitFriends (podNumber
, callback
) {
19 const server
= servers
[podNumber
- 1]
20 return utils
.quitFriends(server
.url
, server
.accessToken
, callback
)
23 function getFriendsList (podNumber
, end
) {
24 const server
= servers
[podNumber
- 1]
25 return utils
.getFriendsList(server
.url
, end
)
28 function uploadVideo (podNumber
, callback
) {
29 const name
= 'my super video'
30 const description
= 'my super description'
31 const tags
= [ 'tag1', 'tag2' ]
32 const fixture
= 'video_short.webm'
33 const server
= servers
[podNumber
- 1]
35 return utils
.uploadVideo(server
.url
, server
.accessToken
, name
, description
, tags
, fixture
, callback
)
38 function getVideos (podNumber
, callback
) {
39 return utils
.getVideosList(servers
[podNumber
- 1].url
, callback
)
42 // ---------------------------------------------------------------
44 before(function (done
) {
46 utils
.flushAndRunMultipleServers(6, function (serversRun
, urlsRun
) {
49 each(servers
, function (server
, callbackEach
) {
50 utils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
51 if (err
) return callbackEach(err
)
53 server
.accessToken
= accessToken
60 it('Should make friends with two pod each in a different group', function (done
) {
64 // Pod 3 makes friend with the first one
68 // Pod 4 makes friend with the second one
72 // Now if the fifth wants to make friends with the third et the first
77 setTimeout(next
, 11000)
82 // It should have 0 friends
83 getFriendsList(5, function (err
, res
) {
86 expect(res
.body
.length
).to
.equal(0)
94 it('Should quit all friends', function (done
) {
107 each([ 1, 2, 3, 4, 5, 6 ], function (i
, callback
) {
108 getFriendsList(i
, function (err
, res
) {
111 expect(res
.body
.length
).to
.equal(0)
120 it('Should make friends with the pods 1, 2, 3', function (done
) {
124 // Pods 1, 2, 3 and 4 become friends
134 // Check the pods 1, 2, 3 and 4 are friends
136 each([ 1, 2, 3, 4 ], function (i
, callback
) {
137 getFriendsList(i
, function (err
, res
) {
140 expect(res
.body
.length
).to
.equal(3)
148 servers
[3].app
.kill()
151 // Expulse pod 4 from pod 1 and 2
159 setTimeout(next
, 11000)
168 setTimeout(next
, 11000)
172 utils
.runServer(4, function (server
) {
173 servers
[3].app
= server
.app
178 getFriendsList(4, function (err
, res
) {
181 // Pod 4 didn't know pod 1 and 2 removed it
182 expect(res
.body
.length
).to
.equal(3)
186 // Pod 6 ask pod 1, 2 and 3
191 setTimeout(next
, 11000)
196 getFriendsList(6, function (err
, res
) {
199 // Pod 4 should not be our friend
200 const result
= res
.body
201 expect(result
.length
).to
.equal(3)
202 for (const pod
of result
) {
203 expect(pod
.url
).not
.equal(servers
[3].url
)
212 it('Should pod 1 quit friends', function (done
) {
216 // Upload a video on server 3 for aditionnal tests
221 setTimeout(next
, 15000)
226 // Remove pod 1 from pod 2
228 getVideos(1, function (err
, res
) {
231 const videos
= res
.body
.data
232 expect(videos
).to
.be
.an('array')
233 expect(videos
.length
).to
.equal(2)
241 getVideos(2, function (err
, res
) {
244 const videos
= res
.body
.data
245 expect(videos
).to
.be
.an('array')
246 expect(videos
.length
).to
.equal(3)
253 it('Should make friends between pod 1 and 2 and exchange their videos', function (done
) {
255 makeFriends(1, function () {
256 setTimeout(function () {
257 getVideos(1, function (err
, res
) {
260 const videos
= res
.body
.data
261 expect(videos
).to
.be
.an('array')
262 expect(videos
.length
).to
.equal(5)
270 after(function (done
) {
271 servers
.forEach(function (server
) {
272 process
.kill(-server
.app
.pid
)
276 utils
.flushTests(done
)