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