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