]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/friendsBasic.js
3 const async
= require('async')
4 const chai
= require('chai')
5 const expect
= chai
.expect
6 const request
= require('supertest')
8 const utils
= require('./utils')
10 describe('Test basic friends', function () {
13 function testMadeFriends (servers
, server_to_test
, callback
) {
15 for (let i
= 0; i
< servers
.length
; i
++) {
16 if (servers
[i
].url
=== server_to_test
.url
) continue
17 friends
.push(servers
[i
].url
)
20 utils
.getFriendsList(server_to_test
.url
, function (err
, res
) {
23 const result
= res
.body
24 const result_urls
= [ result
[0].url
, result
[1].url
]
25 expect(result
).to
.be
.an('array')
26 expect(result
.length
).to
.equal(2)
27 expect(result_urls
[0]).to
.not
.equal(result_urls
[1])
29 const error_string
= 'Friends url do not correspond for ' + server_to_test
.url
30 expect(friends
).to
.contain(result_urls
[0], error_string
)
31 expect(friends
).to
.contain(result_urls
[1], error_string
)
36 // ---------------------------------------------------------------
38 before(function (done
) {
40 utils
.flushAndRunMultipleServers(3, function (servers_run
, urls_run
) {
46 it('Should not have friends', function (done
) {
47 async
.each(servers
, function (server
, callback
) {
48 utils
.getFriendsList(server
.url
, function (err
, res
) {
51 const result
= res
.body
52 expect(result
).to
.be
.an('array')
53 expect(result
.length
).to
.equal(0)
59 it('Should make friends', function (done
) {
62 const path
= '/api/v1/pods/makefriends'
65 // The second pod make friend with the third
67 request(servers
[1].url
)
69 .set('Accept', 'application/json')
73 // Wait for the request between pods
75 setTimeout(next
, 1000)
77 // The second pod should have the third as a friend
79 utils
.getFriendsList(servers
[1].url
, function (err
, res
) {
82 const result
= res
.body
83 expect(result
).to
.be
.an('array')
84 expect(result
.length
).to
.equal(1)
85 expect(result
[0].url
).to
.be
.equal(servers
[2].url
)
90 // Same here, the third pod should have the second pod as a friend
92 utils
.getFriendsList(servers
[2].url
, function (err
, res
) {
95 const result
= res
.body
96 expect(result
).to
.be
.an('array')
97 expect(result
.length
).to
.equal(1)
98 expect(result
[0].url
).to
.be
.equal(servers
[1].url
)
103 // Finally the first pod make friend with the second pod
105 request(servers
[0].url
)
107 .set('Accept', 'application/json')
111 // Wait for the request between pods
113 setTimeout(next
, 1000)
116 // Now each pod should be friend with the other ones
119 async
.each(servers
, function (server
, callback
) {
120 testMadeFriends(servers
, server
, callback
)
125 it('Should not be allowed to make friend again', function (done
) {
126 utils
.makeFriends(servers
[1].url
, 409, done
)
129 it('Should quit friends of pod 2', function (done
) {
131 // Pod 1 quit friends
133 utils
.quitFriends(servers
[1].url
, next
)
135 // Pod 1 should not have friends anymore
137 utils
.getFriendsList(servers
[1].url
, function (err
, res
) {
140 const result
= res
.body
141 expect(result
).to
.be
.an('array')
142 expect(result
.length
).to
.equal(0)
147 // Other pods shouldn't have pod 1 too
149 async
.each([ servers
[0].url
, servers
[2].url
], function (url
, callback
) {
150 utils
.getFriendsList(url
, function (err
, res
) {
153 const result
= res
.body
154 expect(result
).to
.be
.an('array')
155 expect(result
.length
).to
.equal(1)
156 expect(result
[0].url
).not
.to
.be
.equal(servers
[1].url
)
164 it('Should allow pod 2 to make friend again', function (done
) {
165 utils
.makeFriends(servers
[1].url
, function () {
166 async
.each(servers
, function (server
, callback
) {
167 testMadeFriends(servers
, server
, callback
)
172 after(function (done
) {
173 servers
.forEach(function (server
) {
174 process
.kill(-server
.app
.pid
)
178 utils
.flushTests(done
)