]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/multiple-servers.ts
Improve remote runner config UX
[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 { expect } from 'chai'
4 import request from 'supertest'
5 import {
6 checkTmpIsEmpty,
7 checkVideoFilesWereRemoved,
8 checkWebTorrentWorks,
9 completeVideoCheck,
10 dateIsValid,
11 saveVideoInServers,
12 testImage
13 } from '@server/tests/shared'
14 import { buildAbsoluteFixturePath, wait } from '@shared/core-utils'
15 import { HttpStatusCode, VideoCommentThreadTree, VideoPrivacy } from '@shared/models'
16 import {
17 cleanupTests,
18 createMultipleServers,
19 doubleFollow,
20 makeGetRequest,
21 PeerTubeServer,
22 setAccessTokensToServers,
23 setDefaultAccountAvatar,
24 setDefaultChannelAvatar,
25 waitJobs
26 } from '@shared/server-commands'
27
28 describe('Test multiple servers', function () {
29 let servers: PeerTubeServer[] = []
30 const toRemove = []
31 let videoUUID = ''
32 let videoChannelId: number
33
34 before(async function () {
35 this.timeout(120000)
36
37 servers = await createMultipleServers(3)
38
39 // Get the access tokens
40 await setAccessTokensToServers(servers)
41
42 {
43 const videoChannel = {
44 name: 'super_channel_name',
45 displayName: 'my channel',
46 description: 'super channel'
47 }
48 await servers[0].channels.create({ attributes: videoChannel })
49 await setDefaultChannelAvatar(servers[0], videoChannel.name)
50 await setDefaultAccountAvatar(servers)
51
52 const { data } = await servers[0].channels.list({ start: 0, count: 1 })
53 videoChannelId = data[0].id
54 }
55
56 // Server 1 and server 2 follow each other
57 await doubleFollow(servers[0], servers[1])
58 // Server 1 and server 3 follow each other
59 await doubleFollow(servers[0], servers[2])
60 // Server 2 and server 3 follow each other
61 await doubleFollow(servers[1], servers[2])
62 })
63
64 it('Should not have videos for all servers', async function () {
65 for (const server of servers) {
66 const { data } = await server.videos.list()
67 expect(data).to.be.an('array')
68 expect(data.length).to.equal(0)
69 }
70 })
71
72 describe('Should upload the video and propagate on each server', function () {
73 it('Should upload the video on server 1 and propagate on each server', async function () {
74 this.timeout(25000)
75
76 const attributes = {
77 name: 'my super name for server 1',
78 category: 5,
79 licence: 4,
80 language: 'ja',
81 nsfw: true,
82 description: 'my super description for server 1',
83 support: 'my super support text for server 1',
84 originallyPublishedAt: '2019-02-10T13:38:14.449Z',
85 tags: [ 'tag1p1', 'tag2p1' ],
86 channelId: videoChannelId,
87 fixture: 'video_short1.webm'
88 }
89 await servers[0].videos.upload({ attributes })
90
91 await waitJobs(servers)
92
93 // All servers should have this video
94 let publishedAt: string = null
95 for (const server of servers) {
96 const isLocal = server.port === servers[0].port
97 const checkAttributes = {
98 name: 'my super name for server 1',
99 category: 5,
100 licence: 4,
101 language: 'ja',
102 nsfw: true,
103 description: 'my super description for server 1',
104 support: 'my super support text for server 1',
105 originallyPublishedAt: '2019-02-10T13:38:14.449Z',
106 account: {
107 name: 'root',
108 host: servers[0].host
109 },
110 isLocal,
111 publishedAt,
112 duration: 10,
113 tags: [ 'tag1p1', 'tag2p1' ],
114 privacy: VideoPrivacy.PUBLIC,
115 commentsEnabled: true,
116 downloadEnabled: true,
117 channel: {
118 displayName: 'my channel',
119 name: 'super_channel_name',
120 description: 'super channel',
121 isLocal
122 },
123 fixture: 'video_short1.webm',
124 files: [
125 {
126 resolution: 720,
127 size: 572456
128 }
129 ]
130 }
131
132 const { data } = await server.videos.list()
133 expect(data).to.be.an('array')
134 expect(data.length).to.equal(1)
135 const video = data[0]
136
137 await completeVideoCheck({ server, originServer: servers[0], videoUUID: video.uuid, attributes: checkAttributes })
138 publishedAt = video.publishedAt as string
139
140 expect(video.channel.avatars).to.have.lengthOf(2)
141 expect(video.account.avatars).to.have.lengthOf(2)
142
143 for (const image of [ ...video.channel.avatars, ...video.account.avatars ]) {
144 expect(image.createdAt).to.exist
145 expect(image.updatedAt).to.exist
146 expect(image.width).to.be.above(20).and.below(1000)
147 expect(image.path).to.exist
148
149 await makeGetRequest({
150 url: server.url,
151 path: image.path,
152 expectedStatus: HttpStatusCode.OK_200
153 })
154 }
155 }
156 })
157
158 it('Should upload the video on server 2 and propagate on each server', async function () {
159 this.timeout(240000)
160
161 const user = {
162 username: 'user1',
163 password: 'super_password'
164 }
165 await servers[1].users.create({ username: user.username, password: user.password })
166 const userAccessToken = await servers[1].login.getAccessToken(user)
167
168 const attributes = {
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 servers[1].videos.upload({ token: userAccessToken, attributes, mode: '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 === servers[1].url
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: servers[1].host
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: 750000
230 }
231 ],
232 thumbnailfile: 'thumbnail',
233 previewfile: 'preview'
234 }
235
236 const { data } = await server.videos.list()
237 expect(data).to.be.an('array')
238 expect(data.length).to.equal(2)
239 const video = data[1]
240
241 await completeVideoCheck({ server, originServer: servers[1], videoUUID: video.uuid, attributes: checkAttributes })
242 }
243 })
244
245 it('Should upload two videos on server 3 and propagate on each server', async function () {
246 this.timeout(45000)
247
248 {
249 const attributes = {
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 servers[2].videos.upload({ attributes })
261 }
262
263 {
264 const attributes = {
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 servers[2].videos.upload({ attributes })
276 }
277
278 await waitJobs(servers)
279
280 // All servers should have this video
281 for (const server of servers) {
282 const isLocal = server.url === servers[2].url
283 const { data } = await server.videos.list()
284
285 expect(data).to.be.an('array')
286 expect(data.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 (data[2].name === 'my super name for server 3') {
292 video1 = data[2]
293 video2 = data[3]
294 } else {
295 video1 = data[3]
296 video2 = data[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: servers[2].host
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, originServer: servers[2], videoUUID: video1.uuid, attributes: 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: servers[2].host
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, originServer: servers[2], videoUUID: video2.uuid, attributes: 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 { data, total } = await servers[0].videos.list({ isLocal: true })
373
374 expect(total).to.equal(1)
375 expect(data).to.be.an('array')
376 expect(data.length).to.equal(1)
377 expect(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 { data, total } = await servers[1].videos.list({ isLocal: true })
382
383 expect(total).to.equal(1)
384 expect(data).to.be.an('array')
385 expect(data.length).to.equal(1)
386 expect(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 { data, total } = await servers[2].videos.list({ isLocal: true })
391
392 expect(total).to.equal(2)
393 expect(data).to.be.an('array')
394 expect(data.length).to.equal(2)
395 expect(data[0].name).to.equal('my super name for server 3')
396 expect(data[1].name).to.equal('my super name for server 3-2')
397 })
398 })
399
400 describe('Should seed the uploaded video', function () {
401
402 it('Should add the file 1 by asking server 3', async function () {
403 this.retries(2)
404 this.timeout(30000)
405
406 const { data } = await servers[2].videos.list()
407
408 const video = data[0]
409 toRemove.push(data[2])
410 toRemove.push(data[3])
411
412 const videoDetails = await servers[2].videos.get({ id: video.id })
413
414 await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
415 })
416
417 it('Should add the file 2 by asking server 1', async function () {
418 this.retries(2)
419 this.timeout(30000)
420
421 const { data } = await servers[0].videos.list()
422
423 const video = data[1]
424 const videoDetails = await servers[0].videos.get({ id: video.id })
425
426 await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
427 })
428
429 it('Should add the file 3 by asking server 2', async function () {
430 this.retries(2)
431 this.timeout(30000)
432
433 const { data } = await servers[1].videos.list()
434
435 const video = data[2]
436 const videoDetails = await servers[1].videos.get({ id: video.id })
437
438 await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
439 })
440
441 it('Should add the file 3-2 by asking server 1', async function () {
442 this.retries(2)
443 this.timeout(30000)
444
445 const { data } = await servers[0].videos.list()
446
447 const video = data[3]
448 const videoDetails = await servers[0].videos.get({ id: video.id })
449
450 await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
451 })
452
453 it('Should add the file 2 in 360p by asking server 1', async function () {
454 this.retries(2)
455 this.timeout(30000)
456
457 const { data } = await servers[0].videos.list()
458
459 const video = data.find(v => v.name === 'my super name for server 2')
460 const videoDetails = await servers[0].videos.get({ id: video.id })
461
462 const file = videoDetails.files.find(f => f.resolution.id === 360)
463 expect(file).not.to.be.undefined
464
465 await checkWebTorrentWorks(file.magnetUri)
466 })
467 })
468
469 describe('Should update video views, likes and dislikes', function () {
470 let localVideosServer3 = []
471 let remoteVideosServer1 = []
472 let remoteVideosServer2 = []
473 let remoteVideosServer3 = []
474
475 before(async function () {
476 {
477 const { data } = await servers[0].videos.list()
478 remoteVideosServer1 = data.filter(video => video.isLocal === false).map(video => video.uuid)
479 }
480
481 {
482 const { data } = await servers[1].videos.list()
483 remoteVideosServer2 = data.filter(video => video.isLocal === false).map(video => video.uuid)
484 }
485
486 {
487 const { data } = await servers[2].videos.list()
488 localVideosServer3 = data.filter(video => video.isLocal === true).map(video => video.uuid)
489 remoteVideosServer3 = data.filter(video => video.isLocal === false).map(video => video.uuid)
490 }
491 })
492
493 it('Should view multiple videos on owned servers', async function () {
494 this.timeout(30000)
495
496 await servers[2].views.simulateView({ id: localVideosServer3[0] })
497 await wait(1000)
498
499 await servers[2].views.simulateView({ id: localVideosServer3[0] })
500 await servers[2].views.simulateView({ id: localVideosServer3[1] })
501
502 await wait(1000)
503
504 await servers[2].views.simulateView({ id: localVideosServer3[0] })
505 await servers[2].views.simulateView({ id: localVideosServer3[0] })
506
507 await waitJobs(servers)
508
509 for (const server of servers) {
510 await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } })
511 }
512
513 await waitJobs(servers)
514
515 for (const server of servers) {
516 const { data } = await server.videos.list()
517
518 const video0 = data.find(v => v.uuid === localVideosServer3[0])
519 const video1 = data.find(v => v.uuid === localVideosServer3[1])
520
521 expect(video0.views).to.equal(3)
522 expect(video1.views).to.equal(1)
523 }
524 })
525
526 it('Should view multiple videos on each servers', async function () {
527 this.timeout(45000)
528
529 const tasks: Promise<any>[] = []
530 tasks.push(servers[0].views.simulateView({ id: remoteVideosServer1[0] }))
531 tasks.push(servers[1].views.simulateView({ id: remoteVideosServer2[0] }))
532 tasks.push(servers[1].views.simulateView({ id: remoteVideosServer2[0] }))
533 tasks.push(servers[2].views.simulateView({ id: remoteVideosServer3[0] }))
534 tasks.push(servers[2].views.simulateView({ id: remoteVideosServer3[1] }))
535 tasks.push(servers[2].views.simulateView({ id: remoteVideosServer3[1] }))
536 tasks.push(servers[2].views.simulateView({ id: remoteVideosServer3[1] }))
537 tasks.push(servers[2].views.simulateView({ id: localVideosServer3[1] }))
538 tasks.push(servers[2].views.simulateView({ id: localVideosServer3[1] }))
539 tasks.push(servers[2].views.simulateView({ id: localVideosServer3[1] }))
540
541 await Promise.all(tasks)
542
543 await waitJobs(servers)
544
545 for (const server of servers) {
546 await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } })
547 }
548
549 await waitJobs(servers)
550
551 let baseVideos = null
552
553 for (const server of servers) {
554 const { data } = await server.videos.list()
555
556 // Initialize base videos for future comparisons
557 if (baseVideos === null) {
558 baseVideos = data
559 continue
560 }
561
562 for (const baseVideo of baseVideos) {
563 const sameVideo = data.find(video => video.name === baseVideo.name)
564 expect(baseVideo.views).to.equal(sameVideo.views)
565 }
566 }
567 })
568
569 it('Should like and dislikes videos on different services', async function () {
570 this.timeout(50000)
571
572 await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'like' })
573 await wait(500)
574 await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'dislike' })
575 await wait(500)
576 await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'like' })
577 await servers[2].videos.rate({ id: localVideosServer3[1], rating: 'like' })
578 await wait(500)
579 await servers[2].videos.rate({ id: localVideosServer3[1], rating: 'dislike' })
580 await servers[2].videos.rate({ id: remoteVideosServer3[1], rating: 'dislike' })
581 await wait(500)
582 await servers[2].videos.rate({ id: remoteVideosServer3[0], rating: 'like' })
583
584 await waitJobs(servers)
585 await wait(5000)
586 await waitJobs(servers)
587
588 let baseVideos = null
589 for (const server of servers) {
590 const { data } = await server.videos.list()
591
592 // Initialize base videos for future comparisons
593 if (baseVideos === null) {
594 baseVideos = data
595 continue
596 }
597
598 for (const baseVideo of baseVideos) {
599 const sameVideo = data.find(video => video.name === baseVideo.name)
600 expect(baseVideo.likes).to.equal(sameVideo.likes, `Likes of ${sameVideo.uuid} do not correspond`)
601 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes, `Dislikes of ${sameVideo.uuid} do not correspond`)
602 }
603 }
604 })
605 })
606
607 describe('Should manipulate these videos', function () {
608 let updatedAtMin: Date
609
610 it('Should update video 3', async function () {
611 this.timeout(30000)
612
613 const attributes = {
614 name: 'my super video updated',
615 category: 10,
616 licence: 7,
617 language: 'fr',
618 nsfw: true,
619 description: 'my super description updated',
620 support: 'my super support text updated',
621 tags: [ 'tag_up_1', 'tag_up_2' ],
622 thumbnailfile: 'thumbnail.jpg',
623 originallyPublishedAt: '2019-02-11T13:38:14.449Z',
624 previewfile: 'preview.jpg'
625 }
626
627 updatedAtMin = new Date()
628 await servers[2].videos.update({ id: toRemove[0].id, attributes })
629
630 await waitJobs(servers)
631 })
632
633 it('Should have the video 3 updated on each server', async function () {
634 this.timeout(30000)
635
636 for (const server of servers) {
637 const { data } = await server.videos.list()
638
639 const videoUpdated = data.find(video => video.name === 'my super video updated')
640 expect(!!videoUpdated).to.be.true
641
642 expect(new Date(videoUpdated.updatedAt)).to.be.greaterThan(updatedAtMin)
643
644 const isLocal = server.url === servers[2].url
645 const checkAttributes = {
646 name: 'my super video updated',
647 category: 10,
648 licence: 7,
649 language: 'fr',
650 nsfw: true,
651 description: 'my super description updated',
652 support: 'my super support text updated',
653 originallyPublishedAt: '2019-02-11T13:38:14.449Z',
654 account: {
655 name: 'root',
656 host: servers[2].host
657 },
658 isLocal,
659 duration: 5,
660 commentsEnabled: true,
661 downloadEnabled: true,
662 tags: [ 'tag_up_1', 'tag_up_2' ],
663 privacy: VideoPrivacy.PUBLIC,
664 channel: {
665 displayName: 'Main root channel',
666 name: 'root_channel',
667 description: '',
668 isLocal
669 },
670 fixture: 'video_short3.webm',
671 files: [
672 {
673 resolution: 720,
674 size: 292677
675 }
676 ],
677 thumbnailfile: 'thumbnail',
678 previewfile: 'preview'
679 }
680 await completeVideoCheck({ server, originServer: servers[2], videoUUID: videoUpdated.uuid, attributes: checkAttributes })
681 }
682 })
683
684 it('Should only update thumbnail and update updatedAt attribute', async function () {
685 this.timeout(30000)
686
687 const attributes = {
688 thumbnailfile: 'thumbnail.jpg'
689 }
690
691 updatedAtMin = new Date()
692 await servers[2].videos.update({ id: toRemove[0].id, attributes })
693
694 await waitJobs(servers)
695
696 for (const server of servers) {
697 const { data } = await server.videos.list()
698
699 const videoUpdated = data.find(video => video.name === 'my super video updated')
700 expect(new Date(videoUpdated.updatedAt)).to.be.greaterThan(updatedAtMin)
701 }
702 })
703
704 it('Should remove the videos 3 and 3-2 by asking server 3 and correctly delete files', async function () {
705 this.timeout(30000)
706
707 for (const id of [ toRemove[0].id, toRemove[1].id ]) {
708 await saveVideoInServers(servers, id)
709
710 await servers[2].videos.remove({ id })
711
712 await waitJobs(servers)
713
714 for (const server of servers) {
715 await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails })
716 }
717 }
718 })
719
720 it('Should have videos 1 and 3 on each server', async function () {
721 for (const server of servers) {
722 const { data } = await server.videos.list()
723
724 expect(data).to.be.an('array')
725 expect(data.length).to.equal(2)
726 expect(data[0].name).not.to.equal(data[1].name)
727 expect(data[0].name).not.to.equal(toRemove[0].name)
728 expect(data[1].name).not.to.equal(toRemove[0].name)
729 expect(data[0].name).not.to.equal(toRemove[1].name)
730 expect(data[1].name).not.to.equal(toRemove[1].name)
731
732 videoUUID = data.find(video => video.name === 'my super name for server 1').uuid
733 }
734 })
735
736 it('Should get the same video by UUID on each server', async function () {
737 let baseVideo = null
738 for (const server of servers) {
739 const video = await server.videos.get({ id: videoUUID })
740
741 if (baseVideo === null) {
742 baseVideo = video
743 continue
744 }
745
746 expect(baseVideo.name).to.equal(video.name)
747 expect(baseVideo.uuid).to.equal(video.uuid)
748 expect(baseVideo.category.id).to.equal(video.category.id)
749 expect(baseVideo.language.id).to.equal(video.language.id)
750 expect(baseVideo.licence.id).to.equal(video.licence.id)
751 expect(baseVideo.nsfw).to.equal(video.nsfw)
752 expect(baseVideo.account.name).to.equal(video.account.name)
753 expect(baseVideo.account.displayName).to.equal(video.account.displayName)
754 expect(baseVideo.account.url).to.equal(video.account.url)
755 expect(baseVideo.account.host).to.equal(video.account.host)
756 expect(baseVideo.tags).to.deep.equal(video.tags)
757 }
758 })
759
760 it('Should get the preview from each server', async function () {
761 for (const server of servers) {
762 const video = await server.videos.get({ id: videoUUID })
763
764 await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
765 }
766 })
767 })
768
769 describe('Should comment these videos', function () {
770 let childOfFirstChild: VideoCommentThreadTree
771
772 it('Should add comment (threads and replies)', async function () {
773 this.timeout(25000)
774
775 {
776 const text = 'my super first comment'
777 await servers[0].comments.createThread({ videoId: videoUUID, text })
778 }
779
780 {
781 const text = 'my super second comment'
782 await servers[2].comments.createThread({ videoId: videoUUID, text })
783 }
784
785 await waitJobs(servers)
786
787 {
788 const threadId = await servers[1].comments.findCommentId({ videoId: videoUUID, text: 'my super first comment' })
789
790 const text = 'my super answer to thread 1'
791 await servers[1].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text })
792 }
793
794 await waitJobs(servers)
795
796 {
797 const threadId = await servers[2].comments.findCommentId({ videoId: videoUUID, text: 'my super first comment' })
798
799 const body = await servers[2].comments.getThread({ videoId: videoUUID, threadId })
800 const childCommentId = body.children[0].comment.id
801
802 const text3 = 'my second answer to thread 1'
803 await servers[2].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: text3 })
804
805 const text2 = 'my super answer to answer of thread 1'
806 await servers[2].comments.addReply({ videoId: videoUUID, toCommentId: childCommentId, text: text2 })
807 }
808
809 await waitJobs(servers)
810 })
811
812 it('Should have these threads', async function () {
813 for (const server of servers) {
814 const body = await server.comments.listThreads({ videoId: videoUUID })
815
816 expect(body.total).to.equal(2)
817 expect(body.data).to.be.an('array')
818 expect(body.data).to.have.lengthOf(2)
819
820 {
821 const comment = body.data.find(c => c.text === 'my super first comment')
822 expect(comment).to.not.be.undefined
823 expect(comment.inReplyToCommentId).to.be.null
824 expect(comment.account.name).to.equal('root')
825 expect(comment.account.host).to.equal(servers[0].host)
826 expect(comment.totalReplies).to.equal(3)
827 expect(dateIsValid(comment.createdAt as string)).to.be.true
828 expect(dateIsValid(comment.updatedAt as string)).to.be.true
829 }
830
831 {
832 const comment = body.data.find(c => c.text === 'my super second comment')
833 expect(comment).to.not.be.undefined
834 expect(comment.inReplyToCommentId).to.be.null
835 expect(comment.account.name).to.equal('root')
836 expect(comment.account.host).to.equal(servers[2].host)
837 expect(comment.totalReplies).to.equal(0)
838 expect(dateIsValid(comment.createdAt as string)).to.be.true
839 expect(dateIsValid(comment.updatedAt as string)).to.be.true
840 }
841 }
842 })
843
844 it('Should have these comments', async function () {
845 for (const server of servers) {
846 const body = await server.comments.listThreads({ videoId: videoUUID })
847 const threadId = body.data.find(c => c.text === 'my super first comment').id
848
849 const tree = await server.comments.getThread({ videoId: videoUUID, threadId })
850
851 expect(tree.comment.text).equal('my super first comment')
852 expect(tree.comment.account.name).equal('root')
853 expect(tree.comment.account.host).equal(servers[0].host)
854 expect(tree.children).to.have.lengthOf(2)
855
856 const firstChild = tree.children[0]
857 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
858 expect(firstChild.comment.account.name).equal('root')
859 expect(firstChild.comment.account.host).equal(servers[1].host)
860 expect(firstChild.children).to.have.lengthOf(1)
861
862 childOfFirstChild = firstChild.children[0]
863 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
864 expect(childOfFirstChild.comment.account.name).equal('root')
865 expect(childOfFirstChild.comment.account.host).equal(servers[2].host)
866 expect(childOfFirstChild.children).to.have.lengthOf(0)
867
868 const secondChild = tree.children[1]
869 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
870 expect(secondChild.comment.account.name).equal('root')
871 expect(secondChild.comment.account.host).equal(servers[2].host)
872 expect(secondChild.children).to.have.lengthOf(0)
873 }
874 })
875
876 it('Should delete a reply', async function () {
877 this.timeout(30000)
878
879 await servers[2].comments.delete({ videoId: videoUUID, commentId: childOfFirstChild.comment.id })
880
881 await waitJobs(servers)
882 })
883
884 it('Should have this comment marked as deleted', async function () {
885 for (const server of servers) {
886 const { data } = await server.comments.listThreads({ videoId: videoUUID })
887 const threadId = data.find(c => c.text === 'my super first comment').id
888
889 const tree = await server.comments.getThread({ videoId: videoUUID, threadId })
890 expect(tree.comment.text).equal('my super first comment')
891
892 const firstChild = tree.children[0]
893 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
894 expect(firstChild.children).to.have.lengthOf(1)
895
896 const deletedComment = firstChild.children[0].comment
897 expect(deletedComment.isDeleted).to.be.true
898 expect(deletedComment.deletedAt).to.not.be.null
899 expect(deletedComment.account).to.be.null
900 expect(deletedComment.text).to.equal('')
901
902 const secondChild = tree.children[1]
903 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
904 }
905 })
906
907 it('Should delete the thread comments', async function () {
908 this.timeout(30000)
909
910 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
911 const commentId = data.find(c => c.text === 'my super first comment').id
912 await servers[0].comments.delete({ videoId: videoUUID, commentId })
913
914 await waitJobs(servers)
915 })
916
917 it('Should have the threads marked as deleted on other servers too', async function () {
918 for (const server of servers) {
919 const body = await server.comments.listThreads({ videoId: videoUUID })
920
921 expect(body.total).to.equal(2)
922 expect(body.data).to.be.an('array')
923 expect(body.data).to.have.lengthOf(2)
924
925 {
926 const comment = body.data[0]
927 expect(comment).to.not.be.undefined
928 expect(comment.inReplyToCommentId).to.be.null
929 expect(comment.account.name).to.equal('root')
930 expect(comment.account.host).to.equal(servers[2].host)
931 expect(comment.totalReplies).to.equal(0)
932 expect(dateIsValid(comment.createdAt as string)).to.be.true
933 expect(dateIsValid(comment.updatedAt as string)).to.be.true
934 }
935
936 {
937 const deletedComment = body.data[1]
938 expect(deletedComment).to.not.be.undefined
939 expect(deletedComment.isDeleted).to.be.true
940 expect(deletedComment.deletedAt).to.not.be.null
941 expect(deletedComment.text).to.equal('')
942 expect(deletedComment.inReplyToCommentId).to.be.null
943 expect(deletedComment.account).to.be.null
944 expect(deletedComment.totalReplies).to.equal(2)
945 expect(dateIsValid(deletedComment.createdAt as string)).to.be.true
946 expect(dateIsValid(deletedComment.updatedAt as string)).to.be.true
947 expect(dateIsValid(deletedComment.deletedAt as string)).to.be.true
948 }
949 }
950 })
951
952 it('Should delete a remote thread by the origin server', async function () {
953 this.timeout(5000)
954
955 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
956 const commentId = data.find(c => c.text === 'my super second comment').id
957 await servers[0].comments.delete({ videoId: videoUUID, commentId })
958
959 await waitJobs(servers)
960 })
961
962 it('Should have the threads marked as deleted on other servers too', async function () {
963 for (const server of servers) {
964 const body = await server.comments.listThreads({ videoId: videoUUID })
965
966 expect(body.total).to.equal(2)
967 expect(body.data).to.have.lengthOf(2)
968
969 {
970 const comment = body.data[0]
971 expect(comment.text).to.equal('')
972 expect(comment.isDeleted).to.be.true
973 expect(comment.createdAt).to.not.be.null
974 expect(comment.deletedAt).to.not.be.null
975 expect(comment.account).to.be.null
976 expect(comment.totalReplies).to.equal(0)
977 }
978
979 {
980 const comment = body.data[1]
981 expect(comment.text).to.equal('')
982 expect(comment.isDeleted).to.be.true
983 expect(comment.createdAt).to.not.be.null
984 expect(comment.deletedAt).to.not.be.null
985 expect(comment.account).to.be.null
986 expect(comment.totalReplies).to.equal(2)
987 }
988 }
989 })
990
991 it('Should disable comments and download', async function () {
992 this.timeout(20000)
993
994 const attributes = {
995 commentsEnabled: false,
996 downloadEnabled: false
997 }
998
999 await servers[0].videos.update({ id: videoUUID, attributes })
1000
1001 await waitJobs(servers)
1002
1003 for (const server of servers) {
1004 const video = await server.videos.get({ id: videoUUID })
1005 expect(video.commentsEnabled).to.be.false
1006 expect(video.downloadEnabled).to.be.false
1007
1008 const text = 'my super forbidden comment'
1009 await server.comments.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 })
1010 }
1011 })
1012 })
1013
1014 describe('With minimum parameters', function () {
1015 it('Should upload and propagate the video', async function () {
1016 this.timeout(120000)
1017
1018 const path = '/api/v1/videos/upload'
1019
1020 const req = request(servers[1].url)
1021 .post(path)
1022 .set('Accept', 'application/json')
1023 .set('Authorization', 'Bearer ' + servers[1].accessToken)
1024 .field('name', 'minimum parameters')
1025 .field('privacy', '1')
1026 .field('channelId', '1')
1027
1028 await req.attach('videofile', buildAbsoluteFixturePath('video_short.webm'))
1029 .expect(HttpStatusCode.OK_200)
1030
1031 await waitJobs(servers)
1032
1033 for (const server of servers) {
1034 const { data } = await server.videos.list()
1035 const video = data.find(v => v.name === 'minimum parameters')
1036
1037 const isLocal = server.url === servers[1].url
1038 const checkAttributes = {
1039 name: 'minimum parameters',
1040 category: null,
1041 licence: null,
1042 language: null,
1043 nsfw: false,
1044 description: null,
1045 support: null,
1046 account: {
1047 name: 'root',
1048 host: servers[1].host
1049 },
1050 isLocal,
1051 duration: 5,
1052 commentsEnabled: true,
1053 downloadEnabled: true,
1054 tags: [],
1055 privacy: VideoPrivacy.PUBLIC,
1056 channel: {
1057 displayName: 'Main root channel',
1058 name: 'root_channel',
1059 description: '',
1060 isLocal
1061 },
1062 fixture: 'video_short.webm',
1063 files: [
1064 {
1065 resolution: 720,
1066 size: 61000
1067 },
1068 {
1069 resolution: 480,
1070 size: 40000
1071 },
1072 {
1073 resolution: 360,
1074 size: 32000
1075 },
1076 {
1077 resolution: 240,
1078 size: 23000
1079 }
1080 ]
1081 }
1082 await completeVideoCheck({ server, originServer: servers[1], videoUUID: video.uuid, attributes: checkAttributes })
1083 }
1084 })
1085 })
1086
1087 describe('TMP directory', function () {
1088 it('Should have an empty tmp directory', async function () {
1089 for (const server of servers) {
1090 await checkTmpIsEmpty(server)
1091 }
1092 })
1093 })
1094
1095 after(async function () {
1096 await cleanupTests(servers)
1097 })
1098 })