]>
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 () {
14 function testMadeFriends (urls
, url_to_test
, callback
) {
16 for (let i
= 0; i
< urls
.length
; i
++) {
17 if (urls
[i
] === url_to_test
) continue
21 utils
.getFriendsList(url_to_test
, function (err
, res
) {
24 const result
= res
.body
25 const result_urls
= [ result
[0].url
, result
[1].url
]
26 expect(result
).to
.be
.an('array')
27 expect(result
.length
).to
.equal(2)
28 expect(result_urls
[0]).to
.not
.equal(result_urls
[1])
30 const error_string
= 'Friends url do not correspond for ' + url_to_test
31 expect(friends
).to
.contain(result_urls
[0], error_string
)
32 expect(friends
).to
.contain(result_urls
[1], error_string
)
37 // ---------------------------------------------------------------
39 before(function (done
) {
41 utils
.flushAndRunMultipleServers(3, function (apps_run
, urls_run
) {
48 it('Should not have friends', function (done
) {
49 async
.each(urls
, function (url
, callback
) {
50 utils
.getFriendsList(url
, function (err
, res
) {
53 const result
= res
.body
54 expect(result
).to
.be
.an('array')
55 expect(result
.length
).to
.equal(0)
61 it('Should make friends', function (done
) {
64 const path
= '/api/v1/pods/makefriends'
67 // The second pod make friend with the third
71 .set('Accept', 'application/json')
75 // Wait for the request between pods
77 setTimeout(next
, 1000)
79 // The second pod should have the third as a friend
81 utils
.getFriendsList(urls
[1], function (err
, res
) {
84 const result
= res
.body
85 expect(result
).to
.be
.an('array')
86 expect(result
.length
).to
.equal(1)
87 expect(result
[0].url
).to
.be
.equal(urls
[2])
92 // Same here, the third pod should have the second pod as a friend
94 utils
.getFriendsList(urls
[2], function (err
, res
) {
97 const result
= res
.body
98 expect(result
).to
.be
.an('array')
99 expect(result
.length
).to
.equal(1)
100 expect(result
[0].url
).to
.be
.equal(urls
[1])
105 // Finally the first pod make friend with the second pod
109 .set('Accept', 'application/json')
113 // Wait for the request between pods
115 setTimeout(next
, 1000)
118 // Now each pod should be friend with the other ones
121 async
.each(urls
, function (url
, callback
) {
122 testMadeFriends(urls
, url
, callback
)
127 it('Should not be allowed to make friend again', function (done
) {
128 utils
.makeFriends(urls
[1], 409, done
)
131 it('Should quit friends of pod 2', function (done
) {
133 // Pod 1 quit friends
135 utils
.quitFriends(urls
[1], next
)
137 // Pod 1 should not have friends anymore
139 utils
.getFriendsList(urls
[1], function (err
, res
) {
142 const result
= res
.body
143 expect(result
).to
.be
.an('array')
144 expect(result
.length
).to
.equal(0)
149 // Other pods shouldn't have pod 1 too
151 async
.each([ urls
[0], urls
[2] ], function (url
, callback
) {
152 utils
.getFriendsList(url
, function (err
, res
) {
155 const result
= res
.body
156 expect(result
).to
.be
.an('array')
157 expect(result
.length
).to
.equal(1)
158 expect(result
[0].url
).not
.to
.be
.equal(urls
[1])
166 it('Should allow pod 2 to make friend again', function (done
) {
167 utils
.makeFriends(urls
[1], function () {
168 async
.each(urls
, function (url
, callback
) {
169 testMadeFriends(urls
, url
, callback
)
174 after(function (done
) {
175 apps
.forEach(function (app
) {
176 process
.kill(-app
.pid
)
180 utils
.flushTests(done
)