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