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