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