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