]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/friendsAdvanced.js
Add tag search support to server
[github/Chocobozzz/PeerTube.git] / server / tests / api / friendsAdvanced.js
1 'use strict'
2
3 const async = require('async')
4 const chai = require('chai')
5 const expect = chai.expect
6
7 const utils = require('./utils')
8
9 describe('Test advanced friends', function () {
10 let servers = []
11
12 function makeFriends (podNumber, callback) {
13 const server = servers[podNumber - 1]
14 return utils.makeFriends(server.url, server.accessToken, callback)
15 }
16
17 function quitFriends (podNumber, callback) {
18 const server = servers[podNumber - 1]
19 return utils.quitFriends(server.url, server.accessToken, callback)
20 }
21
22 function getFriendsList (podNumber, end) {
23 const server = servers[podNumber - 1]
24 return utils.getFriendsList(server.url, end)
25 }
26
27 function uploadVideo (podNumber, callback) {
28 const name = 'my super video'
29 const description = 'my super description'
30 const tags = [ 'tag1', 'tag2' ]
31 const fixture = 'video_short.webm'
32 const server = servers[podNumber - 1]
33
34 return utils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback)
35 }
36
37 function getVideos (podNumber, callback) {
38 return utils.getVideosList(servers[podNumber - 1].url, callback)
39 }
40
41 // ---------------------------------------------------------------
42
43 before(function (done) {
44 this.timeout(30000)
45 utils.flushAndRunMultipleServers(6, function (serversRun, urlsRun) {
46 servers = serversRun
47
48 async.each(servers, function (server, callbackEach) {
49 utils.loginAndGetAccessToken(server, function (err, accessToken) {
50 if (err) return callbackEach(err)
51
52 server.accessToken = accessToken
53 callbackEach()
54 })
55 }, done)
56 })
57 })
58
59 it('Should make friends with two pod each in a different group', function (done) {
60 this.timeout(20000)
61
62 async.series([
63 // Pod 3 makes friend with the first one
64 function (next) {
65 makeFriends(3, next)
66 },
67 // Pod 4 makes friend with the second one
68 function (next) {
69 makeFriends(4, next)
70 },
71 // Now if the fifth wants to make friends with the third et the first
72 function (next) {
73 makeFriends(5, next)
74 },
75 function (next) {
76 setTimeout(next, 11000)
77 }],
78 function (err) {
79 if (err) throw err
80
81 // It should have 0 friends
82 getFriendsList(5, function (err, res) {
83 if (err) throw err
84
85 expect(res.body.length).to.equal(0)
86
87 done()
88 })
89 }
90 )
91 })
92
93 it('Should quit all friends', function (done) {
94 this.timeout(10000)
95
96 async.series([
97 function (next) {
98 quitFriends(1, next)
99 },
100 function (next) {
101 quitFriends(2, next)
102 }],
103 function (err) {
104 if (err) throw err
105
106 async.each([ 1, 2, 3, 4, 5, 6 ], function (i, callback) {
107 getFriendsList(i, function (err, res) {
108 if (err) throw err
109
110 expect(res.body.length).to.equal(0)
111
112 callback()
113 })
114 }, done)
115 }
116 )
117 })
118
119 it('Should make friends with the pods 1, 2, 3', function (done) {
120 this.timeout(150000)
121
122 async.series([
123 // Pods 1, 2, 3 and 4 become friends
124 function (next) {
125 makeFriends(2, next)
126 },
127 function (next) {
128 makeFriends(1, next)
129 },
130 function (next) {
131 makeFriends(4, next)
132 },
133 // Kill pod 4
134 function (next) {
135 servers[3].app.kill()
136 next()
137 },
138 // Expulse pod 4 from pod 1 and 2
139 function (next) {
140 uploadVideo(1, next)
141 },
142 function (next) {
143 uploadVideo(2, next)
144 },
145 function (next) {
146 setTimeout(next, 11000)
147 },
148 function (next) {
149 uploadVideo(1, next)
150 },
151 function (next) {
152 uploadVideo(2, next)
153 },
154 function (next) {
155 setTimeout(next, 20000)
156 },
157 // Rerun server 4
158 function (next) {
159 utils.runServer(4, function (server) {
160 servers[3].app = server.app
161 next()
162 })
163 },
164 function (next) {
165 getFriendsList(4, function (err, res) {
166 if (err) throw err
167
168 // Pod 4 didn't know pod 1 and 2 removed it
169 expect(res.body.length).to.equal(3)
170 next()
171 })
172 },
173 // Pod 6 ask pod 1, 2 and 3
174 function (next) {
175 makeFriends(6, next)
176 }],
177 function (err) {
178 if (err) throw err
179
180 getFriendsList(6, function (err, res) {
181 if (err) throw err
182
183 // Pod 4 should not be our friend
184 const result = res.body
185 expect(result.length).to.equal(3)
186 for (const pod of result) {
187 expect(pod.url).not.equal(servers[3].url)
188 }
189
190 done()
191 })
192 }
193 )
194 })
195
196 it('Should pod 1 quit friends', function (done) {
197 this.timeout(25000)
198
199 async.series([
200 // Upload a video on server 3 for aditionnal tests
201 function (next) {
202 uploadVideo(3, next)
203 },
204 function (next) {
205 setTimeout(next, 15000)
206 },
207 function (next) {
208 quitFriends(1, next)
209 },
210 // Remove pod 1 from pod 2
211 function (next) {
212 getVideos(1, function (err, res) {
213 if (err) throw err
214
215 const videos = res.body.data
216 expect(videos).to.be.an('array')
217 expect(videos.length).to.equal(2)
218
219 next()
220 })
221 }],
222 function (err) {
223 if (err) throw err
224
225 getVideos(2, function (err, res) {
226 if (err) throw err
227
228 const videos = res.body.data
229 expect(videos).to.be.an('array')
230 expect(videos.length).to.equal(3)
231 done()
232 })
233 }
234 )
235 })
236
237 it('Should make friends between pod 1 and 2 and exchange their videos', function (done) {
238 this.timeout(20000)
239 makeFriends(1, function () {
240 setTimeout(function () {
241 getVideos(1, function (err, res) {
242 if (err) throw err
243
244 const videos = res.body.data
245 expect(videos).to.be.an('array')
246 expect(videos.length).to.equal(5)
247
248 done()
249 })
250 }, 5000)
251 })
252 })
253
254 after(function (done) {
255 servers.forEach(function (server) {
256 process.kill(-server.app.pid)
257 })
258
259 if (this.ok) {
260 utils.flushTests(done)
261 } else {
262 done()
263 }
264 })
265 })