]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/multiple-servers.ts
Add runner server tests
[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 it('Should add the file 1 by asking server 3', async function () {
402 this.timeout(30000)
403
404 const { data } = await servers[2].videos.list()
405
406 const video = data[0]
407 toRemove.push(data[2])
408 toRemove.push(data[3])
409
410 const videoDetails = await servers[2].videos.get({ id: video.id })
411
412 await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
413 })
414
415 it('Should add the file 2 by asking server 1', async function () {
416 this.timeout(30000)
417
418 const { data } = await servers[0].videos.list()
419
420 const video = data[1]
421 const videoDetails = await servers[0].videos.get({ id: video.id })
422
423 await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
424 })
425
426 it('Should add the file 3 by asking server 2', async function () {
427 this.timeout(30000)
428
429 const { data } = await servers[1].videos.list()
430
431 const video = data[2]
432 const videoDetails = await servers[1].videos.get({ id: video.id })
433
434 await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
435 })
436
437 it('Should add the file 3-2 by asking server 1', async function () {
438 this.timeout(30000)
439
440 const { data } = await servers[0].videos.list()
441
442 const video = data[3]
443 const videoDetails = await servers[0].videos.get({ id: video.id })
444
445 await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
446 })
447
448 it('Should add the file 2 in 360p by asking server 1', async function () {
449 this.timeout(30000)
450
451 const { data } = await servers[0].videos.list()
452
453 const video = data.find(v => v.name === 'my super name for server 2')
454 const videoDetails = await servers[0].videos.get({ id: video.id })
455
456 const file = videoDetails.files.find(f => f.resolution.id === 360)
457 expect(file).not.to.be.undefined
458
459 await checkWebTorrentWorks(file.magnetUri)
460 })
461 })
462
463 describe('Should update video views, likes and dislikes', function () {
464 let localVideosServer3 = []
465 let remoteVideosServer1 = []
466 let remoteVideosServer2 = []
467 let remoteVideosServer3 = []
468
469 before(async function () {
470 {
471 const { data } = await servers[0].videos.list()
472 remoteVideosServer1 = data.filter(video => video.isLocal === false).map(video => video.uuid)
473 }
474
475 {
476 const { data } = await servers[1].videos.list()
477 remoteVideosServer2 = data.filter(video => video.isLocal === false).map(video => video.uuid)
478 }
479
480 {
481 const { data } = await servers[2].videos.list()
482 localVideosServer3 = data.filter(video => video.isLocal === true).map(video => video.uuid)
483 remoteVideosServer3 = data.filter(video => video.isLocal === false).map(video => video.uuid)
484 }
485 })
486
487 it('Should view multiple videos on owned servers', async function () {
488 this.timeout(30000)
489
490 await servers[2].views.simulateView({ id: localVideosServer3[0] })
491 await wait(1000)
492
493 await servers[2].views.simulateView({ id: localVideosServer3[0] })
494 await servers[2].views.simulateView({ id: localVideosServer3[1] })
495
496 await wait(1000)
497
498 await servers[2].views.simulateView({ id: localVideosServer3[0] })
499 await servers[2].views.simulateView({ id: localVideosServer3[0] })
500
501 await waitJobs(servers)
502
503 for (const server of servers) {
504 await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } })
505 }
506
507 await waitJobs(servers)
508
509 for (const server of servers) {
510 const { data } = await server.videos.list()
511
512 const video0 = data.find(v => v.uuid === localVideosServer3[0])
513 const video1 = data.find(v => v.uuid === localVideosServer3[1])
514
515 expect(video0.views).to.equal(3)
516 expect(video1.views).to.equal(1)
517 }
518 })
519
520 it('Should view multiple videos on each servers', async function () {
521 this.timeout(45000)
522
523 const tasks: Promise<any>[] = []
524 tasks.push(servers[0].views.simulateView({ id: remoteVideosServer1[0] }))
525 tasks.push(servers[1].views.simulateView({ id: remoteVideosServer2[0] }))
526 tasks.push(servers[1].views.simulateView({ id: remoteVideosServer2[0] }))
527 tasks.push(servers[2].views.simulateView({ id: remoteVideosServer3[0] }))
528 tasks.push(servers[2].views.simulateView({ id: remoteVideosServer3[1] }))
529 tasks.push(servers[2].views.simulateView({ id: remoteVideosServer3[1] }))
530 tasks.push(servers[2].views.simulateView({ id: remoteVideosServer3[1] }))
531 tasks.push(servers[2].views.simulateView({ id: localVideosServer3[1] }))
532 tasks.push(servers[2].views.simulateView({ id: localVideosServer3[1] }))
533 tasks.push(servers[2].views.simulateView({ id: localVideosServer3[1] }))
534
535 await Promise.all(tasks)
536
537 await waitJobs(servers)
538
539 for (const server of servers) {
540 await server.debug.sendCommand({ body: { command: 'process-video-views-buffer' } })
541 }
542
543 await waitJobs(servers)
544
545 let baseVideos = null
546
547 for (const server of servers) {
548 const { data } = await server.videos.list()
549
550 // Initialize base videos for future comparisons
551 if (baseVideos === null) {
552 baseVideos = data
553 continue
554 }
555
556 for (const baseVideo of baseVideos) {
557 const sameVideo = data.find(video => video.name === baseVideo.name)
558 expect(baseVideo.views).to.equal(sameVideo.views)
559 }
560 }
561 })
562
563 it('Should like and dislikes videos on different services', async function () {
564 this.timeout(50000)
565
566 await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'like' })
567 await wait(500)
568 await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'dislike' })
569 await wait(500)
570 await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'like' })
571 await servers[2].videos.rate({ id: localVideosServer3[1], rating: 'like' })
572 await wait(500)
573 await servers[2].videos.rate({ id: localVideosServer3[1], rating: 'dislike' })
574 await servers[2].videos.rate({ id: remoteVideosServer3[1], rating: 'dislike' })
575 await wait(500)
576 await servers[2].videos.rate({ id: remoteVideosServer3[0], rating: 'like' })
577
578 await waitJobs(servers)
579 await wait(5000)
580 await waitJobs(servers)
581
582 let baseVideos = null
583 for (const server of servers) {
584 const { data } = await server.videos.list()
585
586 // Initialize base videos for future comparisons
587 if (baseVideos === null) {
588 baseVideos = data
589 continue
590 }
591
592 for (const baseVideo of baseVideos) {
593 const sameVideo = data.find(video => video.name === baseVideo.name)
594 expect(baseVideo.likes).to.equal(sameVideo.likes, `Likes of ${sameVideo.uuid} do not correspond`)
595 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes, `Dislikes of ${sameVideo.uuid} do not correspond`)
596 }
597 }
598 })
599 })
600
601 describe('Should manipulate these videos', function () {
602 let updatedAtMin: Date
603
604 it('Should update video 3', async function () {
605 this.timeout(30000)
606
607 const attributes = {
608 name: 'my super video updated',
609 category: 10,
610 licence: 7,
611 language: 'fr',
612 nsfw: true,
613 description: 'my super description updated',
614 support: 'my super support text updated',
615 tags: [ 'tag_up_1', 'tag_up_2' ],
616 thumbnailfile: 'thumbnail.jpg',
617 originallyPublishedAt: '2019-02-11T13:38:14.449Z',
618 previewfile: 'preview.jpg'
619 }
620
621 updatedAtMin = new Date()
622 await servers[2].videos.update({ id: toRemove[0].id, attributes })
623
624 await waitJobs(servers)
625 })
626
627 it('Should have the video 3 updated on each server', async function () {
628 this.timeout(30000)
629
630 for (const server of servers) {
631 const { data } = await server.videos.list()
632
633 const videoUpdated = data.find(video => video.name === 'my super video updated')
634 expect(!!videoUpdated).to.be.true
635
636 expect(new Date(videoUpdated.updatedAt)).to.be.greaterThan(updatedAtMin)
637
638 const isLocal = server.url === servers[2].url
639 const checkAttributes = {
640 name: 'my super video updated',
641 category: 10,
642 licence: 7,
643 language: 'fr',
644 nsfw: true,
645 description: 'my super description updated',
646 support: 'my super support text updated',
647 originallyPublishedAt: '2019-02-11T13:38:14.449Z',
648 account: {
649 name: 'root',
650 host: servers[2].host
651 },
652 isLocal,
653 duration: 5,
654 commentsEnabled: true,
655 downloadEnabled: true,
656 tags: [ 'tag_up_1', 'tag_up_2' ],
657 privacy: VideoPrivacy.PUBLIC,
658 channel: {
659 displayName: 'Main root channel',
660 name: 'root_channel',
661 description: '',
662 isLocal
663 },
664 fixture: 'video_short3.webm',
665 files: [
666 {
667 resolution: 720,
668 size: 292677
669 }
670 ],
671 thumbnailfile: 'thumbnail',
672 previewfile: 'preview'
673 }
674 await completeVideoCheck({ server, originServer: servers[2], videoUUID: videoUpdated.uuid, attributes: checkAttributes })
675 }
676 })
677
678 it('Should only update thumbnail and update updatedAt attribute', async function () {
679 this.timeout(30000)
680
681 const attributes = {
682 thumbnailfile: 'thumbnail.jpg'
683 }
684
685 updatedAtMin = new Date()
686 await servers[2].videos.update({ id: toRemove[0].id, attributes })
687
688 await waitJobs(servers)
689
690 for (const server of servers) {
691 const { data } = await server.videos.list()
692
693 const videoUpdated = data.find(video => video.name === 'my super video updated')
694 expect(new Date(videoUpdated.updatedAt)).to.be.greaterThan(updatedAtMin)
695 }
696 })
697
698 it('Should remove the videos 3 and 3-2 by asking server 3 and correctly delete files', async function () {
699 this.timeout(30000)
700
701 for (const id of [ toRemove[0].id, toRemove[1].id ]) {
702 await saveVideoInServers(servers, id)
703
704 await servers[2].videos.remove({ id })
705
706 await waitJobs(servers)
707
708 for (const server of servers) {
709 await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails })
710 }
711 }
712 })
713
714 it('Should have videos 1 and 3 on each server', async function () {
715 for (const server of servers) {
716 const { data } = await server.videos.list()
717
718 expect(data).to.be.an('array')
719 expect(data.length).to.equal(2)
720 expect(data[0].name).not.to.equal(data[1].name)
721 expect(data[0].name).not.to.equal(toRemove[0].name)
722 expect(data[1].name).not.to.equal(toRemove[0].name)
723 expect(data[0].name).not.to.equal(toRemove[1].name)
724 expect(data[1].name).not.to.equal(toRemove[1].name)
725
726 videoUUID = data.find(video => video.name === 'my super name for server 1').uuid
727 }
728 })
729
730 it('Should get the same video by UUID on each server', async function () {
731 let baseVideo = null
732 for (const server of servers) {
733 const video = await server.videos.get({ id: videoUUID })
734
735 if (baseVideo === null) {
736 baseVideo = video
737 continue
738 }
739
740 expect(baseVideo.name).to.equal(video.name)
741 expect(baseVideo.uuid).to.equal(video.uuid)
742 expect(baseVideo.category.id).to.equal(video.category.id)
743 expect(baseVideo.language.id).to.equal(video.language.id)
744 expect(baseVideo.licence.id).to.equal(video.licence.id)
745 expect(baseVideo.nsfw).to.equal(video.nsfw)
746 expect(baseVideo.account.name).to.equal(video.account.name)
747 expect(baseVideo.account.displayName).to.equal(video.account.displayName)
748 expect(baseVideo.account.url).to.equal(video.account.url)
749 expect(baseVideo.account.host).to.equal(video.account.host)
750 expect(baseVideo.tags).to.deep.equal(video.tags)
751 }
752 })
753
754 it('Should get the preview from each server', async function () {
755 for (const server of servers) {
756 const video = await server.videos.get({ id: videoUUID })
757
758 await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
759 }
760 })
761 })
762
763 describe('Should comment these videos', function () {
764 let childOfFirstChild: VideoCommentThreadTree
765
766 it('Should add comment (threads and replies)', async function () {
767 this.timeout(25000)
768
769 {
770 const text = 'my super first comment'
771 await servers[0].comments.createThread({ videoId: videoUUID, text })
772 }
773
774 {
775 const text = 'my super second comment'
776 await servers[2].comments.createThread({ videoId: videoUUID, text })
777 }
778
779 await waitJobs(servers)
780
781 {
782 const threadId = await servers[1].comments.findCommentId({ videoId: videoUUID, text: 'my super first comment' })
783
784 const text = 'my super answer to thread 1'
785 await servers[1].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text })
786 }
787
788 await waitJobs(servers)
789
790 {
791 const threadId = await servers[2].comments.findCommentId({ videoId: videoUUID, text: 'my super first comment' })
792
793 const body = await servers[2].comments.getThread({ videoId: videoUUID, threadId })
794 const childCommentId = body.children[0].comment.id
795
796 const text3 = 'my second answer to thread 1'
797 await servers[2].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: text3 })
798
799 const text2 = 'my super answer to answer of thread 1'
800 await servers[2].comments.addReply({ videoId: videoUUID, toCommentId: childCommentId, text: text2 })
801 }
802
803 await waitJobs(servers)
804 })
805
806 it('Should have these threads', async function () {
807 for (const server of servers) {
808 const body = await server.comments.listThreads({ videoId: videoUUID })
809
810 expect(body.total).to.equal(2)
811 expect(body.data).to.be.an('array')
812 expect(body.data).to.have.lengthOf(2)
813
814 {
815 const comment = body.data.find(c => c.text === 'my super first comment')
816 expect(comment).to.not.be.undefined
817 expect(comment.inReplyToCommentId).to.be.null
818 expect(comment.account.name).to.equal('root')
819 expect(comment.account.host).to.equal(servers[0].host)
820 expect(comment.totalReplies).to.equal(3)
821 expect(dateIsValid(comment.createdAt as string)).to.be.true
822 expect(dateIsValid(comment.updatedAt as string)).to.be.true
823 }
824
825 {
826 const comment = body.data.find(c => c.text === 'my super second comment')
827 expect(comment).to.not.be.undefined
828 expect(comment.inReplyToCommentId).to.be.null
829 expect(comment.account.name).to.equal('root')
830 expect(comment.account.host).to.equal(servers[2].host)
831 expect(comment.totalReplies).to.equal(0)
832 expect(dateIsValid(comment.createdAt as string)).to.be.true
833 expect(dateIsValid(comment.updatedAt as string)).to.be.true
834 }
835 }
836 })
837
838 it('Should have these comments', async function () {
839 for (const server of servers) {
840 const body = await server.comments.listThreads({ videoId: videoUUID })
841 const threadId = body.data.find(c => c.text === 'my super first comment').id
842
843 const tree = await server.comments.getThread({ videoId: videoUUID, threadId })
844
845 expect(tree.comment.text).equal('my super first comment')
846 expect(tree.comment.account.name).equal('root')
847 expect(tree.comment.account.host).equal(servers[0].host)
848 expect(tree.children).to.have.lengthOf(2)
849
850 const firstChild = tree.children[0]
851 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
852 expect(firstChild.comment.account.name).equal('root')
853 expect(firstChild.comment.account.host).equal(servers[1].host)
854 expect(firstChild.children).to.have.lengthOf(1)
855
856 childOfFirstChild = firstChild.children[0]
857 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
858 expect(childOfFirstChild.comment.account.name).equal('root')
859 expect(childOfFirstChild.comment.account.host).equal(servers[2].host)
860 expect(childOfFirstChild.children).to.have.lengthOf(0)
861
862 const secondChild = tree.children[1]
863 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
864 expect(secondChild.comment.account.name).equal('root')
865 expect(secondChild.comment.account.host).equal(servers[2].host)
866 expect(secondChild.children).to.have.lengthOf(0)
867 }
868 })
869
870 it('Should delete a reply', async function () {
871 this.timeout(30000)
872
873 await servers[2].comments.delete({ videoId: videoUUID, commentId: childOfFirstChild.comment.id })
874
875 await waitJobs(servers)
876 })
877
878 it('Should have this comment marked as deleted', async function () {
879 for (const server of servers) {
880 const { data } = await server.comments.listThreads({ videoId: videoUUID })
881 const threadId = data.find(c => c.text === 'my super first comment').id
882
883 const tree = await server.comments.getThread({ videoId: videoUUID, threadId })
884 expect(tree.comment.text).equal('my super first comment')
885
886 const firstChild = tree.children[0]
887 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
888 expect(firstChild.children).to.have.lengthOf(1)
889
890 const deletedComment = firstChild.children[0].comment
891 expect(deletedComment.isDeleted).to.be.true
892 expect(deletedComment.deletedAt).to.not.be.null
893 expect(deletedComment.account).to.be.null
894 expect(deletedComment.text).to.equal('')
895
896 const secondChild = tree.children[1]
897 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
898 }
899 })
900
901 it('Should delete the thread comments', async function () {
902 this.timeout(30000)
903
904 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
905 const commentId = data.find(c => c.text === 'my super first comment').id
906 await servers[0].comments.delete({ videoId: videoUUID, commentId })
907
908 await waitJobs(servers)
909 })
910
911 it('Should have the threads marked as deleted on other servers too', async function () {
912 for (const server of servers) {
913 const body = await server.comments.listThreads({ videoId: videoUUID })
914
915 expect(body.total).to.equal(2)
916 expect(body.data).to.be.an('array')
917 expect(body.data).to.have.lengthOf(2)
918
919 {
920 const comment = body.data[0]
921 expect(comment).to.not.be.undefined
922 expect(comment.inReplyToCommentId).to.be.null
923 expect(comment.account.name).to.equal('root')
924 expect(comment.account.host).to.equal(servers[2].host)
925 expect(comment.totalReplies).to.equal(0)
926 expect(dateIsValid(comment.createdAt as string)).to.be.true
927 expect(dateIsValid(comment.updatedAt as string)).to.be.true
928 }
929
930 {
931 const deletedComment = body.data[1]
932 expect(deletedComment).to.not.be.undefined
933 expect(deletedComment.isDeleted).to.be.true
934 expect(deletedComment.deletedAt).to.not.be.null
935 expect(deletedComment.text).to.equal('')
936 expect(deletedComment.inReplyToCommentId).to.be.null
937 expect(deletedComment.account).to.be.null
938 expect(deletedComment.totalReplies).to.equal(2)
939 expect(dateIsValid(deletedComment.createdAt as string)).to.be.true
940 expect(dateIsValid(deletedComment.updatedAt as string)).to.be.true
941 expect(dateIsValid(deletedComment.deletedAt as string)).to.be.true
942 }
943 }
944 })
945
946 it('Should delete a remote thread by the origin server', async function () {
947 this.timeout(5000)
948
949 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
950 const commentId = data.find(c => c.text === 'my super second comment').id
951 await servers[0].comments.delete({ videoId: videoUUID, commentId })
952
953 await waitJobs(servers)
954 })
955
956 it('Should have the threads marked as deleted on other servers too', async function () {
957 for (const server of servers) {
958 const body = await server.comments.listThreads({ videoId: videoUUID })
959
960 expect(body.total).to.equal(2)
961 expect(body.data).to.have.lengthOf(2)
962
963 {
964 const comment = body.data[0]
965 expect(comment.text).to.equal('')
966 expect(comment.isDeleted).to.be.true
967 expect(comment.createdAt).to.not.be.null
968 expect(comment.deletedAt).to.not.be.null
969 expect(comment.account).to.be.null
970 expect(comment.totalReplies).to.equal(0)
971 }
972
973 {
974 const comment = body.data[1]
975 expect(comment.text).to.equal('')
976 expect(comment.isDeleted).to.be.true
977 expect(comment.createdAt).to.not.be.null
978 expect(comment.deletedAt).to.not.be.null
979 expect(comment.account).to.be.null
980 expect(comment.totalReplies).to.equal(2)
981 }
982 }
983 })
984
985 it('Should disable comments and download', async function () {
986 this.timeout(20000)
987
988 const attributes = {
989 commentsEnabled: false,
990 downloadEnabled: false
991 }
992
993 await servers[0].videos.update({ id: videoUUID, attributes })
994
995 await waitJobs(servers)
996
997 for (const server of servers) {
998 const video = await server.videos.get({ id: videoUUID })
999 expect(video.commentsEnabled).to.be.false
1000 expect(video.downloadEnabled).to.be.false
1001
1002 const text = 'my super forbidden comment'
1003 await server.comments.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 })
1004 }
1005 })
1006 })
1007
1008 describe('With minimum parameters', function () {
1009 it('Should upload and propagate the video', async function () {
1010 this.timeout(120000)
1011
1012 const path = '/api/v1/videos/upload'
1013
1014 const req = request(servers[1].url)
1015 .post(path)
1016 .set('Accept', 'application/json')
1017 .set('Authorization', 'Bearer ' + servers[1].accessToken)
1018 .field('name', 'minimum parameters')
1019 .field('privacy', '1')
1020 .field('channelId', '1')
1021
1022 await req.attach('videofile', buildAbsoluteFixturePath('video_short.webm'))
1023 .expect(HttpStatusCode.OK_200)
1024
1025 await waitJobs(servers)
1026
1027 for (const server of servers) {
1028 const { data } = await server.videos.list()
1029 const video = data.find(v => v.name === 'minimum parameters')
1030
1031 const isLocal = server.url === servers[1].url
1032 const checkAttributes = {
1033 name: 'minimum parameters',
1034 category: null,
1035 licence: null,
1036 language: null,
1037 nsfw: false,
1038 description: null,
1039 support: null,
1040 account: {
1041 name: 'root',
1042 host: servers[1].host
1043 },
1044 isLocal,
1045 duration: 5,
1046 commentsEnabled: true,
1047 downloadEnabled: true,
1048 tags: [],
1049 privacy: VideoPrivacy.PUBLIC,
1050 channel: {
1051 displayName: 'Main root channel',
1052 name: 'root_channel',
1053 description: '',
1054 isLocal
1055 },
1056 fixture: 'video_short.webm',
1057 files: [
1058 {
1059 resolution: 720,
1060 size: 61000
1061 },
1062 {
1063 resolution: 480,
1064 size: 40000
1065 },
1066 {
1067 resolution: 360,
1068 size: 32000
1069 },
1070 {
1071 resolution: 240,
1072 size: 23000
1073 }
1074 ]
1075 }
1076 await completeVideoCheck({ server, originServer: servers[1], videoUUID: video.uuid, attributes: checkAttributes })
1077 }
1078 })
1079 })
1080
1081 describe('TMP directory', function () {
1082 it('Should have an empty tmp directory', async function () {
1083 for (const server of servers) {
1084 await checkTmpIsEmpty(server)
1085 }
1086 })
1087 })
1088
1089 after(async function () {
1090 await cleanupTests(servers)
1091 })
1092 })