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