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