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