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