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