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