]>
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 before(function (done
) {
17 utils
.runMultipleServers(3, function (apps_run
, urls_run
) {
24 it('Should not have friends', function (done
) {
25 async
.each(urls
, function (url
, callback
) {
26 utils
.getFriendsList(url
, function (err
, res
) {
30 expect(result
).to
.be
.an('array')
31 expect(result
.length
).to
.equal(0)
41 it('Should make friends', function (done
) {
44 function testMadeFriends (urls
, url_to_test
, callback
) {
46 for (var i
= 0; i
< urls
.length
; i
++) {
47 if (urls
[i
] === url_to_test
) continue
51 utils
.getFriendsList(url_to_test
, function (err
, res
) {
55 var result_urls
= [ result
[0].url
, result
[1].url
]
56 expect(result
).to
.be
.an('array')
57 expect(result
.length
).to
.equal(2)
58 expect(result_urls
[0]).to
.not
.equal(result_urls
[1])
60 var error_string
= 'Friends url do not correspond for ' + url_to_test
61 expect(friends
).to
.contain(result_urls
[0], error_string
)
62 expect(friends
).to
.contain(result_urls
[1], error_string
)
67 var path
= '/api/v1/pods/makefriends'
69 // The second pod make friend with the third
72 .set('Accept', 'application/json')
74 .end(function (err
, res
) {
77 // Wait for the request between pods
78 setTimeout(function () {
79 // The second pod should have the third as a friend
80 utils
.getFriendsList(urls
[1], function (err
, res
) {
84 expect(result
).to
.be
.an('array')
85 expect(result
.length
).to
.equal(1)
86 expect(result
[0].url
).to
.be
.equal(urls
[2])
88 // Same here, the third pod should have the second pod as a friend
89 utils
.getFriendsList(urls
[2], function (err
, res
) {
93 expect(result
).to
.be
.an('array')
94 expect(result
.length
).to
.equal(1)
95 expect(result
[0].url
).to
.be
.equal(urls
[1])
97 // Finally the first pod make friend with the second pod
100 .set('Accept', 'application/json')
102 .end(function (err
, res
) {
105 setTimeout(function () {
106 // Now each pod should be friend with the other ones
107 async
.each(urls
, function (url
, callback
) {
108 testMadeFriends(urls
, url
, callback
)
122 it('Should not be able to make friends again')
124 after(function (done
) {
125 apps
.forEach(function (app
) {
126 process
.kill(-app
.pid
)
130 utils
.flushTests(function () {