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