]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/multiple-servers.ts
3f6b82c50fd8f7c5c2365ebd5fd0f39febe1988c
[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,
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('Should seed the uploaded video', function () {
353 it('Should add the file 1 by asking server 3', async function () {
354 this.timeout(10000)
355
356 const res = await getVideosList(servers[2].url)
357
358 const video = res.body.data[0]
359 toRemove.push(res.body.data[2])
360 toRemove.push(res.body.data[3])
361
362 const res2 = await getVideo(servers[2].url, video.id)
363 const videoDetails = res2.body
364
365 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
366 expect(torrent.files).to.be.an('array')
367 expect(torrent.files.length).to.equal(1)
368 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
369 })
370
371 it('Should add the file 2 by asking server 1', async function () {
372 this.timeout(10000)
373
374 const res = await getVideosList(servers[0].url)
375
376 const video = res.body.data[1]
377 const res2 = await getVideo(servers[0].url, video.id)
378 const videoDetails = res2.body
379
380 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
381 expect(torrent.files).to.be.an('array')
382 expect(torrent.files.length).to.equal(1)
383 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
384 })
385
386 it('Should add the file 3 by asking server 2', async function () {
387 this.timeout(10000)
388
389 const res = await getVideosList(servers[1].url)
390
391 const video = res.body.data[2]
392 const res2 = await getVideo(servers[1].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 3-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[3]
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)
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 2 in 360p by asking server 1', async function () {
417 this.timeout(10000)
418
419 const res = await getVideosList(servers[0].url)
420
421 const video = res.body.data.find(v => v.name === 'my super name for server 2')
422 const res2 = await getVideo(servers[0].url, video.id)
423 const videoDetails = res2.body
424
425 const file = videoDetails.files.find(f => f.resolution === 360)
426 expect(file).not.to.be.undefined
427
428 const torrent = await webtorrentAdd(file.magnetUri)
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
435 describe('Should update video views, likes and dislikes', function () {
436 let localVideosServer3 = []
437 let remoteVideosServer1 = []
438 let remoteVideosServer2 = []
439 let remoteVideosServer3 = []
440
441 before(async function () {
442 const res1 = await getVideosList(servers[0].url)
443 remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
444
445 const res2 = await getVideosList(servers[1].url)
446 remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
447
448 const res3 = await getVideosList(servers[2].url)
449 localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid)
450 remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid)
451 })
452
453 it('Should view multiple videos on owned servers', async function () {
454 this.timeout(15000)
455
456 const tasks: Promise<any>[] = []
457 await viewVideo(servers[2].url, localVideosServer3[0])
458 await viewVideo(servers[2].url, localVideosServer3[0])
459 await viewVideo(servers[2].url, localVideosServer3[0])
460 await viewVideo(servers[2].url, localVideosServer3[1])
461
462 await Promise.all(tasks)
463 await wait(1500)
464
465 await viewVideo(servers[2].url, localVideosServer3[0])
466
467 await wait(1500)
468
469 await viewVideo(servers[2].url, localVideosServer3[0])
470
471 await wait(5000)
472
473 for (const server of servers) {
474 const res = await getVideosList(server.url)
475
476 const videos = res.body.data
477 const video0 = videos.find(v => v.uuid === localVideosServer3[0])
478 const video1 = videos.find(v => v.uuid === localVideosServer3[1])
479
480 expect(video0.views).to.equal(3)
481 expect(video1.views).to.equal(1)
482 }
483 })
484
485 it('Should view multiple videos on each servers', async function () {
486 this.timeout(15000)
487
488 const tasks: Promise<any>[] = []
489 tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0]))
490 tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0]))
491 tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0]))
492 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[0]))
493 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1]))
494 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1]))
495 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1]))
496 tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
497 tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
498 tasks.push(viewVideo(servers[2].url, localVideosServer3[1]))
499
500 await Promise.all(tasks)
501
502 await wait(10000)
503
504 let baseVideos = null
505
506 for (const server of servers) {
507 const res = await getVideosList(server.url)
508
509 const videos = res.body.data
510
511 // Initialize base videos for future comparisons
512 if (baseVideos === null) {
513 baseVideos = videos
514 continue
515 }
516
517 for (const baseVideo of baseVideos) {
518 const sameVideo = videos.find(video => video.name === baseVideo.name)
519 expect(baseVideo.views).to.equal(sameVideo.views)
520 }
521 }
522 })
523
524 it('Should like and dislikes videos on different services', async function () {
525 this.timeout(20000)
526
527 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')
528 await wait(200)
529 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike')
530 await wait(200)
531 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like')
532 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like')
533 await wait(200)
534 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike')
535 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike')
536 await wait(200)
537 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like')
538
539 await wait(10000)
540
541 let baseVideos = null
542 for (const server of servers) {
543 const res = await getVideosList(server.url)
544
545 const videos = res.body.data
546
547 // Initialize base videos for future comparisons
548 if (baseVideos === null) {
549 baseVideos = videos
550 continue
551 }
552
553 for (const baseVideo of baseVideos) {
554 const sameVideo = videos.find(video => video.name === baseVideo.name)
555 expect(baseVideo.likes).to.equal(sameVideo.likes)
556 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
557 }
558 }
559 })
560 })
561
562 describe('Should manipulate these videos', function () {
563 it('Should update the video 3 by asking server 3', async function () {
564 this.timeout(10000)
565
566 const attributes = {
567 name: 'my super video updated',
568 category: 10,
569 licence: 7,
570 language: 13,
571 nsfw: true,
572 description: 'my super description updated',
573 support: 'my super support text updated',
574 tags: [ 'tag_up_1', 'tag_up_2' ],
575 thumbnailfile: 'thumbnail.jpg',
576 previewfile: 'preview.jpg'
577 }
578
579 await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes)
580
581 await wait(5000)
582 })
583
584 it('Should have the video 3 updated on each server', async function () {
585 this.timeout(10000)
586
587 for (const server of servers) {
588 const res = await getVideosList(server.url)
589
590 const videos = res.body.data
591 const videoUpdated = videos.find(video => video.name === 'my super video updated')
592 expect(!!videoUpdated).to.be.true
593
594 const isLocal = server.url === 'http://localhost:9003'
595 const checkAttributes = {
596 name: 'my super video updated',
597 category: 10,
598 licence: 7,
599 language: 13,
600 nsfw: true,
601 description: 'my super description updated',
602 support: 'my super support text updated',
603 account: {
604 name: 'root',
605 host: 'localhost:9003'
606 },
607 isLocal,
608 duration: 5,
609 commentsEnabled: true,
610 tags: [ 'tag_up_1', 'tag_up_2' ],
611 privacy: VideoPrivacy.PUBLIC,
612 channel: {
613 name: 'Default root channel',
614 description: '',
615 isLocal
616 },
617 fixture: 'video_short3.webm',
618 files: [
619 {
620 resolution: 720,
621 size: 292677
622 }
623 ],
624 thumbnailfile: 'thumbnail',
625 previewfile: 'preview'
626 }
627 await completeVideoCheck(server.url, videoUpdated, checkAttributes)
628 }
629 })
630
631 it('Should remove the videos 3 and 3-2 by asking server 3', async function () {
632 this.timeout(10000)
633
634 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id)
635 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id)
636
637 await wait(5000)
638 })
639
640 it('Should not have files of videos 3 and 3-2 on each server', async function () {
641 for (const server of servers) {
642 await checkVideoFilesWereRemoved(toRemove[0].uuid, server.serverNumber)
643 await checkVideoFilesWereRemoved(toRemove[1].uuid, server.serverNumber)
644 }
645 })
646
647 it('Should have videos 1 and 3 on each server', async function () {
648 for (const server of servers) {
649 const res = await getVideosList(server.url)
650
651 const videos = res.body.data
652 expect(videos).to.be.an('array')
653 expect(videos.length).to.equal(2)
654 expect(videos[0].name).not.to.equal(videos[1].name)
655 expect(videos[0].name).not.to.equal(toRemove[0].name)
656 expect(videos[1].name).not.to.equal(toRemove[0].name)
657 expect(videos[0].name).not.to.equal(toRemove[1].name)
658 expect(videos[1].name).not.to.equal(toRemove[1].name)
659
660 videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid
661 }
662 })
663
664 it('Should get the same video by UUID on each server', async function () {
665 let baseVideo = null
666 for (const server of servers) {
667 const res = await getVideo(server.url, videoUUID)
668
669 const video = res.body
670
671 if (baseVideo === null) {
672 baseVideo = video
673 continue
674 }
675
676 expect(baseVideo.name).to.equal(video.name)
677 expect(baseVideo.uuid).to.equal(video.uuid)
678 expect(baseVideo.category).to.equal(video.category)
679 expect(baseVideo.language).to.equal(video.language)
680 expect(baseVideo.licence).to.equal(video.licence)
681 expect(baseVideo.category).to.equal(video.category)
682 expect(baseVideo.nsfw).to.equal(video.nsfw)
683 expect(baseVideo.account.name).to.equal(video.account.name)
684 expect(baseVideo.account.displayName).to.equal(video.account.displayName)
685 expect(baseVideo.account.url).to.equal(video.account.url)
686 expect(baseVideo.account.host).to.equal(video.account.host)
687 expect(baseVideo.tags).to.deep.equal(video.tags)
688 }
689 })
690
691 it('Should get the preview from each server', async function () {
692 for (const server of servers) {
693 const res = await getVideo(server.url, videoUUID)
694 const video = res.body
695
696 await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
697 }
698 })
699 })
700
701 describe('Should comment these videos', function () {
702 it('Should add comment (threads and replies)', async function () {
703 this.timeout(25000)
704
705 {
706 const text = 'my super first comment'
707 await addVideoCommentThread(servers[ 0 ].url, servers[ 0 ].accessToken, videoUUID, text)
708 }
709
710 {
711 const text = 'my super second comment'
712 await addVideoCommentThread(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, text)
713 }
714
715 await wait(5000)
716
717 {
718 const res = await getVideoCommentThreads(servers[1].url, videoUUID, 0, 5)
719 const threadId = res.body.data.find(c => c.text === 'my super first comment').id
720
721 const text = 'my super answer to thread 1'
722 await addVideoCommentReply(servers[ 1 ].url, servers[ 1 ].accessToken, videoUUID, threadId, text)
723 }
724
725 await wait(5000)
726
727 {
728 const res1 = await getVideoCommentThreads(servers[2].url, videoUUID, 0, 5)
729 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
730
731 const res2 = await getVideoThreadComments(servers[2].url, videoUUID, threadId)
732 const childCommentId = res2.body.children[0].comment.id
733
734 const text3 = 'my second answer to thread 1'
735 await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, threadId, text3)
736
737 const text2 = 'my super answer to answer of thread 1'
738 await addVideoCommentReply(servers[ 2 ].url, servers[ 2 ].accessToken, videoUUID, childCommentId, text2)
739 }
740
741 await wait(5000)
742 })
743
744 it('Should have these threads', async function () {
745 for (const server of servers) {
746 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
747
748 expect(res.body.total).to.equal(2)
749 expect(res.body.data).to.be.an('array')
750 expect(res.body.data).to.have.lengthOf(2)
751
752 {
753 const comment: VideoComment = res.body.data.find(c => c.text === 'my super first comment')
754 expect(comment).to.not.be.undefined
755 expect(comment.inReplyToCommentId).to.be.null
756 expect(comment.account.name).to.equal('root')
757 expect(comment.account.host).to.equal('localhost:9001')
758 expect(comment.totalReplies).to.equal(3)
759 expect(dateIsValid(comment.createdAt as string)).to.be.true
760 expect(dateIsValid(comment.updatedAt as string)).to.be.true
761 }
762
763 {
764 const comment: VideoComment = res.body.data.find(c => c.text === 'my super second comment')
765 expect(comment).to.not.be.undefined
766 expect(comment.inReplyToCommentId).to.be.null
767 expect(comment.account.name).to.equal('root')
768 expect(comment.account.host).to.equal('localhost:9003')
769 expect(comment.totalReplies).to.equal(0)
770 expect(dateIsValid(comment.createdAt as string)).to.be.true
771 expect(dateIsValid(comment.updatedAt as string)).to.be.true
772 }
773 }
774 })
775
776 it('Should have these comments', async function () {
777 for (const server of servers) {
778 const res1 = await getVideoCommentThreads(server.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(server.url, videoUUID, threadId)
782
783 const tree: VideoCommentThreadTree = res2.body
784 expect(tree.comment.text).equal('my super first comment')
785 expect(tree.comment.account.name).equal('root')
786 expect(tree.comment.account.host).equal('localhost:9001')
787 expect(tree.children).to.have.lengthOf(2)
788
789 const firstChild = tree.children[0]
790 expect(firstChild.comment.text).to.equal('my super answer to thread 1')
791 expect(firstChild.comment.account.name).equal('root')
792 expect(firstChild.comment.account.host).equal('localhost:9002')
793 expect(firstChild.children).to.have.lengthOf(1)
794
795 const childOfFirstChild = firstChild.children[0]
796 expect(childOfFirstChild.comment.text).to.equal('my super answer to answer of thread 1')
797 expect(childOfFirstChild.comment.account.name).equal('root')
798 expect(childOfFirstChild.comment.account.host).equal('localhost:9003')
799 expect(childOfFirstChild.children).to.have.lengthOf(0)
800
801 const secondChild = tree.children[1]
802 expect(secondChild.comment.text).to.equal('my second answer to thread 1')
803 expect(secondChild.comment.account.name).equal('root')
804 expect(secondChild.comment.account.host).equal('localhost:9003')
805 expect(secondChild.children).to.have.lengthOf(0)
806 }
807 })
808
809 it('Should delete the thread comments', async function () {
810 this.timeout(10000)
811
812 const res1 = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5)
813 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id
814 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId)
815
816 await wait(5000)
817 })
818
819 it('Should have the thread comments deleted on other servers too', async function () {
820 for (const server of servers) {
821 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5)
822
823 expect(res.body.total).to.equal(1)
824 expect(res.body.data).to.be.an('array')
825 expect(res.body.data).to.have.lengthOf(1)
826
827 {
828 const comment: VideoComment = res.body.data[0]
829 expect(comment).to.not.be.undefined
830 expect(comment.inReplyToCommentId).to.be.null
831 expect(comment.account.name).to.equal('root')
832 expect(comment.account.host).to.equal('localhost:9003')
833 expect(comment.totalReplies).to.equal(0)
834 expect(dateIsValid(comment.createdAt as string)).to.be.true
835 expect(dateIsValid(comment.updatedAt as string)).to.be.true
836 }
837 }
838 })
839
840 it('Should disable comments', async function () {
841 this.timeout(20000)
842
843 const attributes = {
844 commentsEnabled: false
845 }
846
847 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes)
848
849 await wait(5000)
850
851 for (const server of servers) {
852 const res = await getVideo(server.url, videoUUID)
853 expect(res.body.commentsEnabled).to.be.false
854
855 const text = 'my super forbidden comment'
856 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, 409)
857 }
858 })
859 })
860
861 describe('With minimum parameters', function () {
862 it('Should upload and propagate the video', async function () {
863 this.timeout(50000)
864
865 const path = '/api/v1/videos/upload'
866
867 const req = request(servers[1].url)
868 .post(path)
869 .set('Accept', 'application/json')
870 .set('Authorization', 'Bearer ' + servers[1].accessToken)
871 .field('name', 'minimum parameters')
872 .field('privacy', '1')
873 .field('nsfw', 'false')
874 .field('channelId', '1')
875 .field('commentsEnabled', 'true')
876
877 const filePath = join(__dirname, '..', '..', 'api', 'fixtures', 'video_short.webm')
878
879 await req.attach('videofile', filePath)
880 .expect(200)
881
882 await wait(25000)
883
884 for (const server of servers) {
885 const res = await getVideosList(server.url)
886 const video = res.body.data.find(v => v.name === 'minimum parameters')
887
888 const isLocal = server.url === 'http://localhost:9002'
889 const checkAttributes = {
890 name: 'minimum parameters',
891 category: null,
892 licence: null,
893 language: null,
894 nsfw: false,
895 description: null,
896 support: null,
897 account: {
898 name: 'root',
899 host: 'localhost:9002'
900 },
901 isLocal,
902 duration: 5,
903 commentsEnabled: true,
904 tags: [ ],
905 privacy: VideoPrivacy.PUBLIC,
906 channel: {
907 name: 'Default root channel',
908 description: '',
909 isLocal
910 },
911 fixture: 'video_short.webm',
912 files: [
913 {
914 resolution: 720,
915 size: 40315
916 },
917 {
918 resolution: 480,
919 size: 22808
920 },
921 {
922 resolution: 360,
923 size: 18617
924 },
925 {
926 resolution: 240,
927 size: 15217
928 }
929 ]
930 }
931 await completeVideoCheck(server.url, video, checkAttributes)
932 }
933 })
934 })
935
936 after(async function () {
937 killallServers(servers)
938
939 // Keep the logs if the test failed
940 if (this['ok']) {
941 await flushTests()
942 }
943 })
944 })