]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/friends-basic.js
62c40df7b98cf15a489b23e32ee9cfc49d8f81d0
3 const chai
= require('chai')
4 const each
= require('async/each')
5 const expect
= chai
.expect
6 const series
= require('async/series')
8 const loginUtils
= require('../utils/login')
9 const miscsUtils
= require('../utils/miscs')
10 const podsUtils
= require('../utils/pods')
11 const serversUtils
= require('../utils/servers')
13 describe('Test basic friends', function () {
16 function makeFriends (podNumber
, callback
) {
17 const server
= servers
[podNumber
- 1]
18 return podsUtils
.makeFriends(server
.url
, server
.accessToken
, callback
)
21 function testMadeFriends (servers
, serverToTest
, callback
) {
23 for (let i
= 0; i
< servers
.length
; i
++) {
24 if (servers
[i
].url
=== serverToTest
.url
) continue
25 friends
.push(servers
[i
].host
)
28 podsUtils
.getFriendsList(serverToTest
.url
, function (err
, res
) {
31 const result
= res
.body
.data
32 expect(result
).to
.be
.an('array')
33 expect(result
.length
).to
.equal(2)
35 const resultHosts
= [ result
[0].host
, result
[1].host
]
36 expect(resultHosts
[0]).to
.not
.equal(resultHosts
[1])
38 const errorString
= 'Friends host do not correspond for ' + serverToTest
.host
39 expect(friends
).to
.contain(resultHosts
[0], errorString
)
40 expect(friends
).to
.contain(resultHosts
[1], errorString
)
45 // ---------------------------------------------------------------
47 before(function (done
) {
49 serversUtils
.flushAndRunMultipleServers(3, function (serversRun
, urlsRun
) {
52 each(servers
, function (server
, callbackEach
) {
53 loginUtils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
54 if (err
) return callbackEach(err
)
56 server
.accessToken
= accessToken
63 it('Should not have friends', function (done
) {
64 each(servers
, function (server
, callback
) {
65 podsUtils
.getFriendsList(server
.url
, function (err
, res
) {
68 const result
= res
.body
.data
69 expect(result
).to
.be
.an('array')
70 expect(result
.length
).to
.equal(0)
76 it('Should make friends', function (done
) {
80 // The second pod make friend with the third
84 // Wait for the request between pods
86 setTimeout(next
, 11000)
88 // The second pod should have the third as a friend
90 podsUtils
.getFriendsList(servers
[1].url
, function (err
, res
) {
93 const result
= res
.body
.data
94 expect(result
).to
.be
.an('array')
95 expect(result
.length
).to
.equal(1)
98 expect(pod
.host
).to
.equal(servers
[2].host
)
99 expect(pod
.email
).to
.equal('admin3@example.com')
100 expect(pod
.score
).to
.equal(20)
101 expect(miscsUtils
.dateIsValid(pod
.createdAt
)).to
.be
.true
106 // Same here, the third pod should have the second pod as a friend
108 podsUtils
.getFriendsList(servers
[2].url
, function (err
, res
) {
111 const result
= res
.body
.data
112 expect(result
).to
.be
.an('array')
113 expect(result
.length
).to
.equal(1)
115 const pod
= result
[0]
116 expect(pod
.host
).to
.equal(servers
[1].host
)
117 expect(pod
.email
).to
.equal('admin2@example.com')
118 expect(pod
.score
).to
.equal(20)
119 expect(miscsUtils
.dateIsValid(pod
.createdAt
)).to
.be
.true
124 // Finally the first pod make friend with the second pod
128 // Wait for the request between pods
130 setTimeout(next
, 11000)
133 // Now each pod should be friend with the other ones
136 each(servers
, function (server
, callback
) {
137 testMadeFriends(servers
, server
, callback
)
142 it('Should not be allowed to make friend again', function (done
) {
143 const server
= servers
[1]
144 podsUtils
.makeFriends(server
.url
, server
.accessToken
, 409, done
)
147 it('Should quit friends of pod 2', function (done
) {
149 // Pod 1 quit friends
151 const server
= servers
[1]
152 podsUtils
.quitFriends(server
.url
, server
.accessToken
, next
)
154 // Pod 1 should not have friends anymore
156 podsUtils
.getFriendsList(servers
[1].url
, function (err
, res
) {
159 const result
= res
.body
.data
160 expect(result
).to
.be
.an('array')
161 expect(result
.length
).to
.equal(0)
166 // Other pods shouldn't have pod 1 too
168 each([ servers
[0].url
, servers
[2].url
], function (url
, callback
) {
169 podsUtils
.getFriendsList(url
, function (err
, res
) {
172 const result
= res
.body
.data
173 expect(result
).to
.be
.an('array')
174 expect(result
.length
).to
.equal(1)
175 expect(result
[0].host
).not
.to
.be
.equal(servers
[1].host
)
183 it('Should allow pod 2 to make friend again', function (done
) {
186 const server
= servers
[1]
187 podsUtils
.makeFriends(server
.url
, server
.accessToken
, function () {
188 setTimeout(function () {
189 each(servers
, function (server
, callback
) {
190 testMadeFriends(servers
, server
, callback
)
196 after(function (done
) {
197 servers
.forEach(function (server
) {
198 process
.kill(-server
.app
.pid
)
202 serversUtils
.flushTests(done
)