]>
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 getFriendsList (podNumber
, end
) {
29 const server
= servers
[podNumber
- 1]
30 return podsUtils
.getFriendsList(server
.url
, end
)
33 function uploadVideo (podNumber
, callback
) {
34 const name
= 'my super video'
35 const description
= 'my super description'
36 const tags
= [ 'tag1', 'tag2' ]
37 const fixture
= 'video_short.webm'
38 const server
= servers
[podNumber
- 1]
40 return videosUtils
.uploadVideo(server
.url
, server
.accessToken
, name
, description
, tags
, fixture
, callback
)
43 function getVideos (podNumber
, callback
) {
44 return videosUtils
.getVideosList(servers
[podNumber
- 1].url
, callback
)
47 // ---------------------------------------------------------------
49 before(function (done
) {
51 serversUtils
.flushAndRunMultipleServers(6, function (serversRun
, urlsRun
) {
54 each(servers
, function (server
, callbackEach
) {
55 loginUtils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
56 if (err
) return callbackEach(err
)
58 server
.accessToken
= accessToken
65 it('Should make friends with two pod each in a different group', function (done
) {
69 // Pod 3 makes friend with the first one
73 // Pod 4 makes friend with the second one
77 // Now if the fifth wants to make friends with the third et the first
82 setTimeout(next
, 11000)
87 // It should have 0 friends
88 getFriendsList(5, function (err
, res
) {
91 expect(res
.body
.data
.length
).to
.equal(0)
99 it('Should quit all friends', function (done
) {
112 each([ 1, 2, 3, 4, 5, 6 ], function (i
, callback
) {
113 getFriendsList(i
, function (err
, res
) {
116 expect(res
.body
.data
.length
).to
.equal(0)
125 it('Should make friends with the pods 1, 2, 3', function (done
) {
129 // Pods 1, 2, 3 and 4 become friends
139 // Check the pods 1, 2, 3 and 4 are friends
141 each([ 1, 2, 3, 4 ], function (i
, callback
) {
142 getFriendsList(i
, function (err
, res
) {
145 expect(res
.body
.data
.length
).to
.equal(3)
153 servers
[3].app
.kill()
156 // Expulse pod 4 from pod 1 and 2
164 setTimeout(next
, 11000)
173 setTimeout(next
, 11000)
177 serversUtils
.runServer(4, function (server
) {
178 servers
[3].app
= server
.app
183 getFriendsList(4, function (err
, res
) {
186 // Pod 4 didn't know pod 1 and 2 removed it
187 expect(res
.body
.data
.length
).to
.equal(3)
191 // Pod 6 ask pod 1, 2 and 3
196 setTimeout(next
, 11000)
201 getFriendsList(6, function (err
, res
) {
204 // Pod 4 should not be our friend
205 const result
= res
.body
.data
206 expect(result
.length
).to
.equal(3)
207 for (const pod
of result
) {
208 expect(pod
.host
).not
.equal(servers
[3].host
)
217 it('Should pod 1 quit friends', function (done
) {
221 // Upload a video on server 3 for aditionnal tests
226 setTimeout(next
, 15000)
231 // Remove pod 1 from pod 2
233 getVideos(1, function (err
, res
) {
236 const videos
= res
.body
.data
237 expect(videos
).to
.be
.an('array')
238 expect(videos
.length
).to
.equal(2)
246 getVideos(2, function (err
, res
) {
249 const videos
= res
.body
.data
250 expect(videos
).to
.be
.an('array')
251 expect(videos
.length
).to
.equal(3)
258 it('Should make friends between pod 1 and 2 and exchange their videos', function (done
) {
260 makeFriends(1, function () {
261 setTimeout(function () {
262 getVideos(1, function (err
, res
) {
265 const videos
= res
.body
.data
266 expect(videos
).to
.be
.an('array')
267 expect(videos
.length
).to
.equal(5)
275 after(function (done
) {
276 servers
.forEach(function (server
) {
277 process
.kill(-server
.app
.pid
)
281 serversUtils
.flushTests(done
)