]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - test/api/friendsAdvanced.js
Finalise the join in a network and add the ability to quit it
[github/Chocobozzz/PeerTube.git] / test / api / friendsAdvanced.js
1 ;(function () {
2 'use strict'
3
4 var async = require('async')
5 var chai = require('chai')
6 var expect = chai.expect
7
8 var utils = require('./utils')
9
10 describe('Test advanced friends', function () {
11 var apps = []
12 var urls = []
13
14 function makeFriends (pod_number, callback) {
15 return utils.makeFriends(urls[pod_number - 1], callback)
16 }
17
18 function quitFriends (pod_number, callback) {
19 return utils.quitFriends(urls[pod_number - 1], callback)
20 }
21
22 function getFriendsList (pod_number, end) {
23 return utils.getFriendsList(urls[pod_number - 1], end)
24 }
25
26 function uploadVideo (pod_number, callback) {
27 var name = 'my super video'
28 var description = 'my super description'
29 var fixture = 'video_short.webm'
30
31 return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback)
32 }
33
34 function getVideos (pod_number, callback) {
35 return utils.getVideosList(urls[pod_number - 1], callback)
36 }
37
38 before(function (done) {
39 this.timeout(30000)
40 utils.runMultipleServers(6, function (apps_run, urls_run) {
41 apps = apps_run
42 urls = urls_run
43 done()
44 })
45 })
46
47 after(function (done) {
48 apps.forEach(function (app) {
49 process.kill(-app.pid)
50 })
51
52 if (this.ok) {
53 utils.flushTests(function () {
54 done()
55 })
56 } else {
57 done()
58 }
59 })
60
61 it('Should make friends with two pod each in a different group', function (done) {
62 this.timeout(20000)
63
64 // Pod 3 makes friend with the first one
65 makeFriends(3, function () {
66 // Pod 4 makes friend with the second one
67 makeFriends(4, function () {
68 // Now if the fifth wants to make friends with the third et the first
69 makeFriends(5, function () {
70 setTimeout(function () {
71 // It should have 0 friends
72 getFriendsList(5, function (err, res) {
73 if (err) throw err
74
75 expect(res.body.length).to.equal(0)
76
77 done()
78 })
79 }, 11000)
80 })
81 })
82 })
83 })
84
85 it('Should quit all friends', function (done) {
86 this.timeout(10000)
87 quitFriends(1, function () {
88 quitFriends(2, function () {
89 async.each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) {
90 getFriendsList(i, function (err, res) {
91 if (err) throw err
92 expect(res.body.length).to.equal(0)
93 callback()
94 })
95 }, function () {
96 done()
97 })
98 })
99 })
100 })
101
102 it('Should make friends with the pods 1, 2, 3', function (done) {
103 this.timeout(150000)
104
105 // Pods 1, 2, 3 and 4 become friends (yes this is beautiful)
106 makeFriends(2, function () {
107 makeFriends(1, function () {
108 makeFriends(4, function () {
109 // Kill the server 4
110 apps[3].kill()
111
112 // Expulse pod 4 from pod 1 and 2
113 uploadVideo(1, function () {
114 uploadVideo(2, function () {
115 setTimeout(function () {
116 uploadVideo(1, function () {
117 uploadVideo(2, function () {
118 setTimeout(function () {
119 // Rerun server 4
120 utils.runServer(4, function (app, url) {
121 apps[3] = app
122 getFriendsList(4, function (err, res) {
123 if (err) throw err
124 // Pod 4 didn't know pod 1 and 2 removed it
125 expect(res.body.length).to.equal(3)
126
127 // Pod 6 ask pod 1, 2 and 3
128 makeFriends(6, function () {
129 getFriendsList(6, function (err, res) {
130 if (err) throw err
131
132 // Pod 4 should not be our friend
133 var result = res.body
134 expect(result.length).to.equal(3)
135 for (var pod of result) {
136 expect(pod.url).not.equal(urls[3])
137 }
138
139 done()
140 })
141 })
142 })
143 })
144 }, 15000)
145 })
146 })
147 }, 11000)
148 })
149 })
150 })
151 })
152 })
153 })
154
155 it('Should pod 1 quit friends', function (done) {
156 this.timeout(25000)
157 // Upload a video on server 3 for aditionnal tests
158 uploadVideo(3, function () {
159 setTimeout(function () {
160 quitFriends(1, function () {
161 // Remove pod 1 from pod 2
162 getVideos(1, function (err, res) {
163 if (err) throw err
164 expect(res.body).to.be.an('array')
165 expect(res.body.length).to.equal(2)
166
167 getVideos(2, function (err, res) {
168 if (err) throw err
169 expect(res.body).to.be.an('array')
170 expect(res.body.length).to.equal(3)
171 done()
172 })
173 })
174 })
175 }, 15000)
176 })
177 })
178
179 it('Should make friends between pod 1 and 2 and exchange their videos', function (done) {
180 this.timeout(20000)
181 makeFriends(1, function () {
182 setTimeout(function () {
183 getVideos(1, function (err, res) {
184 if (err) throw err
185
186 expect(res.body).to.be.an('array')
187 expect(res.body.length).to.equal(5)
188
189 done()
190 })
191 }, 5000)
192 })
193 })
194 })
195 })()