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