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