]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - test/api/friendsBasic.js
4 var async
= require('async')
5 var chai
= require('chai')
6 var expect
= chai
.expect
7 var request
= require('supertest')
9 var utils
= require('./utils')
11 describe('Test basic friends', function () {
15 function testMadeFriends (urls
, url_to_test
, callback
) {
17 for (var i
= 0; i
< urls
.length
; i
++) {
18 if (urls
[i
] === url_to_test
) continue
22 utils
.getFriendsList(url_to_test
, function (err
, res
) {
26 var result_urls
= [ result
[0].url
, result
[1].url
]
27 expect(result
).to
.be
.an('array')
28 expect(result
.length
).to
.equal(2)
29 expect(result_urls
[0]).to
.not
.equal(result_urls
[1])
31 var error_string
= 'Friends url do not correspond for ' + url_to_test
32 expect(friends
).to
.contain(result_urls
[0], error_string
)
33 expect(friends
).to
.contain(result_urls
[1], error_string
)
38 // ---------------------------------------------------------------
40 before(function (done
) {
42 utils
.flushAndRunMultipleServers(3, function (apps_run
, urls_run
) {
49 it('Should not have friends', function (done
) {
50 async
.each(urls
, function (url
, callback
) {
51 utils
.getFriendsList(url
, function (err
, res
) {
55 expect(result
).to
.be
.an('array')
56 expect(result
.length
).to
.equal(0)
62 it('Should make friends', function (done
) {
65 var path
= '/api/v1/pods/makefriends'
68 // The second pod make friend with the third
72 .set('Accept', 'application/json')
76 // Wait for the request between pods
78 setTimeout(next
, 1000)
80 // The second pod should have the third as a friend
82 utils
.getFriendsList(urls
[1], function (err
, res
) {
86 expect(result
).to
.be
.an('array')
87 expect(result
.length
).to
.equal(1)
88 expect(result
[0].url
).to
.be
.equal(urls
[2])
93 // Same here, the third pod should have the second pod as a friend
95 utils
.getFriendsList(urls
[2], function (err
, res
) {
99 expect(result
).to
.be
.an('array')
100 expect(result
.length
).to
.equal(1)
101 expect(result
[0].url
).to
.be
.equal(urls
[1])
106 // Finally the first pod make friend with the second pod
110 .set('Accept', 'application/json')
114 // Wait for the request between pods
116 setTimeout(next
, 1000)
119 // Now each pod should be friend with the other ones
122 async
.each(urls
, function (url
, callback
) {
123 testMadeFriends(urls
, url
, callback
)
128 it('Should not be allowed to make friend again', function (done
) {
129 utils
.makeFriends(urls
[1], 409, done
)
132 it('Should quit friends of pod 2', function (done
) {
134 // Pod 1 quit friends
136 utils
.quitFriends(urls
[1], next
)
138 // Pod 1 should not have friends anymore
140 utils
.getFriendsList(urls
[1], function (err
, res
) {
143 var result
= res
.body
144 expect(result
).to
.be
.an('array')
145 expect(result
.length
).to
.equal(0)
150 // Other pods shouldn't have pod 1 too
152 async
.each([ urls
[0], urls
[2] ], function (url
, callback
) {
153 utils
.getFriendsList(url
, function (err
, res
) {
156 var result
= res
.body
157 expect(result
).to
.be
.an('array')
158 expect(result
.length
).to
.equal(1)
159 expect(result
[0].url
).not
.to
.be
.equal(urls
[1])
167 it('Should allow pod 2 to make friend again', function (done
) {
168 utils
.makeFriends(urls
[1], function () {
169 async
.each(urls
, function (url
, callback
) {
170 testMadeFriends(urls
, url
, callback
)
175 after(function (done
) {
176 apps
.forEach(function (app
) {
177 process
.kill(-app
.pid
)
181 utils
.flushTests(done
)