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