]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/friendsAdvanced.js
Add tag search support to server
[github/Chocobozzz/PeerTube.git] / server / tests / api / friendsAdvanced.js
CommitLineData
9f10b292 1'use strict'
3bcb78b3 2
f0f5567b
C
3const async = require('async')
4const chai = require('chai')
5const expect = chai.expect
3bcb78b3 6
f0f5567b 7const utils = require('./utils')
3bcb78b3 8
9f10b292 9describe('Test advanced friends', function () {
0c1cbbfe 10 let servers = []
3bcb78b3 11
bc503c2a 12 function makeFriends (podNumber, callback) {
b3b92647
C
13 const server = servers[podNumber - 1]
14 return utils.makeFriends(server.url, server.accessToken, callback)
9f10b292 15 }
45239549 16
bc503c2a 17 function quitFriends (podNumber, callback) {
b3b92647
C
18 const server = servers[podNumber - 1]
19 return utils.quitFriends(server.url, server.accessToken, callback)
9f10b292 20 }
3bcb78b3 21
bc503c2a 22 function getFriendsList (podNumber, end) {
b3b92647
C
23 const server = servers[podNumber - 1]
24 return utils.getFriendsList(server.url, end)
9f10b292 25 }
3bcb78b3 26
bc503c2a 27 function uploadVideo (podNumber, callback) {
f0f5567b
C
28 const name = 'my super video'
29 const description = 'my super description'
be587647 30 const tags = [ 'tag1', 'tag2' ]
f0f5567b 31 const fixture = 'video_short.webm'
bc503c2a 32 const server = servers[podNumber - 1]
3bcb78b3 33
be587647 34 return utils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback)
9f10b292 35 }
3bcb78b3 36
bc503c2a
C
37 function getVideos (podNumber, callback) {
38 return utils.getVideosList(servers[podNumber - 1].url, callback)
9f10b292 39 }
45239549 40
9f10b292 41 // ---------------------------------------------------------------
ee66c593 42
9f10b292
C
43 before(function (done) {
44 this.timeout(30000)
bc503c2a
C
45 utils.flushAndRunMultipleServers(6, function (serversRun, urlsRun) {
46 servers = serversRun
0c1cbbfe 47
bc503c2a
C
48 async.each(servers, function (server, callbackEach) {
49 utils.loginAndGetAccessToken(server, function (err, accessToken) {
50 if (err) return callbackEach(err)
0c1cbbfe 51
bc503c2a
C
52 server.accessToken = accessToken
53 callbackEach()
0c1cbbfe
C
54 })
55 }, done)
3bcb78b3 56 })
9f10b292 57 })
3bcb78b3 58
9f10b292
C
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) {
ee66c593
C
83 if (err) throw err
84
9f10b292
C
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) {
ee66c593
C
108 if (err) throw err
109
110 expect(res.body.length).to.equal(0)
111
9f10b292 112 callback()
3bcb78b3 113 })
9f10b292
C
114 }, done)
115 }
116 )
117 })
3bcb78b3 118
9f10b292
C
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) {
0c1cbbfe 135 servers[3].app.kill()
9f10b292
C
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) {
0c1cbbfe
C
159 utils.runServer(4, function (server) {
160 servers[3].app = server.app
9f10b292
C
161 next()
162 })
163 },
164 function (next) {
165 getFriendsList(4, function (err, res) {
ee66c593
C
166 if (err) throw err
167
9f10b292
C
168 // Pod 4 didn't know pod 1 and 2 removed it
169 expect(res.body.length).to.equal(3)
ee66c593 170 next()
9f10b292
C
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) {
ee66c593
C
181 if (err) throw err
182
9f10b292 183 // Pod 4 should not be our friend
f0f5567b 184 const result = res.body
9f10b292 185 expect(result.length).to.equal(3)
f0f5567b 186 for (const pod of result) {
0c1cbbfe 187 expect(pod.url).not.equal(servers[3].url)
9f10b292 188 }
ee66c593 189
9f10b292
C
190 done()
191 })
192 }
193 )
194 })
ee66c593 195
9f10b292
C
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
68ce3ae0
C
214
215 const videos = res.body.data
216 expect(videos).to.be.an('array')
217 expect(videos.length).to.equal(2)
45239549 218
9f10b292
C
219 next()
220 })
221 }],
222 function (err) {
223 if (err) throw err
ee66c593 224
9f10b292 225 getVideos(2, function (err, res) {
ee66c593 226 if (err) throw err
68ce3ae0
C
227
228 const videos = res.body.data
229 expect(videos).to.be.an('array')
230 expect(videos.length).to.equal(3)
9f10b292
C
231 done()
232 })
233 }
234 )
235 })
ee66c593 236
9f10b292
C
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
45239549 243
68ce3ae0
C
244 const videos = res.body.data
245 expect(videos).to.be.an('array')
246 expect(videos.length).to.equal(5)
45239549 247
9f10b292
C
248 done()
249 })
250 }, 5000)
45239549 251 })
9f10b292 252 })
ee66c593 253
9f10b292 254 after(function (done) {
0c1cbbfe
C
255 servers.forEach(function (server) {
256 process.kill(-server.app.pid)
ee66c593 257 })
9f10b292
C
258
259 if (this.ok) {
260 utils.flushTests(done)
261 } else {
262 done()
263 }
3bcb78b3 264 })
9f10b292 265})