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