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