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