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