]>
Commit | Line | Data |
---|---|---|
0e1dc3e7 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
0e1dc3e7 | 3 | import * as chai from 'chai' |
d50acfab | 4 | import 'mocha' |
b1a134ee | 5 | import { join } from 'path' |
f595d394 | 6 | import * as request from 'supertest' |
b1f5b93e | 7 | import { VideoPrivacy } from '../../../../shared/models/videos' |
c5d31dba | 8 | import { VideoComment, VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model' |
0e1dc3e7 C |
9 | |
10 | import { | |
b64c950a C |
11 | addVideoChannel, |
12 | checkVideoFilesWereRemoved, | |
13 | completeVideoCheck, | |
14 | createUser, | |
15 | dateIsValid, | |
16 | doubleFollow, | |
17 | flushAndRunMultipleServers, | |
18 | flushTests, | |
19 | getVideo, | |
20 | getVideoChannelsList, | |
21 | getVideosList, | |
22 | killallServers, | |
23 | rateVideo, | |
24 | removeVideo, | |
25 | ServerInfo, | |
26 | setAccessTokensToServers, | |
27 | testImage, | |
28 | updateVideo, | |
29 | uploadVideo, | |
30 | userLogin, | |
31 | viewVideo, | |
32 | wait, | |
33 | webtorrentAdd | |
b1f5b93e | 34 | } from '../../utils' |
c5d31dba | 35 | import { |
b64c950a C |
36 | addVideoCommentReply, |
37 | addVideoCommentThread, | |
38 | deleteVideoComment, | |
39 | getVideoCommentThreads, | |
c5d31dba C |
40 | getVideoThreadComments |
41 | } from '../../utils/videos/video-comments' | |
0e1dc3e7 C |
42 | |
43 | const expect = chai.expect | |
44 | ||
9a27cdc2 | 45 | describe('Test multiple servers', function () { |
0e1dc3e7 C |
46 | let servers: ServerInfo[] = [] |
47 | const toRemove = [] | |
48 | let videoUUID = '' | |
5f04dd2f | 49 | let videoChannelId: number |
0e1dc3e7 C |
50 | |
51 | before(async function () { | |
52 | this.timeout(120000) | |
53 | ||
54 | servers = await flushAndRunMultipleServers(3) | |
55 | ||
56 | // Get the access tokens | |
57 | await setAccessTokensToServers(servers) | |
58 | ||
5f04dd2f C |
59 | const videoChannel = { |
60 | name: 'my channel', | |
61 | description: 'super channel' | |
62 | } | |
63 | await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) | |
64 | const channelRes = await getVideoChannelsList(servers[0].url, 0, 1) | |
65 | videoChannelId = channelRes.body.data[0].id | |
66 | ||
9a27cdc2 C |
67 | // Server 1 and server 2 follow each other |
68 | await doubleFollow(servers[0], servers[1]) | |
69 | // Server 1 and server 3 follow each other | |
70 | await doubleFollow(servers[0], servers[2]) | |
71 | // Server 2 and server 3 follow each other | |
72 | await doubleFollow(servers[1], servers[2]) | |
0e1dc3e7 C |
73 | }) |
74 | ||
9a27cdc2 | 75 | it('Should not have videos for all servers', async function () { |
0e1dc3e7 C |
76 | for (const server of servers) { |
77 | const res = await getVideosList(server.url) | |
78 | const videos = res.body.data | |
79 | expect(videos).to.be.an('array') | |
80 | expect(videos.length).to.equal(0) | |
81 | } | |
82 | }) | |
83 | ||
9a27cdc2 C |
84 | describe('Should upload the video and propagate on each server', function () { |
85 | it('Should upload the video on server 1 and propagate on each server', async function () { | |
652b3056 | 86 | this.timeout(25000) |
0e1dc3e7 C |
87 | |
88 | const videoAttributes = { | |
9a27cdc2 | 89 | name: 'my super name for server 1', |
0e1dc3e7 C |
90 | category: 5, |
91 | licence: 4, | |
92 | language: 9, | |
93 | nsfw: true, | |
9a27cdc2 | 94 | description: 'my super description for server 1', |
2422c46b | 95 | support: 'my super support text for server 1', |
0e1dc3e7 | 96 | tags: [ 'tag1p1', 'tag2p1' ], |
5f04dd2f | 97 | channelId: videoChannelId, |
0e1dc3e7 C |
98 | fixture: 'video_short1.webm' |
99 | } | |
100 | await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) | |
101 | ||
652b3056 | 102 | await wait(10000) |
0e1dc3e7 | 103 | |
9a27cdc2 | 104 | // All servers should have this video |
0e1dc3e7 | 105 | for (const server of servers) { |
b1f5b93e C |
106 | const isLocal = server.url === 'http://localhost:9001' |
107 | const checkAttributes = { | |
108 | name: 'my super name for server 1', | |
109 | category: 5, | |
110 | licence: 4, | |
111 | language: 9, | |
112 | nsfw: true, | |
113 | description: 'my super description for server 1', | |
2422c46b | 114 | support: 'my super support text for server 1', |
b64c950a C |
115 | account: { |
116 | name: 'root', | |
117 | host: 'localhost:9001' | |
118 | }, | |
b1f5b93e C |
119 | isLocal, |
120 | duration: 10, | |
121 | tags: [ 'tag1p1', 'tag2p1' ], | |
122 | privacy: VideoPrivacy.PUBLIC, | |
47564bbe | 123 | commentsEnabled: true, |
b1f5b93e C |
124 | channel: { |
125 | name: 'my channel', | |
126 | description: 'super channel', | |
127 | isLocal | |
128 | }, | |
8b0d42ee | 129 | fixture: 'video_short1.webm', |
b1f5b93e C |
130 | files: [ |
131 | { | |
132 | resolution: 720, | |
133 | size: 572456 | |
134 | } | |
135 | ] | |
136 | } | |
0e1dc3e7 C |
137 | |
138 | const res = await getVideosList(server.url) | |
0e1dc3e7 C |
139 | const videos = res.body.data |
140 | expect(videos).to.be.an('array') | |
141 | expect(videos.length).to.equal(1) | |
142 | const video = videos[0] | |
0e1dc3e7 | 143 | |
b1f5b93e | 144 | await completeVideoCheck(server.url, video, checkAttributes) |
0e1dc3e7 C |
145 | } |
146 | }) | |
147 | ||
9a27cdc2 | 148 | it('Should upload the video on server 2 and propagate on each server', async function () { |
572f8d3d | 149 | this.timeout(50000) |
0e1dc3e7 | 150 | |
5f04dd2f C |
151 | const user = { |
152 | username: 'user1', | |
153 | password: 'super_password' | |
154 | } | |
155 | await createUser(servers[1].url, servers[1].accessToken, user.username, user.password) | |
eec63bbc | 156 | const userAccessToken = await userLogin(servers[1], user) |
5f04dd2f | 157 | |
0e1dc3e7 | 158 | const videoAttributes = { |
9a27cdc2 | 159 | name: 'my super name for server 2', |
0e1dc3e7 C |
160 | category: 4, |
161 | licence: 3, | |
162 | language: 11, | |
163 | nsfw: true, | |
9a27cdc2 | 164 | description: 'my super description for server 2', |
2422c46b | 165 | support: 'my super support text for server 2', |
0e1dc3e7 | 166 | tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], |
ac81d1a0 C |
167 | fixture: 'video_short2.webm', |
168 | thumbnailfile: 'thumbnail.jpg', | |
169 | previewfile: 'preview.jpg' | |
0e1dc3e7 | 170 | } |
5f04dd2f | 171 | await uploadVideo(servers[1].url, userAccessToken, videoAttributes) |
0e1dc3e7 | 172 | |
572f8d3d | 173 | // Transcoding |
62c852b2 | 174 | await wait(30000) |
0e1dc3e7 | 175 | |
9a27cdc2 | 176 | // All servers should have this video |
0e1dc3e7 | 177 | for (const server of servers) { |
b1f5b93e C |
178 | const isLocal = server.url === 'http://localhost:9002' |
179 | const checkAttributes = { | |
180 | name: 'my super name for server 2', | |
181 | category: 4, | |
182 | licence: 3, | |
183 | language: 11, | |
184 | nsfw: true, | |
185 | description: 'my super description for server 2', | |
2422c46b | 186 | support: 'my super support text for server 2', |
b64c950a C |
187 | account: { |
188 | name: 'user1', | |
189 | host: 'localhost:9002' | |
190 | }, | |
b1f5b93e | 191 | isLocal, |
47564bbe | 192 | commentsEnabled: true, |
b1f5b93e C |
193 | duration: 5, |
194 | tags: [ 'tag1p2', 'tag2p2', 'tag3p2' ], | |
195 | privacy: VideoPrivacy.PUBLIC, | |
196 | channel: { | |
197 | name: 'Default user1 channel', | |
198 | description: 'super channel', | |
199 | isLocal | |
200 | }, | |
201 | fixture: 'video_short2.webm', | |
202 | files: [ | |
203 | { | |
204 | resolution: 240, | |
205 | size: 190000 | |
206 | }, | |
207 | { | |
208 | resolution: 360, | |
209 | size: 280000 | |
210 | }, | |
211 | { | |
212 | resolution: 480, | |
213 | size: 390000 | |
214 | }, | |
215 | { | |
216 | resolution: 720, | |
217 | size: 710000 | |
218 | } | |
ac81d1a0 C |
219 | ], |
220 | thumbnailfile: 'thumbnail', | |
221 | previewfile: 'preview' | |
b1f5b93e | 222 | } |
0e1dc3e7 C |
223 | |
224 | const res = await getVideosList(server.url) | |
0e1dc3e7 C |
225 | const videos = res.body.data |
226 | expect(videos).to.be.an('array') | |
227 | expect(videos.length).to.equal(2) | |
228 | const video = videos[1] | |
0e1dc3e7 | 229 | |
b1f5b93e | 230 | await completeVideoCheck(server.url, video, checkAttributes) |
0e1dc3e7 C |
231 | } |
232 | }) | |
233 | ||
9a27cdc2 | 234 | it('Should upload two videos on server 3 and propagate on each server', async function () { |
0e1dc3e7 C |
235 | this.timeout(45000) |
236 | ||
237 | const videoAttributes1 = { | |
9a27cdc2 | 238 | name: 'my super name for server 3', |
0e1dc3e7 C |
239 | category: 6, |
240 | licence: 5, | |
241 | language: 11, | |
242 | nsfw: true, | |
9a27cdc2 | 243 | description: 'my super description for server 3', |
2422c46b | 244 | support: 'my super support text for server 3', |
0e1dc3e7 C |
245 | tags: [ 'tag1p3' ], |
246 | fixture: 'video_short3.webm' | |
247 | } | |
248 | await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1) | |
249 | ||
250 | const videoAttributes2 = { | |
9a27cdc2 | 251 | name: 'my super name for server 3-2', |
0e1dc3e7 C |
252 | category: 7, |
253 | licence: 6, | |
254 | language: 12, | |
255 | nsfw: false, | |
9a27cdc2 | 256 | description: 'my super description for server 3-2', |
2422c46b | 257 | support: 'my super support text for server 3-2', |
0e1dc3e7 C |
258 | tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], |
259 | fixture: 'video_short.webm' | |
260 | } | |
261 | await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2) | |
262 | ||
572f8d3d | 263 | await wait(10000) |
0e1dc3e7 | 264 | |
9a27cdc2 | 265 | // All servers should have this video |
0e1dc3e7 | 266 | for (const server of servers) { |
b1f5b93e | 267 | const isLocal = server.url === 'http://localhost:9003' |
0e1dc3e7 C |
268 | const res = await getVideosList(server.url) |
269 | ||
270 | const videos = res.body.data | |
271 | expect(videos).to.be.an('array') | |
272 | expect(videos.length).to.equal(4) | |
273 | ||
274 | // We not sure about the order of the two last uploads | |
275 | let video1 = null | |
276 | let video2 = null | |
9a27cdc2 | 277 | if (videos[2].name === 'my super name for server 3') { |
0e1dc3e7 C |
278 | video1 = videos[2] |
279 | video2 = videos[3] | |
280 | } else { | |
281 | video1 = videos[3] | |
282 | video2 = videos[2] | |
283 | } | |
284 | ||
b1f5b93e C |
285 | const checkAttributesVideo1 = { |
286 | name: 'my super name for server 3', | |
287 | category: 6, | |
288 | licence: 5, | |
289 | language: 11, | |
290 | nsfw: true, | |
291 | description: 'my super description for server 3', | |
2422c46b | 292 | support: 'my super support text for server 3', |
b64c950a C |
293 | account: { |
294 | name: 'root', | |
295 | host: 'localhost:9003' | |
296 | }, | |
b1f5b93e C |
297 | isLocal, |
298 | duration: 5, | |
47564bbe | 299 | commentsEnabled: true, |
b1f5b93e C |
300 | tags: [ 'tag1p3' ], |
301 | privacy: VideoPrivacy.PUBLIC, | |
302 | channel: { | |
303 | name: 'Default root channel', | |
304 | description: '', | |
305 | isLocal | |
306 | }, | |
307 | fixture: 'video_short3.webm', | |
308 | files: [ | |
309 | { | |
310 | resolution: 720, | |
311 | size: 292677 | |
312 | } | |
313 | ] | |
0e1dc3e7 | 314 | } |
b1f5b93e C |
315 | await completeVideoCheck(server.url, video1, checkAttributesVideo1) |
316 | ||
317 | const checkAttributesVideo2 = { | |
318 | name: 'my super name for server 3-2', | |
319 | category: 7, | |
320 | licence: 6, | |
321 | language: 12, | |
322 | nsfw: false, | |
323 | description: 'my super description for server 3-2', | |
2422c46b | 324 | support: 'my super support text for server 3-2', |
b64c950a C |
325 | account: { |
326 | name: 'root', | |
327 | host: 'localhost:9003' | |
328 | }, | |
47564bbe | 329 | commentsEnabled: true, |
b1f5b93e C |
330 | isLocal, |
331 | duration: 5, | |
332 | tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], | |
333 | privacy: VideoPrivacy.PUBLIC, | |
334 | channel: { | |
335 | name: 'Default root channel', | |
336 | description: '', | |
337 | isLocal | |
338 | }, | |
8b0d42ee | 339 | fixture: 'video_short.webm', |
b1f5b93e C |
340 | files: [ |
341 | { | |
342 | resolution: 720, | |
343 | size: 218910 | |
344 | } | |
345 | ] | |
0e1dc3e7 | 346 | } |
b1f5b93e | 347 | await completeVideoCheck(server.url, video2, checkAttributesVideo2) |
0e1dc3e7 C |
348 | } |
349 | }) | |
350 | }) | |
351 | ||
352 | describe('Should seed the uploaded video', function () { | |
9a27cdc2 | 353 | it('Should add the file 1 by asking server 3', async function () { |
572f8d3d | 354 | this.timeout(10000) |
0e1dc3e7 C |
355 | |
356 | const res = await getVideosList(servers[2].url) | |
357 | ||
358 | const video = res.body.data[0] | |
359 | toRemove.push(res.body.data[2]) | |
360 | toRemove.push(res.body.data[3]) | |
361 | ||
5f04dd2f C |
362 | const res2 = await getVideo(servers[2].url, video.id) |
363 | const videoDetails = res2.body | |
364 | ||
b1f5b93e | 365 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) |
0e1dc3e7 C |
366 | expect(torrent.files).to.be.an('array') |
367 | expect(torrent.files.length).to.equal(1) | |
368 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
369 | }) | |
370 | ||
9a27cdc2 | 371 | it('Should add the file 2 by asking server 1', async function () { |
572f8d3d | 372 | this.timeout(10000) |
0e1dc3e7 C |
373 | |
374 | const res = await getVideosList(servers[0].url) | |
375 | ||
376 | const video = res.body.data[1] | |
5f04dd2f C |
377 | const res2 = await getVideo(servers[0].url, video.id) |
378 | const videoDetails = res2.body | |
0e1dc3e7 | 379 | |
b1f5b93e | 380 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) |
0e1dc3e7 C |
381 | expect(torrent.files).to.be.an('array') |
382 | expect(torrent.files.length).to.equal(1) | |
383 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
384 | }) | |
385 | ||
9a27cdc2 | 386 | it('Should add the file 3 by asking server 2', async function () { |
572f8d3d | 387 | this.timeout(10000) |
0e1dc3e7 C |
388 | |
389 | const res = await getVideosList(servers[1].url) | |
390 | ||
391 | const video = res.body.data[2] | |
5f04dd2f C |
392 | const res2 = await getVideo(servers[1].url, video.id) |
393 | const videoDetails = res2.body | |
0e1dc3e7 | 394 | |
b1f5b93e | 395 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) |
0e1dc3e7 C |
396 | expect(torrent.files).to.be.an('array') |
397 | expect(torrent.files.length).to.equal(1) | |
398 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
399 | }) | |
400 | ||
9a27cdc2 | 401 | it('Should add the file 3-2 by asking server 1', async function () { |
572f8d3d | 402 | this.timeout(10000) |
0e1dc3e7 C |
403 | |
404 | const res = await getVideosList(servers[0].url) | |
405 | ||
406 | const video = res.body.data[3] | |
5f04dd2f C |
407 | const res2 = await getVideo(servers[0].url, video.id) |
408 | const videoDetails = res2.body | |
0e1dc3e7 | 409 | |
5f04dd2f | 410 | const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) |
0e1dc3e7 C |
411 | expect(torrent.files).to.be.an('array') |
412 | expect(torrent.files.length).to.equal(1) | |
413 | expect(torrent.files[0].path).to.exist.and.to.not.equal('') | |
414 | }) | |
14d3270f | 415 | |
9a27cdc2 | 416 | it('Should add the file 2 in 360p by asking server 1', async function () { |
572f8d3d | 417 | this.timeout(10000) |
14d3270f C |
418 | |
419 | const res = await getVideosList(servers[0].url) | |
420 | ||
9a27cdc2 | 421 | const video = res.body.data.find(v => v.name === 'my super name for server 2') |
5f04dd2f C |
422 | const res2 = await getVideo(servers[0].url, video.id) |
423 | const videoDetails = res2.body | |
424 | ||
425 | const file = videoDetails.files.find(f => f.resolution === 360) | |
14d3270f C |
426 | expect(file).not.to.be.undefined |
427 | ||
428 | const torrent = await webtorrentAdd(file.magnetUri) | |
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 | }) | |
0e1dc3e7 C |
433 | }) |
434 | ||
435 | describe('Should update video views, likes and dislikes', function () { | |
9a27cdc2 C |
436 | let localVideosServer3 = [] |
437 | let remoteVideosServer1 = [] | |
438 | let remoteVideosServer2 = [] | |
439 | let remoteVideosServer3 = [] | |
0e1dc3e7 C |
440 | |
441 | before(async function () { | |
442 | const res1 = await getVideosList(servers[0].url) | |
9a27cdc2 | 443 | remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid) |
0e1dc3e7 C |
444 | |
445 | const res2 = await getVideosList(servers[1].url) | |
9a27cdc2 | 446 | remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid) |
0e1dc3e7 C |
447 | |
448 | const res3 = await getVideosList(servers[2].url) | |
9a27cdc2 C |
449 | localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid) |
450 | remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid) | |
0e1dc3e7 C |
451 | }) |
452 | ||
453 | it('Should view multiple videos on owned servers', async function () { | |
b5c0e955 | 454 | this.timeout(15000) |
0e1dc3e7 C |
455 | |
456 | const tasks: Promise<any>[] = [] | |
b5c0e955 C |
457 | await viewVideo(servers[2].url, localVideosServer3[0]) |
458 | await viewVideo(servers[2].url, localVideosServer3[0]) | |
459 | await viewVideo(servers[2].url, localVideosServer3[0]) | |
460 | await viewVideo(servers[2].url, localVideosServer3[1]) | |
0e1dc3e7 C |
461 | |
462 | await Promise.all(tasks) | |
b5c0e955 C |
463 | await wait(1500) |
464 | ||
465 | await viewVideo(servers[2].url, localVideosServer3[0]) | |
466 | ||
467 | await wait(1500) | |
468 | ||
469 | await viewVideo(servers[2].url, localVideosServer3[0]) | |
0e1dc3e7 | 470 | |
572f8d3d | 471 | await wait(5000) |
0e1dc3e7 C |
472 | |
473 | for (const server of servers) { | |
474 | const res = await getVideosList(server.url) | |
475 | ||
476 | const videos = res.body.data | |
9a27cdc2 C |
477 | const video0 = videos.find(v => v.uuid === localVideosServer3[0]) |
478 | const video1 = videos.find(v => v.uuid === localVideosServer3[1]) | |
5f04dd2f | 479 | |
1f3e9fec C |
480 | expect(video0.views).to.equal(3) |
481 | expect(video1.views).to.equal(1) | |
0e1dc3e7 C |
482 | } |
483 | }) | |
484 | ||
485 | it('Should view multiple videos on each servers', async function () { | |
572f8d3d | 486 | this.timeout(15000) |
0e1dc3e7 C |
487 | |
488 | const tasks: Promise<any>[] = [] | |
1f3e9fec C |
489 | tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0])) |
490 | tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) | |
491 | tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) | |
492 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[0])) | |
493 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) | |
494 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) | |
495 | tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) | |
496 | tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) | |
497 | tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) | |
498 | tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) | |
0e1dc3e7 C |
499 | |
500 | await Promise.all(tasks) | |
501 | ||
572f8d3d | 502 | await wait(10000) |
0e1dc3e7 C |
503 | |
504 | let baseVideos = null | |
505 | ||
506 | for (const server of servers) { | |
507 | const res = await getVideosList(server.url) | |
508 | ||
509 | const videos = res.body.data | |
510 | ||
511 | // Initialize base videos for future comparisons | |
512 | if (baseVideos === null) { | |
513 | baseVideos = videos | |
35a097b8 | 514 | continue |
0e1dc3e7 C |
515 | } |
516 | ||
517 | for (const baseVideo of baseVideos) { | |
518 | const sameVideo = videos.find(video => video.name === baseVideo.name) | |
519 | expect(baseVideo.views).to.equal(sameVideo.views) | |
520 | } | |
521 | } | |
522 | }) | |
523 | ||
524 | it('Should like and dislikes videos on different services', async function () { | |
572f8d3d | 525 | this.timeout(20000) |
0e1dc3e7 | 526 | |
94a5ff8a C |
527 | await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like') |
528 | await wait(200) | |
529 | await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike') | |
530 | await wait(200) | |
531 | await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like') | |
532 | await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like') | |
533 | await wait(200) | |
534 | await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike') | |
535 | await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike') | |
536 | await wait(200) | |
537 | await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like') | |
0e1dc3e7 | 538 | |
572f8d3d | 539 | await wait(10000) |
0e1dc3e7 C |
540 | |
541 | let baseVideos = null | |
542 | for (const server of servers) { | |
543 | const res = await getVideosList(server.url) | |
544 | ||
545 | const videos = res.body.data | |
546 | ||
547 | // Initialize base videos for future comparisons | |
548 | if (baseVideos === null) { | |
549 | baseVideos = videos | |
35a097b8 | 550 | continue |
0e1dc3e7 C |
551 | } |
552 | ||
35a097b8 | 553 | for (const baseVideo of baseVideos) { |
0e1dc3e7 C |
554 | const sameVideo = videos.find(video => video.name === baseVideo.name) |
555 | expect(baseVideo.likes).to.equal(sameVideo.likes) | |
556 | expect(baseVideo.dislikes).to.equal(sameVideo.dislikes) | |
35a097b8 | 557 | } |
0e1dc3e7 C |
558 | } |
559 | }) | |
560 | }) | |
561 | ||
562 | describe('Should manipulate these videos', function () { | |
9a27cdc2 | 563 | it('Should update the video 3 by asking server 3', async function () { |
572f8d3d | 564 | this.timeout(10000) |
0e1dc3e7 C |
565 | |
566 | const attributes = { | |
567 | name: 'my super video updated', | |
568 | category: 10, | |
569 | licence: 7, | |
570 | language: 13, | |
571 | nsfw: true, | |
572 | description: 'my super description updated', | |
2422c46b | 573 | support: 'my super support text updated', |
ac81d1a0 C |
574 | tags: [ 'tag_up_1', 'tag_up_2' ], |
575 | thumbnailfile: 'thumbnail.jpg', | |
576 | previewfile: 'preview.jpg' | |
0e1dc3e7 C |
577 | } |
578 | ||
579 | await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) | |
580 | ||
572f8d3d | 581 | await wait(5000) |
0e1dc3e7 C |
582 | }) |
583 | ||
9a27cdc2 | 584 | it('Should have the video 3 updated on each server', async function () { |
572f8d3d | 585 | this.timeout(10000) |
0e1dc3e7 C |
586 | |
587 | for (const server of servers) { | |
588 | const res = await getVideosList(server.url) | |
589 | ||
590 | const videos = res.body.data | |
591 | const videoUpdated = videos.find(video => video.name === 'my super video updated') | |
0e1dc3e7 | 592 | expect(!!videoUpdated).to.be.true |
0e1dc3e7 | 593 | |
b1f5b93e C |
594 | const isLocal = server.url === 'http://localhost:9003' |
595 | const checkAttributes = { | |
596 | name: 'my super video updated', | |
597 | category: 10, | |
598 | licence: 7, | |
599 | language: 13, | |
600 | nsfw: true, | |
601 | description: 'my super description updated', | |
2422c46b | 602 | support: 'my super support text updated', |
b64c950a C |
603 | account: { |
604 | name: 'root', | |
605 | host: 'localhost:9003' | |
606 | }, | |
b1f5b93e C |
607 | isLocal, |
608 | duration: 5, | |
47564bbe | 609 | commentsEnabled: true, |
b1f5b93e C |
610 | tags: [ 'tag_up_1', 'tag_up_2' ], |
611 | privacy: VideoPrivacy.PUBLIC, | |
612 | channel: { | |
613 | name: 'Default root channel', | |
614 | description: '', | |
615 | isLocal | |
616 | }, | |
617 | fixture: 'video_short3.webm', | |
618 | files: [ | |
619 | { | |
620 | resolution: 720, | |
621 | size: 292677 | |
622 | } | |
ac81d1a0 C |
623 | ], |
624 | thumbnailfile: 'thumbnail', | |
625 | previewfile: 'preview' | |
b1f5b93e C |
626 | } |
627 | await completeVideoCheck(server.url, videoUpdated, checkAttributes) | |
0e1dc3e7 C |
628 | } |
629 | }) | |
630 | ||
9a27cdc2 | 631 | it('Should remove the videos 3 and 3-2 by asking server 3', async function () { |
572f8d3d | 632 | this.timeout(10000) |
0e1dc3e7 C |
633 | |
634 | await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id) | |
635 | await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id) | |
636 | ||
572f8d3d | 637 | await wait(5000) |
0e1dc3e7 C |
638 | }) |
639 | ||
f05a1c30 C |
640 | it('Should not have files of videos 3 and 3-2 on each server', async function () { |
641 | for (const server of servers) { | |
642 | await checkVideoFilesWereRemoved(toRemove[0].uuid, server.serverNumber) | |
643 | await checkVideoFilesWereRemoved(toRemove[1].uuid, server.serverNumber) | |
644 | } | |
645 | }) | |
646 | ||
9a27cdc2 | 647 | it('Should have videos 1 and 3 on each server', async function () { |
0e1dc3e7 C |
648 | for (const server of servers) { |
649 | const res = await getVideosList(server.url) | |
650 | ||
651 | const videos = res.body.data | |
652 | expect(videos).to.be.an('array') | |
653 | expect(videos.length).to.equal(2) | |
654 | expect(videos[0].name).not.to.equal(videos[1].name) | |
655 | expect(videos[0].name).not.to.equal(toRemove[0].name) | |
656 | expect(videos[1].name).not.to.equal(toRemove[0].name) | |
657 | expect(videos[0].name).not.to.equal(toRemove[1].name) | |
658 | expect(videos[1].name).not.to.equal(toRemove[1].name) | |
659 | ||
9a27cdc2 | 660 | videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid |
0e1dc3e7 C |
661 | } |
662 | }) | |
663 | ||
9a27cdc2 | 664 | it('Should get the same video by UUID on each server', async function () { |
0e1dc3e7 C |
665 | let baseVideo = null |
666 | for (const server of servers) { | |
667 | const res = await getVideo(server.url, videoUUID) | |
668 | ||
669 | const video = res.body | |
670 | ||
671 | if (baseVideo === null) { | |
672 | baseVideo = video | |
35a097b8 | 673 | continue |
0e1dc3e7 C |
674 | } |
675 | ||
676 | expect(baseVideo.name).to.equal(video.name) | |
677 | expect(baseVideo.uuid).to.equal(video.uuid) | |
678 | expect(baseVideo.category).to.equal(video.category) | |
679 | expect(baseVideo.language).to.equal(video.language) | |
680 | expect(baseVideo.licence).to.equal(video.licence) | |
681 | expect(baseVideo.category).to.equal(video.category) | |
682 | expect(baseVideo.nsfw).to.equal(video.nsfw) | |
b64c950a C |
683 | expect(baseVideo.account.name).to.equal(video.account.name) |
684 | expect(baseVideo.account.displayName).to.equal(video.account.displayName) | |
685 | expect(baseVideo.account.url).to.equal(video.account.url) | |
686 | expect(baseVideo.account.host).to.equal(video.account.host) | |
0e1dc3e7 C |
687 | expect(baseVideo.tags).to.deep.equal(video.tags) |
688 | } | |
689 | }) | |
690 | ||
9a27cdc2 | 691 | it('Should get the preview from each server', async function () { |
0e1dc3e7 C |
692 | for (const server of servers) { |
693 | const res = await getVideo(server.url, videoUUID) | |
694 | const video = res.body | |
695 | ||
7b0956ec | 696 | await testImage(server.url, 'video_short1-preview.webm', video.previewPath) |
0e1dc3e7 C |
697 | } |
698 | }) | |
699 | }) | |
700 | ||
d50acfab C |
701 | describe('Should comment these videos', function () { |
702 | it('Should add comment (threads and replies)', async function () { | |
703 | this.timeout(25000) | |
704 | ||
705 | { | |
706 | const text = 'my super first comment' | |
707 | await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID, text) | |
708 | } | |
709 | ||
710 | { | |
711 | const text = 'my super second comment' | |
712 | await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, text) | |
713 | } | |
714 | ||
715 | await wait(5000) | |
716 | ||
717 | { | |
718 | const res = await getVideoCommentThreads(servers[1].url, videoUUID, 0, 5) | |
719 | const threadId = res.body.data.find(c => c.text === 'my super first comment').id | |
720 | ||
721 | const text = 'my super answer to thread 1' | |
722 | await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, videoUUID, threadId, text) | |
723 | } | |
724 | ||
725 | await wait(5000) | |
726 | ||
727 | { | |
728 | const res1 = await getVideoCommentThreads(servers[2].url, videoUUID, 0, 5) | |
729 | const threadId = res1.body.data.find(c => c.text === 'my super first comment').id | |
730 | ||
731 | const res2 = await getVideoThreadComments(servers[2].url, videoUUID, threadId) | |
732 | const childCommentId = res2.body.children[0].comment.id | |
733 | ||
734 | const text3 = 'my second answer to thread 1' | |
735 | await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, threadId, text3) | |
736 | ||
737 | const text2 = 'my super answer to answer of thread 1' | |
738 | await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, childCommentId, text2) | |
739 | } | |
740 | ||
741 | await wait(5000) | |
742 | }) | |
743 | ||
744 | it('Should have these threads', async function () { | |
745 | for (const server of servers) { | |
746 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) | |
747 | ||
748 | expect(res.body.total).to.equal(2) | |
749 | expect(res.body.data).to.be.an('array') | |
750 | expect(res.body.data).to.have.lengthOf(2) | |
751 | ||
752 | { | |
753 | const comment: VideoComment = res.body.data.find(c => c.text === 'my super first comment') | |
754 | expect(comment).to.not.be.undefined | |
755 | expect(comment.inReplyToCommentId).to.be.null | |
756 | expect(comment.account.name).to.equal('root') | |
757 | expect(comment.account.host).to.equal('localhost:9001') | |
758 | expect(comment.totalReplies).to.equal(3) | |
759 | expect(dateIsValid(comment.createdAt as string)).to.be.true | |
760 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | |
761 | } | |
762 | ||
763 | { | |
764 | const comment: VideoComment = res.body.data.find(c => c.text === 'my super second comment') | |
765 | expect(comment).to.not.be.undefined | |
766 | expect(comment.inReplyToCommentId).to.be.null | |
767 | expect(comment.account.name).to.equal('root') | |
768 | expect(comment.account.host).to.equal('localhost:9003') | |
769 | expect(comment.totalReplies).to.equal(0) | |
770 | expect(dateIsValid(comment.createdAt as string)).to.be.true | |
771 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | |
772 | } | |
773 | } | |
774 | }) | |
775 | ||
776 | it('Should have these comments', async function () { | |
777 | for (const server of servers) { | |
778 | const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5) | |
779 | const threadId = res1.body.data.find(c => c.text === 'my super first comment').id | |
780 | ||
781 | const res2 = await getVideoThreadComments(server.url, videoUUID, threadId) | |
782 | ||
783 | const tree: VideoCommentThreadTree = res2.body | |
784 | expect(tree.comment.text).equal('my super first comment') | |
785 | expect(tree.comment.account.name).equal('root') | |
786 | expect(tree.comment.account.host).equal('localhost:9001') | |
787 | expect(tree.children).to.have.lengthOf(2) | |
788 | ||
789 | const firstChild = tree.children[0] | |
790 | expect(firstChild.comment.text).to.equal('my super answer to thread 1') | |
791 | expect(firstChild.comment.account.name).equal('root') | |
792 | expect(firstChild.comment.account.host).equal('localhost:9002') | |
793 | expect(firstChild.children).to.have.lengthOf(1) | |
794 | ||
795 | const childOfFirstChild = firstChild.children[0] | |
796 | expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1') | |
797 | expect(childOfFirstChild.comment.account.name).equal('root') | |
798 | expect(childOfFirstChild.comment.account.host).equal('localhost:9003') | |
799 | expect(childOfFirstChild.children).to.have.lengthOf(0) | |
800 | ||
801 | const secondChild = tree.children[1] | |
802 | expect(secondChild.comment.text).to.equal('my second answer to thread 1') | |
803 | expect(secondChild.comment.account.name).equal('root') | |
804 | expect(secondChild.comment.account.host).equal('localhost:9003') | |
805 | expect(secondChild.children).to.have.lengthOf(0) | |
806 | } | |
807 | }) | |
47564bbe | 808 | |
4cb6d457 C |
809 | it('Should delete the thread comments', async function () { |
810 | this.timeout(10000) | |
811 | ||
812 | const res1 = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5) | |
813 | const threadId = res1.body.data.find(c => c.text === 'my super first comment').id | |
814 | await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) | |
815 | ||
816 | await wait(5000) | |
817 | }) | |
818 | ||
819 | it('Should have the thread comments deleted on other servers too', async function () { | |
820 | for (const server of servers) { | |
821 | const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) | |
822 | ||
823 | expect(res.body.total).to.equal(1) | |
824 | expect(res.body.data).to.be.an('array') | |
825 | expect(res.body.data).to.have.lengthOf(1) | |
826 | ||
827 | { | |
828 | const comment: VideoComment = res.body.data[0] | |
829 | expect(comment).to.not.be.undefined | |
830 | expect(comment.inReplyToCommentId).to.be.null | |
831 | expect(comment.account.name).to.equal('root') | |
832 | expect(comment.account.host).to.equal('localhost:9003') | |
833 | expect(comment.totalReplies).to.equal(0) | |
834 | expect(dateIsValid(comment.createdAt as string)).to.be.true | |
835 | expect(dateIsValid(comment.updatedAt as string)).to.be.true | |
836 | } | |
837 | } | |
838 | }) | |
839 | ||
47564bbe C |
840 | it('Should disable comments', async function () { |
841 | this.timeout(20000) | |
842 | ||
843 | const attributes = { | |
844 | commentsEnabled: false | |
845 | } | |
846 | ||
847 | await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes) | |
848 | ||
849 | await wait(5000) | |
850 | ||
851 | for (const server of servers) { | |
852 | const res = await getVideo(server.url, videoUUID) | |
853 | expect(res.body.commentsEnabled).to.be.false | |
854 | ||
855 | const text = 'my super forbidden comment' | |
856 | await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, 409) | |
857 | } | |
858 | }) | |
d50acfab C |
859 | }) |
860 | ||
f595d394 C |
861 | describe('With minimum parameters', function () { |
862 | it('Should upload and propagate the video', async function () { | |
863 | this.timeout(50000) | |
864 | ||
865 | const path = '/api/v1/videos/upload' | |
866 | ||
867 | const req = request(servers[1].url) | |
868 | .post(path) | |
869 | .set('Accept', 'application/json') | |
870 | .set('Authorization', 'Bearer ' + servers[1].accessToken) | |
871 | .field('name', 'minimum parameters') | |
872 | .field('privacy', '1') | |
873 | .field('nsfw', 'false') | |
874 | .field('channelId', '1') | |
47564bbe | 875 | .field('commentsEnabled', 'true') |
f595d394 | 876 | |
59651eee | 877 | const filePath = join(__dirname, '..', '..', 'api', 'fixtures', 'video_short.webm') |
f595d394 C |
878 | |
879 | await req.attach('videofile', filePath) | |
880 | .expect(200) | |
881 | ||
882 | await wait(25000) | |
883 | ||
884 | for (const server of servers) { | |
885 | const res = await getVideosList(server.url) | |
886 | const video = res.body.data.find(v => v.name === 'minimum parameters') | |
887 | ||
b1f5b93e C |
888 | const isLocal = server.url === 'http://localhost:9002' |
889 | const checkAttributes = { | |
890 | name: 'minimum parameters', | |
891 | category: null, | |
892 | licence: null, | |
893 | language: null, | |
894 | nsfw: false, | |
895 | description: null, | |
2422c46b | 896 | support: null, |
b64c950a C |
897 | account: { |
898 | name: 'root', | |
899 | host: 'localhost:9002' | |
900 | }, | |
b1f5b93e C |
901 | isLocal, |
902 | duration: 5, | |
47564bbe | 903 | commentsEnabled: true, |
b1f5b93e C |
904 | tags: [ ], |
905 | privacy: VideoPrivacy.PUBLIC, | |
906 | channel: { | |
907 | name: 'Default root channel', | |
908 | description: '', | |
909 | isLocal | |
910 | }, | |
911 | fixture: 'video_short.webm', | |
912 | files: [ | |
913 | { | |
914 | resolution: 720, | |
915 | size: 40315 | |
916 | }, | |
917 | { | |
918 | resolution: 480, | |
919 | size: 22808 | |
920 | }, | |
921 | { | |
922 | resolution: 360, | |
923 | size: 18617 | |
924 | }, | |
925 | { | |
926 | resolution: 240, | |
927 | size: 15217 | |
928 | } | |
929 | ] | |
930 | } | |
931 | await completeVideoCheck(server.url, video, checkAttributes) | |
f595d394 C |
932 | } |
933 | }) | |
934 | }) | |
935 | ||
0e1dc3e7 C |
936 | after(async function () { |
937 | killallServers(servers) | |
938 | ||
939 | // Keep the logs if the test failed | |
940 | if (this['ok']) { | |
941 | await flushTests() | |
942 | } | |
943 | }) | |
944 | }) |