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