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