]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - test/api/friendsAdvanced.js
4 var request
= require('supertest')
5 var chai
= require('chai')
6 var expect
= chai
.expect
8 var utils
= require('../utils')
10 describe('Test advanced friends', function () {
11 var path
= '/api/v1/pods/makefriends'
15 function makeFriend (pod_number
, callback
) {
16 // The first pod make friend with the third
17 request(urls
[pod_number
- 1])
19 .set('Accept', 'application/json')
21 .end(function (err
, res
) {
24 // Wait for the request between pods
25 setTimeout(function () {
31 function getFriendsList (pod_number
, end
) {
32 var path
= '/api/v1/pods/'
34 request(urls
[pod_number
- 1])
36 .set('Accept', 'application/json')
38 .expect('Content-Type', /json/)
42 function uploadVideo (pod_number
, callback
) {
43 var path
= '/api/v1/videos'
45 request(urls
[pod_number
- 1])
47 .set('Accept', 'application/json')
48 .field('name', 'my super video')
49 .field('description', 'my super description')
50 .attach('input_video', __dirname
+ '/../fixtures/video_short.webm')
55 // Wait for the retry requests
56 setTimeout(callback
, 10000)
60 beforeEach(function (done
) {
62 utils
.runMultipleServers(6, function (apps_run
, urls_run
) {
69 afterEach(function (done
) {
70 apps
.forEach(function (app
) {
71 process
.kill(-app
.pid
)
75 utils
.flushTests(function () {
83 it('Should make friends with two pod each in a different group', function (done
) {
86 // Pod 3 makes friend with the first one
87 makeFriend(3, function () {
88 // Pod 4 makes friend with the second one
89 makeFriend(4, function () {
90 // Now if the fifth wants to make friends with the third et the first
91 makeFriend(5, function () {
92 // It should have 0 friends
93 getFriendsList(5, function (err
, res
) {
96 expect(res
.body
.length
).to
.equal(0)
105 it('Should make friends with the pods 1, 2, 3', function (done
) {
108 // Pods 1, 2, 3 and 4 become friends (yes this is beautiful)
109 makeFriend(2, function () {
110 makeFriend(1, function () {
111 makeFriend(4, function () {
115 // Expulse pod 4 from pod 1 and 2
116 uploadVideo(1, function () {
117 setTimeout(function () {
118 uploadVideo(1, function () {
119 setTimeout(function () {
120 uploadVideo(2, function () {
121 setTimeout(function () {
122 uploadVideo(2, function () {
123 setTimeout(function () {
125 utils
.runServer(4, function (app
, url
) {
127 getFriendsList(4, function (err
, res
) {
129 // Pod 4 didn't know pod 1 and 2 removed it
130 expect(res
.body
.length
).to
.equal(3)
132 // Pod 6 ask pod 1, 2 and 3
133 makeFriend(6, function () {
134 getFriendsList(6, function (err
, res
) {
137 // Pod 4 should not be our friend
138 var result
= res
.body
139 expect(result
.length
).to
.equal(3)
140 for (var pod
of result
) {
141 expect(pod
.url
).not
.equal(urls
[3])