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