]>
Commit | Line | Data |
---|---|---|
0e1dc3e7 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
5 | ||
6 | import { | |
7 | dateIsValid, | |
8 | flushAndRunMultipleServers, | |
9 | flushTests, | |
10 | getVideo, | |
11 | getVideosList, | |
12 | killallServers, | |
0e1dc3e7 C |
13 | rateVideo, |
14 | removeVideo, | |
15 | ServerInfo, | |
16 | setAccessTokensToServers, | |
17 | testVideoImage, | |
18 | updateVideo, | |
19 | uploadVideo, | |
20 | wait, | |
5f04dd2f C |
21 | webtorrentAdd, |
22 | addVideoChannel, | |
23 | getVideoChannelsList, | |
9a27cdc2 C |
24 | getUserAccessToken, |
25 | doubleFollow | |
0e1dc3e7 | 26 | } from '../utils' |
5f04dd2f | 27 | import { createUser } from '../utils/users' |
1f3e9fec | 28 | import { viewVideo } from '../utils/videos' |
0e1dc3e7 C |
29 | |
30 | const expect = chai.expect | |
31 | ||
9a27cdc2 | 32 | describe('Test multiple servers', function () { |
0e1dc3e7 C |
33 | let servers: ServerInfo[] = [] |
34 | const toRemove = [] | |
35 | let videoUUID = '' | |
5f04dd2f | 36 | let videoChannelId: number |
0e1dc3e7 C |
37 | |
38 | before(async function () { | |
39 | this.timeout(120000) | |
40 | ||
41 | servers = await flushAndRunMultipleServers(3) | |
42 | ||
43 | // Get the access tokens | |
44 | await setAccessTokensToServers(servers) | |
45 | ||
5f04dd2f C |
46 | const videoChannel = { |
47 | name: 'my channel', | |
48 | description: 'super channel' | |
49 | } | |
50 | await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) | |
51 | const channelRes = await getVideoChannelsList(servers[0].url, 0, 1) | |
52 | videoChannelId = channelRes.body.data[0].id | |
53 | ||
9a27cdc2 C |
54 | // Server 1 and server 2 follow each other |
55 | await doubleFollow(servers[0], servers[1]) | |
56 | // Server 1 and server 3 follow each other | |
57 | await doubleFollow(servers[0], servers[2]) | |
58 | // Server 2 and server 3 follow each other | |
59 | await doubleFollow(servers[1], servers[2]) | |
0e1dc3e7 C |
60 | }) |
61 | ||
9a27cdc2 | 62 | it('Should not have videos for all servers', async function () { |
0e1dc3e7 C |
63 | for (const server of servers) { |
64 | const res = await getVideosList(server.url) | |
65 | const videos = res.body.data | |
66 | expect(videos).to.be.an('array') | |
67 | expect(videos.length).to.equal(0) | |
68 | } | |
69 | }) | |
70 | ||
9a27cdc2 C |
71 | describe('Should upload the video and propagate on each server', function () { |
72 | it('Should upload the video on server 1 and propagate on each server', async function () { | |
652b3056 | 73 | this.timeout(25000) |
0e1dc3e7 C |
74 | |
75 | const videoAttributes = { | |
9a27cdc2 | 76 | name: 'my super name for server 1', |
0e1dc3e7 C |
77 | category: 5, |
78 | licence: 4, | |
79 | language: 9, | |
80 | nsfw: true, | |
9a27cdc2 | 81 | description: 'my super description for server 1', |
0e1dc3e7 | 82 | tags: [ 'tag1p1', 'tag2p1' ], |
5f04dd2f | 83 | channelId: videoChannelId, |
0e1dc3e7 C |
84 | fixture: 'video_short1.webm' |
85 | } | |
86 | await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | |
87 | ||
652b3056 | 88 | await wait(10000) |
0e1dc3e7 | 89 | |
9a27cdc2 | 90 | // All servers should have this video |
0e1dc3e7 C |
91 | for (const server of servers) { |
92 | let baseMagnet = null | |
93 | ||
94 | const res = await getVideosList(server.url) | |
95 | ||
96 | const videos = res.body.data | |
97 | expect(videos).to.be.an('array') | |
98 | expect(videos.length).to.equal(1) | |
99 | const video = videos[0] | |
9a27cdc2 | 100 | expect(video.name).to.equal('my super name for server 1') |
0e1dc3e7 C |
101 | expect(video.category).to.equal(5) |
102 | expect(video.categoryLabel).to.equal('Sports') | |
103 | expect(video.licence).to.equal(4) | |
104 | expect(video.licenceLabel).to.equal('Attribution - Non Commercial') | |
105 | expect(video.language).to.equal(9) | |
106 | expect(video.languageLabel).to.equal('Japanese') | |
107 | expect(video.nsfw).to.be.ok | |
9a27cdc2 C |
108 | expect(video.description).to.equal('my super description for server 1') |
109 | expect(video.serverHost).to.equal('localhost:9001') | |
0e1dc3e7 C |
110 | expect(video.duration).to.equal(10) |
111 | expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) | |
112 | expect(dateIsValid(video.createdAt)).to.be.true | |
113 | expect(dateIsValid(video.updatedAt)).to.be.true | |
b1fa3eba | 114 | expect(video.accountName).to.equal('root') |
0e1dc3e7 | 115 | |
5f04dd2f C |
116 | const res2 = await getVideo(server.url, video.uuid) |
117 | const videoDetails = res2.body | |
118 | ||
119 | expect(videoDetails.channel.name).to.equal('my channel') | |
120 | expect(videoDetails.channel.description).to.equal('super channel') | |
b1fa3eba | 121 | expect(videoDetails.account.name).to.equal('root') |
5f04dd2f C |
122 | expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true |
123 | expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true | |
124 | expect(videoDetails.files).to.have.lengthOf(1) | |
0e1dc3e7 | 125 | |
5f04dd2f | 126 | const file = videoDetails.files[0] |
0e1dc3e7 C |
127 | const magnetUri = file.magnetUri |
128 | expect(file.magnetUri).to.have.lengthOf.above(2) | |
9a27cdc2 C |
129 | expect(file.torrentUrl).to |
130 | .equal(`http://${videoDetails.serverHost}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`) | |
131 | expect(file.fileUrl).to.equal(`http://${videoDetails.serverHost}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`) | |
14d3270f C |
132 | expect(file.resolution).to.equal(720) |
133 | expect(file.resolutionLabel).to.equal('720p') | |
0e1dc3e7 C |
134 | expect(file.size).to.equal(572456) |
135 | ||
136 | if (server.url !== 'http://localhost:9001') { | |
137 | expect(video.isLocal).to.be.false | |
5f04dd2f | 138 | expect(videoDetails.channel.isLocal).to.be.false |
0e1dc3e7 C |
139 | } else { |
140 | expect(video.isLocal).to.be.true | |
5f04dd2f | 141 | expect(videoDetails.channel.isLocal).to.be.true |
0e1dc3e7 C |
142 | } |
143 | ||
9a27cdc2 | 144 | // All servers should have the same magnet Uri |
0e1dc3e7 C |
145 | if (baseMagnet === null) { |
146 | baseMagnet = magnetUri | |
147 | } else { | |
148 | expect(baseMagnet).to.equal(magnetUri) | |
149 | } | |
150 | ||
151 | const test = await testVideoImage(server.url, 'video_short1.webm', video.thumbnailPath) | |
152 | expect(test).to.equal(true) | |
153 | } | |
154 | }) | |
155 | ||
9a27cdc2 | 156 | it('Should upload the video on server 2 and propagate on each server', async function () { |
572f8d3d | 157 | this.timeout(50000) |
0e1dc3e7 | 158 | |
5f04dd2f C |
159 | const user = { |
160 | username: 'user1', | |
161 | password: 'super_password' | |
162 | } | |
163 | await createUser(servers[1].url, servers[1].accessToken, user.username, user.password) | |
164 | const userAccessToken = await getUserAccessToken(servers[1], user) | |
165 | ||
0e1dc3e7 | 166 | const videoAttributes = { |
9a27cdc2 | 167 | name: 'my super name for server 2', |
0e1dc3e7 C |
168 | category: 4, |
169 | licence: 3, | |
170 | language: 11, | |
171 | nsfw: true, | |
9a27cdc2 | 172 | description: 'my super description for server 2', |
0e1dc3e7 C |
173 | tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], |
174 | fixture: 'video_short2.webm' | |
175 | } | |
5f04dd2f | 176 | await uploadVideo(servers[1].url, userAccessToken, videoAttributes) |
0e1dc3e7 | 177 | |
572f8d3d | 178 | // Transcoding |
62c852b2 | 179 | await wait(30000) |
0e1dc3e7 | 180 | |
9a27cdc2 | 181 | // All servers should have this video |
0e1dc3e7 | 182 | for (const server of servers) { |
40298b02 | 183 | let baseMagnet = {} |
0e1dc3e7 C |
184 | |
185 | const res = await getVideosList(server.url) | |
186 | ||
187 | const videos = res.body.data | |
188 | expect(videos).to.be.an('array') | |
189 | expect(videos.length).to.equal(2) | |
190 | const video = videos[1] | |
9a27cdc2 | 191 | expect(video.name).to.equal('my super name for server 2') |
0e1dc3e7 C |
192 | expect(video.category).to.equal(4) |
193 | expect(video.categoryLabel).to.equal('Art') | |
194 | expect(video.licence).to.equal(3) | |
195 | expect(video.licenceLabel).to.equal('Attribution - No Derivatives') | |
196 | expect(video.language).to.equal(11) | |
197 | expect(video.languageLabel).to.equal('German') | |
198 | expect(video.nsfw).to.be.true | |
9a27cdc2 C |
199 | expect(video.description).to.equal('my super description for server 2') |
200 | expect(video.serverHost).to.equal('localhost:9002') | |
0e1dc3e7 C |
201 | expect(video.duration).to.equal(5) |
202 | expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) | |
203 | expect(dateIsValid(video.createdAt)).to.be.true | |
204 | expect(dateIsValid(video.updatedAt)).to.be.true | |
b1fa3eba | 205 | expect(video.accountName).to.equal('user1') |
5f04dd2f C |
206 | |
207 | if (server.url !== 'http://localhost:9002') { | |
208 | expect(video.isLocal).to.be.false | |
209 | } else { | |
210 | expect(video.isLocal).to.be.true | |
211 | } | |
0e1dc3e7 | 212 | |
5f04dd2f C |
213 | const res2 = await getVideo(server.url, video.uuid) |
214 | const videoDetails = res2.body | |
215 | ||
216 | expect(videoDetails.channel.name).to.equal('Default user1 channel') | |
217 | expect(dateIsValid(videoDetails.channel.createdAt)).to.be.true | |
218 | expect(dateIsValid(videoDetails.channel.updatedAt)).to.be.true | |
219 | ||
220 | expect(videoDetails.files).to.have.lengthOf(4) | |
0e1dc3e7 | 221 | |
40298b02 | 222 | // Check common attributes |
5f04dd2f | 223 | for (const file of videoDetails.files) { |
40298b02 | 224 | expect(file.magnetUri).to.have.lengthOf.above(2) |
0e1dc3e7 | 225 | |
9a27cdc2 | 226 | // All servers should have the same magnet Uri |
40298b02 C |
227 | if (baseMagnet[file.resolution] === undefined) { |
228 | baseMagnet[file.resolution] = file.magnet | |
229 | } else { | |
230 | expect(baseMagnet[file.resolution]).to.equal(file.magnet) | |
231 | } | |
0e1dc3e7 C |
232 | } |
233 | ||
5f04dd2f | 234 | const file240p = videoDetails.files.find(f => f.resolution === 240) |
40298b02 C |
235 | expect(file240p).not.to.be.undefined |
236 | expect(file240p.resolutionLabel).to.equal('240p') | |
031094f7 | 237 | expect(file240p.size).to.be.above(180000).and.below(200000) |
40298b02 | 238 | |
5f04dd2f | 239 | const file360p = videoDetails.files.find(f => f.resolution === 360) |
40298b02 C |
240 | expect(file360p).not.to.be.undefined |
241 | expect(file360p.resolutionLabel).to.equal('360p') | |
031094f7 | 242 | expect(file360p.size).to.be.above(270000).and.below(290000) |
40298b02 | 243 | |
5f04dd2f | 244 | const file480p = videoDetails.files.find(f => f.resolution === 480) |
40298b02 C |
245 | expect(file480p).not.to.be.undefined |
246 | expect(file480p.resolutionLabel).to.equal('480p') | |
031094f7 | 247 | expect(file480p.size).to.be.above(380000).and.below(400000) |
40298b02 | 248 | |
5f04dd2f | 249 | const file720p = videoDetails.files.find(f => f.resolution === 720) |
40298b02 C |
250 | expect(file720p).not.to.be.undefined |
251 | expect(file720p.resolutionLabel).to.equal('720p') | |
14d3270f | 252 | expect(file720p.size).to.be.above(700000).and.below(7200000) |
40298b02 | 253 | |
5f04dd2f | 254 | const test = await testVideoImage(server.url, 'video_short2.webm', videoDetails.thumbnailPath) |
0e1dc3e7 C |
255 | expect(test).to.equal(true) |
256 | } | |
257 | }) | |
258 | ||
9a27cdc2 | 259 | it('Should upload two videos on server 3 and propagate on each server', async function () { |
0e1dc3e7 C |
260 | this.timeout(45000) |
261 | ||
262 | const videoAttributes1 = { | |
9a27cdc2 | 263 | name: 'my super name for server 3', |
0e1dc3e7 C |
264 | category: 6, |
265 | licence: 5, | |
266 | language: 11, | |
267 | nsfw: true, | |
9a27cdc2 | 268 | description: 'my super description for server 3', |
0e1dc3e7 C |
269 | tags: [ 'tag1p3' ], |
270 | fixture: 'video_short3.webm' | |
271 | } | |
272 | await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1) | |
273 | ||
274 | const videoAttributes2 = { | |
9a27cdc2 | 275 | name: 'my super name for server 3-2', |
0e1dc3e7 C |
276 | category: 7, |
277 | licence: 6, | |
278 | language: 12, | |
279 | nsfw: false, | |
9a27cdc2 | 280 | description: 'my super description for server 3-2', |
0e1dc3e7 C |
281 | tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], |
282 | fixture: 'video_short.webm' | |
283 | } | |
284 | await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2) | |
285 | ||
572f8d3d | 286 | await wait(10000) |
0e1dc3e7 C |
287 | |
288 | let baseMagnet = null | |
9a27cdc2 | 289 | // All servers should have this video |
0e1dc3e7 C |
290 | for (const server of servers) { |
291 | const res = await getVideosList(server.url) | |
292 | ||
293 | const videos = res.body.data | |
294 | expect(videos).to.be.an('array') | |
295 | expect(videos.length).to.equal(4) | |
296 | ||
297 | // We not sure about the order of the two last uploads | |
298 | let video1 = null | |
299 | let video2 = null | |
9a27cdc2 | 300 | if (videos[2].name === 'my super name for server 3') { |
0e1dc3e7 C |
301 | video1 = videos[2] |
302 | video2 = videos[3] | |
303 | } else { | |
304 | video1 = videos[3] | |
305 | video2 = videos[2] | |
306 | } | |
307 | ||
9a27cdc2 | 308 | expect(video1.name).to.equal('my super name for server 3') |
0e1dc3e7 C |
309 | expect(video1.category).to.equal(6) |
310 | expect(video1.categoryLabel).to.equal('Travels') | |
311 | expect(video1.licence).to.equal(5) | |
312 | expect(video1.licenceLabel).to.equal('Attribution - Non Commercial - Share Alike') | |
313 | expect(video1.language).to.equal(11) | |
314 | expect(video1.languageLabel).to.equal('German') | |
315 | expect(video1.nsfw).to.be.ok | |
9a27cdc2 C |
316 | expect(video1.description).to.equal('my super description for server 3') |
317 | expect(video1.serverHost).to.equal('localhost:9003') | |
0e1dc3e7 C |
318 | expect(video1.duration).to.equal(5) |
319 | expect(video1.tags).to.deep.equal([ 'tag1p3' ]) | |
b1fa3eba | 320 | expect(video1.accountName).to.equal('root') |
0e1dc3e7 C |
321 | expect(dateIsValid(video1.createdAt)).to.be.true |
322 | expect(dateIsValid(video1.updatedAt)).to.be.true | |
323 | ||
5f04dd2f C |
324 | const res2 = await getVideo(server.url, video1.id) |
325 | const video1Details = res2.body | |
326 | expect(video1Details.files).to.have.lengthOf(1) | |
0e1dc3e7 | 327 | |
5f04dd2f | 328 | const file1 = video1Details.files[0] |
0e1dc3e7 | 329 | expect(file1.magnetUri).to.have.lengthOf.above(2) |
14d3270f C |
330 | expect(file1.resolution).to.equal(720) |
331 | expect(file1.resolutionLabel).to.equal('720p') | |
0e1dc3e7 C |
332 | expect(file1.size).to.equal(292677) |
333 | ||
9a27cdc2 | 334 | expect(video2.name).to.equal('my super name for server 3-2') |
0e1dc3e7 C |
335 | expect(video2.category).to.equal(7) |
336 | expect(video2.categoryLabel).to.equal('Gaming') | |
337 | expect(video2.licence).to.equal(6) | |
338 | expect(video2.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives') | |
339 | expect(video2.language).to.equal(12) | |
340 | expect(video2.languageLabel).to.equal('Korean') | |
341 | expect(video2.nsfw).to.be.false | |
9a27cdc2 C |
342 | expect(video2.description).to.equal('my super description for server 3-2') |
343 | expect(video2.serverHost).to.equal('localhost:9003') | |
0e1dc3e7 C |
344 | expect(video2.duration).to.equal(5) |
345 | expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) | |
b1fa3eba | 346 | expect(video2.accountName).to.equal('root') |
0e1dc3e7 C |
347 | expect(dateIsValid(video2.createdAt)).to.be.true |
348 | expect(dateIsValid(video2.updatedAt)).to.be.true | |
349 | ||
5f04dd2f C |
350 | const res3 = await getVideo(server.url, video2.id) |
351 | const video2Details = res3.body | |
0e1dc3e7 | 352 | |
5f04dd2f C |
353 | expect(video2Details.files).to.have.lengthOf(1) |
354 | ||
355 | const file2 = video2Details.files[0] | |
0e1dc3e7 C |
356 | const magnetUri2 = file2.magnetUri |
357 | expect(file2.magnetUri).to.have.lengthOf.above(2) | |
14d3270f C |
358 | expect(file2.resolution).to.equal(720) |
359 | expect(file2.resolutionLabel).to.equal('720p') | |
0e1dc3e7 C |
360 | expect(file2.size).to.equal(218910) |
361 | ||
362 | if (server.url !== 'http://localhost:9003') { | |
363 | expect(video1.isLocal).to.be.false | |
364 | expect(video2.isLocal).to.be.false | |
365 | } else { | |
366 | expect(video1.isLocal).to.be.true | |
367 | expect(video2.isLocal).to.be.true | |
368 | } | |
369 | ||
9a27cdc2 | 370 | // All servers should have the same magnet Uri |
0e1dc3e7 C |
371 | if (baseMagnet === null) { |
372 | baseMagnet = magnetUri2 | |
373 | } else { | |
374 | expect(baseMagnet).to.equal(magnetUri2) | |
375 | } | |
376 | ||
377 | const test1 = await testVideoImage(server.url, 'video_short3.webm', video1.thumbnailPath) | |
378 | expect(test1).to.equal(true) | |
379 | ||
380 | const test2 = await testVideoImage(server.url, 'video_short.webm', video2.thumbnailPath) | |
381 | expect(test2).to.equal(true) | |
382 | } | |
383 | }) | |
384 | }) | |
385 | ||
386 | describe('Should seed the uploaded video', function () { | |
9a27cdc2 | 387 | it('Should add the file 1 by asking server 3', async function () { |
572f8d3d | 388 | this.timeout(10000) |
0e1dc3e7 C |
389 | |
390 | const res = await getVideosList(servers[2].url) | |
391 | ||
392 | const video = res.body.data[0] | |
393 | toRemove.push(res.body.data[2]) | |
394 | toRemove.push(res.body.data[3]) | |
395 | ||
5f04dd2f C |
396 | const res2 = await getVideo(servers[2].url, video.id) |
397 | const videoDetails = res2.body | |
398 | ||
399 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) | |
0e1dc3e7 C |
400 | expect(torrent.files).to.be.an('array') |
401 | expect(torrent.files.length).to.equal(1) | |
402 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
403 | }) | |
404 | ||
9a27cdc2 | 405 | it('Should add the file 2 by asking server 1', async function () { |
572f8d3d | 406 | this.timeout(10000) |
0e1dc3e7 C |
407 | |
408 | const res = await getVideosList(servers[0].url) | |
409 | ||
410 | const video = res.body.data[1] | |
5f04dd2f C |
411 | const res2 = await getVideo(servers[0].url, video.id) |
412 | const videoDetails = res2.body | |
0e1dc3e7 | 413 | |
5f04dd2f | 414 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) |
0e1dc3e7 C |
415 | expect(torrent.files).to.be.an('array') |
416 | expect(torrent.files.length).to.equal(1) | |
417 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
418 | }) | |
419 | ||
9a27cdc2 | 420 | it('Should add the file 3 by asking server 2', async function () { |
572f8d3d | 421 | this.timeout(10000) |
0e1dc3e7 C |
422 | |
423 | const res = await getVideosList(servers[1].url) | |
424 | ||
425 | const video = res.body.data[2] | |
5f04dd2f C |
426 | const res2 = await getVideo(servers[1].url, video.id) |
427 | const videoDetails = res2.body | |
0e1dc3e7 | 428 | |
5f04dd2f | 429 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) |
0e1dc3e7 C |
430 | expect(torrent.files).to.be.an('array') |
431 | expect(torrent.files.length).to.equal(1) | |
432 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
433 | }) | |
434 | ||
9a27cdc2 | 435 | it('Should add the file 3-2 by asking server 1', async function () { |
572f8d3d | 436 | this.timeout(10000) |
0e1dc3e7 C |
437 | |
438 | const res = await getVideosList(servers[0].url) | |
439 | ||
440 | const video = res.body.data[3] | |
5f04dd2f C |
441 | const res2 = await getVideo(servers[0].url, video.id) |
442 | const videoDetails = res2.body | |
0e1dc3e7 | 443 | |
5f04dd2f | 444 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) |
0e1dc3e7 C |
445 | expect(torrent.files).to.be.an('array') |
446 | expect(torrent.files.length).to.equal(1) | |
447 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
448 | }) | |
14d3270f | 449 | |
9a27cdc2 | 450 | it('Should add the file 2 in 360p by asking server 1', async function () { |
572f8d3d | 451 | this.timeout(10000) |
14d3270f C |
452 | |
453 | const res = await getVideosList(servers[0].url) | |
454 | ||
9a27cdc2 | 455 | const video = res.body.data.find(v => v.name === 'my super name for server 2') |
5f04dd2f C |
456 | const res2 = await getVideo(servers[0].url, video.id) |
457 | const videoDetails = res2.body | |
458 | ||
459 | const file = videoDetails.files.find(f => f.resolution === 360) | |
14d3270f C |
460 | expect(file).not.to.be.undefined |
461 | ||
462 | const torrent = await webtorrentAdd(file.magnetUri) | |
463 | expect(torrent.files).to.be.an('array') | |
464 | expect(torrent.files.length).to.equal(1) | |
465 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
466 | }) | |
0e1dc3e7 C |
467 | }) |
468 | ||
469 | describe('Should update video views, likes and dislikes', function () { | |
9a27cdc2 C |
470 | let localVideosServer3 = [] |
471 | let remoteVideosServer1 = [] | |
472 | let remoteVideosServer2 = [] | |
473 | let remoteVideosServer3 = [] | |
0e1dc3e7 C |
474 | |
475 | before(async function () { | |
476 | const res1 = await getVideosList(servers[0].url) | |
9a27cdc2 | 477 | remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid) |
0e1dc3e7 C |
478 | |
479 | const res2 = await getVideosList(servers[1].url) | |
9a27cdc2 | 480 | remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid) |
0e1dc3e7 C |
481 | |
482 | const res3 = await getVideosList(servers[2].url) | |
9a27cdc2 C |
483 | localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid) |
484 | remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid) | |
0e1dc3e7 C |
485 | }) |
486 | ||
487 | it('Should view multiple videos on owned servers', async function () { | |
572f8d3d | 488 | this.timeout(10000) |
0e1dc3e7 C |
489 | |
490 | const tasks: Promise<any>[] = [] | |
1f3e9fec C |
491 | tasks.push(viewVideo(servers[2].url, localVideosServer3[0])) |
492 | tasks.push(viewVideo(servers[2].url, localVideosServer3[0])) | |
493 | tasks.push(viewVideo(servers[2].url, localVideosServer3[0])) | |
494 | tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) | |
0e1dc3e7 C |
495 | |
496 | await Promise.all(tasks) | |
497 | ||
572f8d3d | 498 | await wait(5000) |
0e1dc3e7 C |
499 | |
500 | for (const server of servers) { | |
501 | const res = await getVideosList(server.url) | |
502 | ||
503 | const videos = res.body.data | |
9a27cdc2 C |
504 | const video0 = videos.find(v => v.uuid === localVideosServer3[0]) |
505 | const video1 = videos.find(v => v.uuid === localVideosServer3[1]) | |
5f04dd2f | 506 | |
1f3e9fec C |
507 | expect(video0.views).to.equal(3) |
508 | expect(video1.views).to.equal(1) | |
0e1dc3e7 C |
509 | } |
510 | }) | |
511 | ||
512 | it('Should view multiple videos on each servers', async function () { | |
572f8d3d | 513 | this.timeout(15000) |
0e1dc3e7 C |
514 | |
515 | const tasks: Promise<any>[] = [] | |
1f3e9fec C |
516 | tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0])) |
517 | tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) | |
518 | tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) | |
519 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[0])) | |
520 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) | |
521 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) | |
522 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) | |
523 | tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) | |
524 | tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) | |
525 | tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) | |
0e1dc3e7 C |
526 | |
527 | await Promise.all(tasks) | |
528 | ||
572f8d3d | 529 | await wait(10000) |
0e1dc3e7 C |
530 | |
531 | let baseVideos = null | |
532 | ||
533 | for (const server of servers) { | |
534 | const res = await getVideosList(server.url) | |
535 | ||
536 | const videos = res.body.data | |
537 | ||
538 | // Initialize base videos for future comparisons | |
539 | if (baseVideos === null) { | |
540 | baseVideos = videos | |
35a097b8 | 541 | continue |
0e1dc3e7 C |
542 | } |
543 | ||
544 | for (const baseVideo of baseVideos) { | |
545 | const sameVideo = videos.find(video => video.name === baseVideo.name) | |
546 | expect(baseVideo.views).to.equal(sameVideo.views) | |
547 | } | |
548 | } | |
549 | }) | |
550 | ||
551 | it('Should like and dislikes videos on different services', async function () { | |
572f8d3d | 552 | this.timeout(20000) |
0e1dc3e7 C |
553 | |
554 | const tasks: Promise<any>[] = [] | |
9a27cdc2 C |
555 | tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')) |
556 | tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike')) | |
557 | tasks.push(rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')) | |
558 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like')) | |
559 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike')) | |
560 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike')) | |
561 | tasks.push(rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like')) | |
0e1dc3e7 C |
562 | |
563 | await Promise.all(tasks) | |
564 | ||
572f8d3d | 565 | await wait(10000) |
0e1dc3e7 C |
566 | |
567 | let baseVideos = null | |
568 | for (const server of servers) { | |
569 | const res = await getVideosList(server.url) | |
570 | ||
571 | const videos = res.body.data | |
572 | ||
573 | // Initialize base videos for future comparisons | |
574 | if (baseVideos === null) { | |
575 | baseVideos = videos | |
35a097b8 | 576 | continue |
0e1dc3e7 C |
577 | } |
578 | ||
35a097b8 | 579 | for (const baseVideo of baseVideos) { |
0e1dc3e7 C |
580 | const sameVideo = videos.find(video => video.name === baseVideo.name) |
581 | expect(baseVideo.likes).to.equal(sameVideo.likes) | |
582 | expect(baseVideo.dislikes).to.equal(sameVideo.dislikes) | |
35a097b8 | 583 | } |
0e1dc3e7 C |
584 | } |
585 | }) | |
586 | }) | |
587 | ||
588 | describe('Should manipulate these videos', function () { | |
9a27cdc2 | 589 | it('Should update the video 3 by asking server 3', async function () { |
572f8d3d | 590 | this.timeout(10000) |
0e1dc3e7 C |
591 | |
592 | const attributes = { | |
593 | name: 'my super video updated', | |
594 | category: 10, | |
595 | licence: 7, | |
596 | language: 13, | |
597 | nsfw: true, | |
598 | description: 'my super description updated', | |
599 | tags: [ 'tag_up_1', 'tag_up_2' ] | |
600 | } | |
601 | ||
602 | await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) | |
603 | ||
572f8d3d | 604 | await wait(5000) |
0e1dc3e7 C |
605 | }) |
606 | ||
9a27cdc2 | 607 | it('Should have the video 3 updated on each server', async function () { |
572f8d3d | 608 | this.timeout(10000) |
0e1dc3e7 C |
609 | |
610 | for (const server of servers) { | |
611 | const res = await getVideosList(server.url) | |
612 | ||
613 | const videos = res.body.data | |
614 | const videoUpdated = videos.find(video => video.name === 'my super video updated') | |
615 | ||
616 | expect(!!videoUpdated).to.be.true | |
617 | expect(videoUpdated.category).to.equal(10) | |
618 | expect(videoUpdated.categoryLabel).to.equal('Entertainment') | |
619 | expect(videoUpdated.licence).to.equal(7) | |
620 | expect(videoUpdated.licenceLabel).to.equal('Public Domain Dedication') | |
621 | expect(videoUpdated.language).to.equal(13) | |
622 | expect(videoUpdated.languageLabel).to.equal('French') | |
623 | expect(videoUpdated.nsfw).to.be.ok | |
624 | expect(videoUpdated.description).to.equal('my super description updated') | |
625 | expect(videoUpdated.tags).to.deep.equal([ 'tag_up_1', 'tag_up_2' ]) | |
626 | expect(dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true | |
627 | ||
5f04dd2f C |
628 | const res2 = await getVideo(server.url, videoUpdated.uuid) |
629 | const videoUpdatedDetails = res2.body | |
630 | ||
631 | const file = videoUpdatedDetails .files[0] | |
0e1dc3e7 | 632 | expect(file.magnetUri).to.have.lengthOf.above(2) |
14d3270f C |
633 | expect(file.resolution).to.equal(720) |
634 | expect(file.resolutionLabel).to.equal('720p') | |
0e1dc3e7 C |
635 | expect(file.size).to.equal(292677) |
636 | ||
637 | const test = await testVideoImage(server.url, 'video_short3.webm', videoUpdated.thumbnailPath) | |
638 | expect(test).to.equal(true) | |
639 | ||
640 | // Avoid "duplicate torrent" errors | |
641 | const refreshWebTorrent = true | |
5f04dd2f | 642 | const torrent = await webtorrentAdd(videoUpdatedDetails .files[0].magnetUri, refreshWebTorrent) |
0e1dc3e7 C |
643 | expect(torrent.files).to.be.an('array') |
644 | expect(torrent.files.length).to.equal(1) | |
645 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
646 | } | |
647 | }) | |
648 | ||
9a27cdc2 | 649 | it('Should remove the videos 3 and 3-2 by asking server 3', async function () { |
572f8d3d | 650 | this.timeout(10000) |
0e1dc3e7 C |
651 | |
652 | await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id) | |
653 | await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id) | |
654 | ||
572f8d3d | 655 | await wait(5000) |
0e1dc3e7 C |
656 | }) |
657 | ||
9a27cdc2 | 658 | it('Should have videos 1 and 3 on each server', async function () { |
0e1dc3e7 C |
659 | for (const server of servers) { |
660 | const res = await getVideosList(server.url) | |
661 | ||
662 | const videos = res.body.data | |
663 | expect(videos).to.be.an('array') | |
664 | expect(videos.length).to.equal(2) | |
665 | expect(videos[0].name).not.to.equal(videos[1].name) | |
666 | expect(videos[0].name).not.to.equal(toRemove[0].name) | |
667 | expect(videos[1].name).not.to.equal(toRemove[0].name) | |
668 | expect(videos[0].name).not.to.equal(toRemove[1].name) | |
669 | expect(videos[1].name).not.to.equal(toRemove[1].name) | |
670 | ||
9a27cdc2 | 671 | videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid |
0e1dc3e7 C |
672 | } |
673 | }) | |
674 | ||
9a27cdc2 | 675 | it('Should get the same video by UUID on each server', async function () { |
0e1dc3e7 C |
676 | let baseVideo = null |
677 | for (const server of servers) { | |
678 | const res = await getVideo(server.url, videoUUID) | |
679 | ||
680 | const video = res.body | |
681 | ||
682 | if (baseVideo === null) { | |
683 | baseVideo = video | |
35a097b8 | 684 | continue |
0e1dc3e7 C |
685 | } |
686 | ||
687 | expect(baseVideo.name).to.equal(video.name) | |
688 | expect(baseVideo.uuid).to.equal(video.uuid) | |
689 | expect(baseVideo.category).to.equal(video.category) | |
690 | expect(baseVideo.language).to.equal(video.language) | |
691 | expect(baseVideo.licence).to.equal(video.licence) | |
692 | expect(baseVideo.category).to.equal(video.category) | |
693 | expect(baseVideo.nsfw).to.equal(video.nsfw) | |
b1fa3eba | 694 | expect(baseVideo.accountName).to.equal(video.accountName) |
0e1dc3e7 C |
695 | expect(baseVideo.tags).to.deep.equal(video.tags) |
696 | } | |
697 | }) | |
698 | ||
9a27cdc2 | 699 | it('Should get the preview from each server', async function () { |
0e1dc3e7 C |
700 | for (const server of servers) { |
701 | const res = await getVideo(server.url, videoUUID) | |
702 | const video = res.body | |
703 | ||
704 | const test = await testVideoImage(server.url, 'video_short1-preview.webm', video.previewPath) | |
705 | expect(test).to.equal(true) | |
706 | } | |
707 | }) | |
708 | }) | |
709 | ||
710 | after(async function () { | |
711 | killallServers(servers) | |
712 | ||
713 | // Keep the logs if the test failed | |
714 | if (this['ok']) { | |
715 | await flushTests() | |
716 | } | |
717 | }) | |
718 | }) |