]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - test/api/friends.js
4 var request
= require('supertest')
5 var chai
= require('chai')
6 var expect
= chai
.expect
7 var async
= require('async')
9 var utils
= require('../utils')
11 function getFriendsList (url
, end
) {
12 var path
= '/api/v1/pods/'
16 .set('Accept', 'application/json')
18 .expect('Content-Type', /json/)
22 describe('Test friends', function () {
26 before(function (done
) {
28 utils
.runMultipleServers(3, function (apps_run
, urls_run
) {
35 it('Should not have friends', function (done
) {
36 async
.each(urls
, function (url
, callback
) {
37 getFriendsList(url
, function (err
, res
) {
41 expect(result
).to
.be
.an('array')
42 expect(result
.length
).to
.equal(0)
52 it('Should make friends', function (done
) {
55 function testMadeFriends (urls
, url_to_test
, callback
) {
57 for (var i
= 0; i
< urls
.length
; i
++) {
58 if (urls
[i
] === url_to_test
) continue
62 getFriendsList(url_to_test
, function (err
, res
) {
66 var result_urls
= [ result
[0].url
, result
[1].url
]
67 expect(result
).to
.be
.an('array')
68 expect(result
.length
).to
.equal(2)
69 expect(result_urls
[0]).to
.not
.equal(result_urls
[1])
71 var error_string
= 'Friends url do not correspond for ' + url_to_test
72 expect(friends
).to
.contain(result_urls
[0], error_string
)
73 expect(friends
).to
.contain(result_urls
[1], error_string
)
78 var path
= '/api/v1/pods/makefriends'
80 // The second pod make friend with the third
83 .set('Accept', 'application/json')
85 .end(function (err
, res
) {
88 // Wait for the request between pods
89 setTimeout(function () {
90 // The second pod should have the third as a friend
91 getFriendsList(urls
[1], function (err
, res
) {
95 expect(result
).to
.be
.an('array')
96 expect(result
.length
).to
.equal(1)
97 expect(result
[0].url
).to
.be
.equal(urls
[2])
99 // Same here, the third pod should have the second pod as a friend
100 getFriendsList(urls
[2], function (err
, res
) {
103 var result
= res
.body
104 expect(result
).to
.be
.an('array')
105 expect(result
.length
).to
.equal(1)
106 expect(result
[0].url
).to
.be
.equal(urls
[1])
108 // Finally the first pod make friend with the second pod
111 .set('Accept', 'application/json')
113 .end(function (err
, res
) {
116 setTimeout(function () {
117 // Now each pod should be friend with the other ones
118 async
.each(urls
, function (url
, callback
) {
119 testMadeFriends(urls
, url
, callback
)
133 it('Should not be able to make friends again')
135 after(function (done
) {
136 apps
.forEach(function (app
) {
137 process
.kill(-app
.pid
)
141 utils
.flushTests(function () {