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