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