]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/friendsBasic.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 loginUtils
= require('../utils/login')
9 const podsUtils
= require('../utils/pods')
10 const serversUtils
= require('../utils/servers')
12 describe('Test basic friends', function () {
15 function makeFriends (podNumber
, callback
) {
16 const server
= servers
[podNumber
- 1]
17 return podsUtils
.makeFriends(server
.url
, server
.accessToken
, callback
)
20 function testMadeFriends (servers
, serverToTest
, callback
) {
22 for (let i
= 0; i
< servers
.length
; i
++) {
23 if (servers
[i
].url
=== serverToTest
.url
) continue
24 friends
.push(servers
[i
].url
)
27 podsUtils
.getFriendsList(serverToTest
.url
, function (err
, res
) {
30 const result
= res
.body
31 expect(result
).to
.be
.an('array')
32 expect(result
.length
).to
.equal(2)
34 const resultUrls
= [ result
[0].url
, result
[1].url
]
35 expect(resultUrls
[0]).to
.not
.equal(resultUrls
[1])
37 const errorString
= 'Friends url do not correspond for ' + serverToTest
.url
38 expect(friends
).to
.contain(resultUrls
[0], errorString
)
39 expect(friends
).to
.contain(resultUrls
[1], errorString
)
44 // ---------------------------------------------------------------
46 before(function (done
) {
48 serversUtils
.flushAndRunMultipleServers(3, function (serversRun
, urlsRun
) {
51 each(servers
, function (server
, callbackEach
) {
52 loginUtils
.loginAndGetAccessToken(server
, function (err
, accessToken
) {
53 if (err
) return callbackEach(err
)
55 server
.accessToken
= accessToken
62 it('Should not have friends', function (done
) {
63 each(servers
, function (server
, callback
) {
64 podsUtils
.getFriendsList(server
.url
, function (err
, res
) {
67 const result
= res
.body
68 expect(result
).to
.be
.an('array')
69 expect(result
.length
).to
.equal(0)
75 it('Should make friends', function (done
) {
79 // The second pod make friend with the third
83 // Wait for the request between pods
85 setTimeout(next
, 1000)
87 // The second pod should have the third as a friend
89 podsUtils
.getFriendsList(servers
[1].url
, function (err
, res
) {
92 const result
= res
.body
93 expect(result
).to
.be
.an('array')
94 expect(result
.length
).to
.equal(1)
95 expect(result
[0].url
).to
.be
.equal(servers
[2].url
)
100 // Same here, the third pod should have the second pod as a friend
102 podsUtils
.getFriendsList(servers
[2].url
, function (err
, res
) {
105 const result
= res
.body
106 expect(result
).to
.be
.an('array')
107 expect(result
.length
).to
.equal(1)
108 expect(result
[0].url
).to
.be
.equal(servers
[1].url
)
113 // Finally the first pod make friend with the second pod
117 // Wait for the request between pods
119 setTimeout(next
, 1000)
122 // Now each pod should be friend with the other ones
125 each(servers
, function (server
, callback
) {
126 testMadeFriends(servers
, server
, callback
)
131 it('Should not be allowed to make friend again', function (done
) {
132 const server
= servers
[1]
133 podsUtils
.makeFriends(server
.url
, server
.accessToken
, 409, done
)
136 it('Should quit friends of pod 2', function (done
) {
138 // Pod 1 quit friends
140 const server
= servers
[1]
141 podsUtils
.quitFriends(server
.url
, server
.accessToken
, next
)
143 // Pod 1 should not have friends anymore
145 podsUtils
.getFriendsList(servers
[1].url
, function (err
, res
) {
148 const result
= res
.body
149 expect(result
).to
.be
.an('array')
150 expect(result
.length
).to
.equal(0)
155 // Other pods shouldn't have pod 1 too
157 each([ servers
[0].url
, servers
[2].url
], function (url
, callback
) {
158 podsUtils
.getFriendsList(url
, function (err
, res
) {
161 const result
= res
.body
162 expect(result
).to
.be
.an('array')
163 expect(result
.length
).to
.equal(1)
164 expect(result
[0].url
).not
.to
.be
.equal(servers
[1].url
)
172 it('Should allow pod 2 to make friend again', function (done
) {
173 const server
= servers
[1]
174 podsUtils
.makeFriends(server
.url
, server
.accessToken
, function () {
175 each(servers
, function (server
, callback
) {
176 testMadeFriends(servers
, server
, callback
)
181 after(function (done
) {
182 servers
.forEach(function (server
) {
183 process
.kill(-server
.app
.pid
)
187 serversUtils
.flushTests(done
)