aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos/multiple-servers.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/videos/multiple-servers.ts')
-rw-r--r--server/tests/api/videos/multiple-servers.ts472
1 files changed, 220 insertions, 252 deletions
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index a8c8a889b..f9220e4b3 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -3,49 +3,29 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import * as request from 'supertest' 5import * as request from 'supertest'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 6import {
8 addVideoChannel,
9 buildAbsoluteFixturePath, 7 buildAbsoluteFixturePath,
10 checkTmpIsEmpty, 8 checkTmpIsEmpty,
11 checkVideoFilesWereRemoved, 9 checkVideoFilesWereRemoved,
12 cleanupTests, 10 cleanupTests,
13 completeVideoCheck, 11 completeVideoCheck,
14 createUser, 12 createMultipleServers,
15 dateIsValid, 13 dateIsValid,
16 doubleFollow, 14 doubleFollow,
17 flushAndRunMultipleServers, 15 PeerTubeServer,
18 getLocalVideos, 16 saveVideoInServers,
19 getVideo,
20 getVideoChannelsList,
21 getVideosList,
22 rateVideo,
23 removeVideo,
24 ServerInfo,
25 setAccessTokensToServers, 17 setAccessTokensToServers,
26 testImage, 18 testImage,
27 updateVideo,
28 uploadVideo,
29 userLogin,
30 viewVideo,
31 wait, 19 wait,
20 waitJobs,
32 webtorrentAdd 21 webtorrentAdd
33} from '../../../../shared/extra-utils' 22} from '@shared/extra-utils'
34import { waitJobs } from '../../../../shared/extra-utils/server/jobs' 23import { HttpStatusCode, VideoCommentThreadTree, VideoPrivacy } from '@shared/models'
35import {
36 addVideoCommentReply,
37 addVideoCommentThread,
38 deleteVideoComment,
39 findCommentId,
40 getVideoCommentThreads,
41 getVideoThreadComments
42} from '../../../../shared/extra-utils/videos/video-comments'
43import { VideoComment, VideoCommentThreadTree, VideoPrivacy } from '../../../../shared/models/videos'
44 24
45const expect = chai.expect 25const expect = chai.expect
46 26
47describe('Test multiple servers', function () { 27describe('Test multiple servers', function () {
48 let servers: ServerInfo[] = [] 28 let servers: PeerTubeServer[] = []
49 const toRemove = [] 29 const toRemove = []
50 let videoUUID = '' 30 let videoUUID = ''
51 let videoChannelId: number 31 let videoChannelId: number
@@ -53,7 +33,7 @@ describe('Test multiple servers', function () {
53 before(async function () { 33 before(async function () {
54 this.timeout(120000) 34 this.timeout(120000)
55 35
56 servers = await flushAndRunMultipleServers(3) 36 servers = await createMultipleServers(3)
57 37
58 // Get the access tokens 38 // Get the access tokens
59 await setAccessTokensToServers(servers) 39 await setAccessTokensToServers(servers)
@@ -64,9 +44,9 @@ describe('Test multiple servers', function () {
64 displayName: 'my channel', 44 displayName: 'my channel',
65 description: 'super channel' 45 description: 'super channel'
66 } 46 }
67 await addVideoChannel(servers[0].url, servers[0].accessToken, videoChannel) 47 await servers[0].channels.create({ attributes: videoChannel })
68 const channelRes = await getVideoChannelsList(servers[0].url, 0, 1) 48 const { data } = await servers[0].channels.list({ start: 0, count: 1 })
69 videoChannelId = channelRes.body.data[0].id 49 videoChannelId = data[0].id
70 } 50 }
71 51
72 // Server 1 and server 2 follow each other 52 // Server 1 and server 2 follow each other
@@ -79,10 +59,9 @@ describe('Test multiple servers', function () {
79 59
80 it('Should not have videos for all servers', async function () { 60 it('Should not have videos for all servers', async function () {
81 for (const server of servers) { 61 for (const server of servers) {
82 const res = await getVideosList(server.url) 62 const { data } = await server.videos.list()
83 const videos = res.body.data 63 expect(data).to.be.an('array')
84 expect(videos).to.be.an('array') 64 expect(data.length).to.equal(0)
85 expect(videos.length).to.equal(0)
86 } 65 }
87 }) 66 })
88 67
@@ -90,7 +69,7 @@ describe('Test multiple servers', function () {
90 it('Should upload the video on server 1 and propagate on each server', async function () { 69 it('Should upload the video on server 1 and propagate on each server', async function () {
91 this.timeout(25000) 70 this.timeout(25000)
92 71
93 const videoAttributes = { 72 const attributes = {
94 name: 'my super name for server 1', 73 name: 'my super name for server 1',
95 category: 5, 74 category: 5,
96 licence: 4, 75 licence: 4,
@@ -103,7 +82,7 @@ describe('Test multiple servers', function () {
103 channelId: videoChannelId, 82 channelId: videoChannelId,
104 fixture: 'video_short1.webm' 83 fixture: 'video_short1.webm'
105 } 84 }
106 await uploadVideo(servers[0].url, servers[0].accessToken, videoAttributes) 85 await servers[0].videos.upload({ attributes })
107 86
108 await waitJobs(servers) 87 await waitJobs(servers)
109 88
@@ -146,14 +125,13 @@ describe('Test multiple servers', function () {
146 ] 125 ]
147 } 126 }
148 127
149 const res = await getVideosList(server.url) 128 const { data } = await server.videos.list()
150 const videos = res.body.data 129 expect(data).to.be.an('array')
151 expect(videos).to.be.an('array') 130 expect(data.length).to.equal(1)
152 expect(videos.length).to.equal(1) 131 const video = data[0]
153 const video = videos[0]
154 132
155 await completeVideoCheck(server.url, video, checkAttributes) 133 await completeVideoCheck(server, video, checkAttributes)
156 publishedAt = video.publishedAt 134 publishedAt = video.publishedAt as string
157 } 135 }
158 }) 136 })
159 137
@@ -164,10 +142,10 @@ describe('Test multiple servers', function () {
164 username: 'user1', 142 username: 'user1',
165 password: 'super_password' 143 password: 'super_password'
166 } 144 }
167 await createUser({ url: servers[1].url, accessToken: servers[1].accessToken, username: user.username, password: user.password }) 145 await servers[1].users.create({ username: user.username, password: user.password })
168 const userAccessToken = await userLogin(servers[1], user) 146 const userAccessToken = await servers[1].login.getAccessToken(user)
169 147
170 const videoAttributes = { 148 const attributes = {
171 name: 'my super name for server 2', 149 name: 'my super name for server 2',
172 category: 4, 150 category: 4,
173 licence: 3, 151 licence: 3,
@@ -180,7 +158,7 @@ describe('Test multiple servers', function () {
180 thumbnailfile: 'thumbnail.jpg', 158 thumbnailfile: 'thumbnail.jpg',
181 previewfile: 'preview.jpg' 159 previewfile: 'preview.jpg'
182 } 160 }
183 await uploadVideo(servers[1].url, userAccessToken, videoAttributes, HttpStatusCode.OK_200, 'resumable') 161 await servers[1].videos.upload({ token: userAccessToken, attributes, mode: 'resumable' })
184 162
185 // Transcoding 163 // Transcoding
186 await waitJobs(servers) 164 await waitJobs(servers)
@@ -235,65 +213,67 @@ describe('Test multiple servers', function () {
235 previewfile: 'preview' 213 previewfile: 'preview'
236 } 214 }
237 215
238 const res = await getVideosList(server.url) 216 const { data } = await server.videos.list()
239 const videos = res.body.data 217 expect(data).to.be.an('array')
240 expect(videos).to.be.an('array') 218 expect(data.length).to.equal(2)
241 expect(videos.length).to.equal(2) 219 const video = data[1]
242 const video = videos[1]
243 220
244 await completeVideoCheck(server.url, video, checkAttributes) 221 await completeVideoCheck(server, video, checkAttributes)
245 } 222 }
246 }) 223 })
247 224
248 it('Should upload two videos on server 3 and propagate on each server', async function () { 225 it('Should upload two videos on server 3 and propagate on each server', async function () {
249 this.timeout(45000) 226 this.timeout(45000)
250 227
251 const videoAttributes1 = { 228 {
252 name: 'my super name for server 3', 229 const attributes = {
253 category: 6, 230 name: 'my super name for server 3',
254 licence: 5, 231 category: 6,
255 language: 'de', 232 licence: 5,
256 nsfw: true, 233 language: 'de',
257 description: 'my super description for server 3', 234 nsfw: true,
258 support: 'my super support text for server 3', 235 description: 'my super description for server 3',
259 tags: [ 'tag1p3' ], 236 support: 'my super support text for server 3',
260 fixture: 'video_short3.webm' 237 tags: [ 'tag1p3' ],
238 fixture: 'video_short3.webm'
239 }
240 await servers[2].videos.upload({ attributes })
261 } 241 }
262 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes1) 242
263 243 {
264 const videoAttributes2 = { 244 const attributes = {
265 name: 'my super name for server 3-2', 245 name: 'my super name for server 3-2',
266 category: 7, 246 category: 7,
267 licence: 6, 247 licence: 6,
268 language: 'ko', 248 language: 'ko',
269 nsfw: false, 249 nsfw: false,
270 description: 'my super description for server 3-2', 250 description: 'my super description for server 3-2',
271 support: 'my super support text for server 3-2', 251 support: 'my super support text for server 3-2',
272 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ], 252 tags: [ 'tag2p3', 'tag3p3', 'tag4p3' ],
273 fixture: 'video_short.webm' 253 fixture: 'video_short.webm'
254 }
255 await servers[2].videos.upload({ attributes })
274 } 256 }
275 await uploadVideo(servers[2].url, servers[2].accessToken, videoAttributes2)
276 257
277 await waitJobs(servers) 258 await waitJobs(servers)
278 259
279 // All servers should have this video 260 // All servers should have this video
280 for (const server of servers) { 261 for (const server of servers) {
281 const isLocal = server.url === 'http://localhost:' + servers[2].port 262 const isLocal = server.url === 'http://localhost:' + servers[2].port
282 const res = await getVideosList(server.url) 263 const { data } = await server.videos.list()
283 264
284 const videos = res.body.data 265 expect(data).to.be.an('array')
285 expect(videos).to.be.an('array') 266 expect(data.length).to.equal(4)
286 expect(videos.length).to.equal(4)
287 267
288 // We not sure about the order of the two last uploads 268 // We not sure about the order of the two last uploads
289 let video1 = null 269 let video1 = null
290 let video2 = null 270 let video2 = null
291 if (videos[2].name === 'my super name for server 3') { 271 if (data[2].name === 'my super name for server 3') {
292 video1 = videos[2] 272 video1 = data[2]
293 video2 = videos[3] 273 video2 = data[3]
294 } else { 274 } else {
295 video1 = videos[3] 275 video1 = data[3]
296 video2 = videos[2] 276 video2 = data[2]
297 } 277 }
298 278
299 const checkAttributesVideo1 = { 279 const checkAttributesVideo1 = {
@@ -328,7 +308,7 @@ describe('Test multiple servers', function () {
328 } 308 }
329 ] 309 ]
330 } 310 }
331 await completeVideoCheck(server.url, video1, checkAttributesVideo1) 311 await completeVideoCheck(server, video1, checkAttributesVideo1)
332 312
333 const checkAttributesVideo2 = { 313 const checkAttributesVideo2 = {
334 name: 'my super name for server 3-2', 314 name: 'my super name for server 3-2',
@@ -362,38 +342,38 @@ describe('Test multiple servers', function () {
362 } 342 }
363 ] 343 ]
364 } 344 }
365 await completeVideoCheck(server.url, video2, checkAttributesVideo2) 345 await completeVideoCheck(server, video2, checkAttributesVideo2)
366 } 346 }
367 }) 347 })
368 }) 348 })
369 349
370 describe('It should list local videos', function () { 350 describe('It should list local videos', function () {
371 it('Should list only local videos on server 1', async function () { 351 it('Should list only local videos on server 1', async function () {
372 const { body } = await getLocalVideos(servers[0].url) 352 const { data, total } = await servers[0].videos.list({ filter: 'local' })
373 353
374 expect(body.total).to.equal(1) 354 expect(total).to.equal(1)
375 expect(body.data).to.be.an('array') 355 expect(data).to.be.an('array')
376 expect(body.data.length).to.equal(1) 356 expect(data.length).to.equal(1)
377 expect(body.data[0].name).to.equal('my super name for server 1') 357 expect(data[0].name).to.equal('my super name for server 1')
378 }) 358 })
379 359
380 it('Should list only local videos on server 2', async function () { 360 it('Should list only local videos on server 2', async function () {
381 const { body } = await getLocalVideos(servers[1].url) 361 const { data, total } = await servers[1].videos.list({ filter: 'local' })
382 362
383 expect(body.total).to.equal(1) 363 expect(total).to.equal(1)
384 expect(body.data).to.be.an('array') 364 expect(data).to.be.an('array')
385 expect(body.data.length).to.equal(1) 365 expect(data.length).to.equal(1)
386 expect(body.data[0].name).to.equal('my super name for server 2') 366 expect(data[0].name).to.equal('my super name for server 2')
387 }) 367 })
388 368
389 it('Should list only local videos on server 3', async function () { 369 it('Should list only local videos on server 3', async function () {
390 const { body } = await getLocalVideos(servers[2].url) 370 const { data, total } = await servers[2].videos.list({ filter: 'local' })
391 371
392 expect(body.total).to.equal(2) 372 expect(total).to.equal(2)
393 expect(body.data).to.be.an('array') 373 expect(data).to.be.an('array')
394 expect(body.data.length).to.equal(2) 374 expect(data.length).to.equal(2)
395 expect(body.data[0].name).to.equal('my super name for server 3') 375 expect(data[0].name).to.equal('my super name for server 3')
396 expect(body.data[1].name).to.equal('my super name for server 3-2') 376 expect(data[1].name).to.equal('my super name for server 3-2')
397 }) 377 })
398 }) 378 })
399 379
@@ -401,15 +381,13 @@ describe('Test multiple servers', function () {
401 it('Should add the file 1 by asking server 3', async function () { 381 it('Should add the file 1 by asking server 3', async function () {
402 this.timeout(10000) 382 this.timeout(10000)
403 383
404 const res = await getVideosList(servers[2].url) 384 const { data } = await servers[2].videos.list()
405
406 const video = res.body.data[0]
407 toRemove.push(res.body.data[2])
408 toRemove.push(res.body.data[3])
409 385
410 const res2 = await getVideo(servers[2].url, video.id) 386 const video = data[0]
411 const videoDetails = res2.body 387 toRemove.push(data[2])
388 toRemove.push(data[3])
412 389
390 const videoDetails = await servers[2].videos.get({ id: video.id })
413 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) 391 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
414 expect(torrent.files).to.be.an('array') 392 expect(torrent.files).to.be.an('array')
415 expect(torrent.files.length).to.equal(1) 393 expect(torrent.files.length).to.equal(1)
@@ -419,11 +397,10 @@ describe('Test multiple servers', function () {
419 it('Should add the file 2 by asking server 1', async function () { 397 it('Should add the file 2 by asking server 1', async function () {
420 this.timeout(10000) 398 this.timeout(10000)
421 399
422 const res = await getVideosList(servers[0].url) 400 const { data } = await servers[0].videos.list()
423 401
424 const video = res.body.data[1] 402 const video = data[1]
425 const res2 = await getVideo(servers[0].url, video.id) 403 const videoDetails = await servers[0].videos.get({ id: video.id })
426 const videoDetails = res2.body
427 404
428 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) 405 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
429 expect(torrent.files).to.be.an('array') 406 expect(torrent.files).to.be.an('array')
@@ -434,11 +411,10 @@ describe('Test multiple servers', function () {
434 it('Should add the file 3 by asking server 2', async function () { 411 it('Should add the file 3 by asking server 2', async function () {
435 this.timeout(10000) 412 this.timeout(10000)
436 413
437 const res = await getVideosList(servers[1].url) 414 const { data } = await servers[1].videos.list()
438 415
439 const video = res.body.data[2] 416 const video = data[2]
440 const res2 = await getVideo(servers[1].url, video.id) 417 const videoDetails = await servers[1].videos.get({ id: video.id })
441 const videoDetails = res2.body
442 418
443 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) 419 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true)
444 expect(torrent.files).to.be.an('array') 420 expect(torrent.files).to.be.an('array')
@@ -449,11 +425,10 @@ describe('Test multiple servers', function () {
449 it('Should add the file 3-2 by asking server 1', async function () { 425 it('Should add the file 3-2 by asking server 1', async function () {
450 this.timeout(10000) 426 this.timeout(10000)
451 427
452 const res = await getVideosList(servers[0].url) 428 const { data } = await servers[0].videos.list()
453 429
454 const video = res.body.data[3] 430 const video = data[3]
455 const res2 = await getVideo(servers[0].url, video.id) 431 const videoDetails = await servers[0].videos.get({ id: video.id })
456 const videoDetails = res2.body
457 432
458 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) 433 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri)
459 expect(torrent.files).to.be.an('array') 434 expect(torrent.files).to.be.an('array')
@@ -464,11 +439,10 @@ describe('Test multiple servers', function () {
464 it('Should add the file 2 in 360p by asking server 1', async function () { 439 it('Should add the file 2 in 360p by asking server 1', async function () {
465 this.timeout(10000) 440 this.timeout(10000)
466 441
467 const res = await getVideosList(servers[0].url) 442 const { data } = await servers[0].videos.list()
468 443
469 const video = res.body.data.find(v => v.name === 'my super name for server 2') 444 const video = data.find(v => v.name === 'my super name for server 2')
470 const res2 = await getVideo(servers[0].url, video.id) 445 const videoDetails = await servers[0].videos.get({ id: video.id })
471 const videoDetails = res2.body
472 446
473 const file = videoDetails.files.find(f => f.resolution.id === 360) 447 const file = videoDetails.files.find(f => f.resolution.id === 360)
474 expect(file).not.to.be.undefined 448 expect(file).not.to.be.undefined
@@ -487,30 +461,36 @@ describe('Test multiple servers', function () {
487 let remoteVideosServer3 = [] 461 let remoteVideosServer3 = []
488 462
489 before(async function () { 463 before(async function () {
490 const res1 = await getVideosList(servers[0].url) 464 {
491 remoteVideosServer1 = res1.body.data.filter(video => video.isLocal === false).map(video => video.uuid) 465 const { data } = await servers[0].videos.list()
466 remoteVideosServer1 = data.filter(video => video.isLocal === false).map(video => video.uuid)
467 }
492 468
493 const res2 = await getVideosList(servers[1].url) 469 {
494 remoteVideosServer2 = res2.body.data.filter(video => video.isLocal === false).map(video => video.uuid) 470 const { data } = await servers[1].videos.list()
471 remoteVideosServer2 = data.filter(video => video.isLocal === false).map(video => video.uuid)
472 }
495 473
496 const res3 = await getVideosList(servers[2].url) 474 {
497 localVideosServer3 = res3.body.data.filter(video => video.isLocal === true).map(video => video.uuid) 475 const { data } = await servers[2].videos.list()
498 remoteVideosServer3 = res3.body.data.filter(video => video.isLocal === false).map(video => video.uuid) 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 }
499 }) 479 })
500 480
501 it('Should view multiple videos on owned servers', async function () { 481 it('Should view multiple videos on owned servers', async function () {
502 this.timeout(30000) 482 this.timeout(30000)
503 483
504 await viewVideo(servers[2].url, localVideosServer3[0]) 484 await servers[2].videos.view({ id: localVideosServer3[0] })
505 await wait(1000) 485 await wait(1000)
506 486
507 await viewVideo(servers[2].url, localVideosServer3[0]) 487 await servers[2].videos.view({ id: localVideosServer3[0] })
508 await viewVideo(servers[2].url, localVideosServer3[1]) 488 await servers[2].videos.view({ id: localVideosServer3[1] })
509 489
510 await wait(1000) 490 await wait(1000)
511 491
512 await viewVideo(servers[2].url, localVideosServer3[0]) 492 await servers[2].videos.view({ id: localVideosServer3[0] })
513 await viewVideo(servers[2].url, localVideosServer3[0]) 493 await servers[2].videos.view({ id: localVideosServer3[0] })
514 494
515 await waitJobs(servers) 495 await waitJobs(servers)
516 496
@@ -520,11 +500,10 @@ describe('Test multiple servers', function () {
520 await waitJobs(servers) 500 await waitJobs(servers)
521 501
522 for (const server of servers) { 502 for (const server of servers) {
523 const res = await getVideosList(server.url) 503 const { data } = await server.videos.list()
524 504
525 const videos = res.body.data 505 const video0 = data.find(v => v.uuid === localVideosServer3[0])
526 const video0 = videos.find(v => v.uuid === localVideosServer3[0]) 506 const video1 = data.find(v => v.uuid === localVideosServer3[1])
527 const video1 = videos.find(v => v.uuid === localVideosServer3[1])
528 507
529 expect(video0.views).to.equal(3) 508 expect(video0.views).to.equal(3)
530 expect(video1.views).to.equal(1) 509 expect(video1.views).to.equal(1)
@@ -535,16 +514,16 @@ describe('Test multiple servers', function () {
535 this.timeout(45000) 514 this.timeout(45000)
536 515
537 const tasks: Promise<any>[] = [] 516 const tasks: Promise<any>[] = []
538 tasks.push(viewVideo(servers[0].url, remoteVideosServer1[0])) 517 tasks.push(servers[0].videos.view({ id: remoteVideosServer1[0] }))
539 tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) 518 tasks.push(servers[1].videos.view({ id: remoteVideosServer2[0] }))
540 tasks.push(viewVideo(servers[1].url, remoteVideosServer2[0])) 519 tasks.push(servers[1].videos.view({ id: remoteVideosServer2[0] }))
541 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[0])) 520 tasks.push(servers[2].videos.view({ id: remoteVideosServer3[0] }))
542 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) 521 tasks.push(servers[2].videos.view({ id: remoteVideosServer3[1] }))
543 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) 522 tasks.push(servers[2].videos.view({ id: remoteVideosServer3[1] }))
544 tasks.push(viewVideo(servers[2].url, remoteVideosServer3[1])) 523 tasks.push(servers[2].videos.view({ id: remoteVideosServer3[1] }))
545 tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) 524 tasks.push(servers[2].videos.view({ id: localVideosServer3[1] }))
546 tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) 525 tasks.push(servers[2].videos.view({ id: localVideosServer3[1] }))
547 tasks.push(viewVideo(servers[2].url, localVideosServer3[1])) 526 tasks.push(servers[2].videos.view({ id: localVideosServer3[1] }))
548 527
549 await Promise.all(tasks) 528 await Promise.all(tasks)
550 529
@@ -558,18 +537,16 @@ describe('Test multiple servers', function () {
558 let baseVideos = null 537 let baseVideos = null
559 538
560 for (const server of servers) { 539 for (const server of servers) {
561 const res = await getVideosList(server.url) 540 const { data } = await server.videos.list()
562
563 const videos = res.body.data
564 541
565 // Initialize base videos for future comparisons 542 // Initialize base videos for future comparisons
566 if (baseVideos === null) { 543 if (baseVideos === null) {
567 baseVideos = videos 544 baseVideos = data
568 continue 545 continue
569 } 546 }
570 547
571 for (const baseVideo of baseVideos) { 548 for (const baseVideo of baseVideos) {
572 const sameVideo = videos.find(video => video.name === baseVideo.name) 549 const sameVideo = data.find(video => video.name === baseVideo.name)
573 expect(baseVideo.views).to.equal(sameVideo.views) 550 expect(baseVideo.views).to.equal(sameVideo.views)
574 } 551 }
575 } 552 }
@@ -578,35 +555,34 @@ describe('Test multiple servers', function () {
578 it('Should like and dislikes videos on different services', async function () { 555 it('Should like and dislikes videos on different services', async function () {
579 this.timeout(50000) 556 this.timeout(50000)
580 557
581 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like') 558 await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'like' })
582 await wait(500) 559 await wait(500)
583 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'dislike') 560 await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'dislike' })
584 await wait(500) 561 await wait(500)
585 await rateVideo(servers[0].url, servers[0].accessToken, remoteVideosServer1[0], 'like') 562 await servers[0].videos.rate({ id: remoteVideosServer1[0], rating: 'like' })
586 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'like') 563 await servers[2].videos.rate({ id: localVideosServer3[1], rating: 'like' })
587 await wait(500) 564 await wait(500)
588 await rateVideo(servers[2].url, servers[2].accessToken, localVideosServer3[1], 'dislike') 565 await servers[2].videos.rate({ id: localVideosServer3[1], rating: 'dislike' })
589 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[1], 'dislike') 566 await servers[2].videos.rate({ id: remoteVideosServer3[1], rating: 'dislike' })
590 await wait(500) 567 await wait(500)
591 await rateVideo(servers[2].url, servers[2].accessToken, remoteVideosServer3[0], 'like') 568 await servers[2].videos.rate({ id: remoteVideosServer3[0], rating: 'like' })
592 569
593 await waitJobs(servers) 570 await waitJobs(servers)
594 await wait(5000) 571 await wait(5000)
572 await waitJobs(servers)
595 573
596 let baseVideos = null 574 let baseVideos = null
597 for (const server of servers) { 575 for (const server of servers) {
598 const res = await getVideosList(server.url) 576 const { data } = await server.videos.list()
599
600 const videos = res.body.data
601 577
602 // Initialize base videos for future comparisons 578 // Initialize base videos for future comparisons
603 if (baseVideos === null) { 579 if (baseVideos === null) {
604 baseVideos = videos 580 baseVideos = data
605 continue 581 continue
606 } 582 }
607 583
608 for (const baseVideo of baseVideos) { 584 for (const baseVideo of baseVideos) {
609 const sameVideo = videos.find(video => video.name === baseVideo.name) 585 const sameVideo = data.find(video => video.name === baseVideo.name)
610 expect(baseVideo.likes).to.equal(sameVideo.likes) 586 expect(baseVideo.likes).to.equal(sameVideo.likes)
611 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes) 587 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
612 } 588 }
@@ -632,7 +608,7 @@ describe('Test multiple servers', function () {
632 previewfile: 'preview.jpg' 608 previewfile: 'preview.jpg'
633 } 609 }
634 610
635 await updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, attributes) 611 await servers[2].videos.update({ id: toRemove[0].id, attributes })
636 612
637 await waitJobs(servers) 613 await waitJobs(servers)
638 }) 614 })
@@ -641,10 +617,9 @@ describe('Test multiple servers', function () {
641 this.timeout(10000) 617 this.timeout(10000)
642 618
643 for (const server of servers) { 619 for (const server of servers) {
644 const res = await getVideosList(server.url) 620 const { data } = await server.videos.list()
645 621
646 const videos = res.body.data 622 const videoUpdated = data.find(video => video.name === 'my super video updated')
647 const videoUpdated = videos.find(video => video.name === 'my super video updated')
648 expect(!!videoUpdated).to.be.true 623 expect(!!videoUpdated).to.be.true
649 624
650 const isLocal = server.url === 'http://localhost:' + servers[2].port 625 const isLocal = server.url === 'http://localhost:' + servers[2].port
@@ -683,49 +658,46 @@ describe('Test multiple servers', function () {
683 thumbnailfile: 'thumbnail', 658 thumbnailfile: 'thumbnail',
684 previewfile: 'preview' 659 previewfile: 'preview'
685 } 660 }
686 await completeVideoCheck(server.url, videoUpdated, checkAttributes) 661 await completeVideoCheck(server, videoUpdated, checkAttributes)
687 } 662 }
688 }) 663 })
689 664
690 it('Should remove the videos 3 and 3-2 by asking server 3', async function () { 665 it('Should remove the videos 3 and 3-2 by asking server 3 and correctly delete files', async function () {
691 this.timeout(10000) 666 this.timeout(30000)
692 667
693 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[0].id) 668 for (const id of [ toRemove[0].id, toRemove[1].id ]) {
694 await removeVideo(servers[2].url, servers[2].accessToken, toRemove[1].id) 669 await saveVideoInServers(servers, id)
695 670
696 await waitJobs(servers) 671 await servers[2].videos.remove({ id })
697 })
698 672
699 it('Should not have files of videos 3 and 3-2 on each server', async function () { 673 await waitJobs(servers)
700 for (const server of servers) { 674
701 await checkVideoFilesWereRemoved(toRemove[0].uuid, server.internalServerNumber) 675 for (const server of servers) {
702 await checkVideoFilesWereRemoved(toRemove[1].uuid, server.internalServerNumber) 676 await checkVideoFilesWereRemoved({ server, video: server.store.videoDetails })
677 }
703 } 678 }
704 }) 679 })
705 680
706 it('Should have videos 1 and 3 on each server', async function () { 681 it('Should have videos 1 and 3 on each server', async function () {
707 for (const server of servers) { 682 for (const server of servers) {
708 const res = await getVideosList(server.url) 683 const { data } = await server.videos.list()
709 684
710 const videos = res.body.data 685 expect(data).to.be.an('array')
711 expect(videos).to.be.an('array') 686 expect(data.length).to.equal(2)
712 expect(videos.length).to.equal(2) 687 expect(data[0].name).not.to.equal(data[1].name)
713 expect(videos[0].name).not.to.equal(videos[1].name) 688 expect(data[0].name).not.to.equal(toRemove[0].name)
714 expect(videos[0].name).not.to.equal(toRemove[0].name) 689 expect(data[1].name).not.to.equal(toRemove[0].name)
715 expect(videos[1].name).not.to.equal(toRemove[0].name) 690 expect(data[0].name).not.to.equal(toRemove[1].name)
716 expect(videos[0].name).not.to.equal(toRemove[1].name) 691 expect(data[1].name).not.to.equal(toRemove[1].name)
717 expect(videos[1].name).not.to.equal(toRemove[1].name) 692
718 693 videoUUID = data.find(video => video.name === 'my super name for server 1').uuid
719 videoUUID = videos.find(video => video.name === 'my super name for server 1').uuid
720 } 694 }
721 }) 695 })
722 696
723 it('Should get the same video by UUID on each server', async function () { 697 it('Should get the same video by UUID on each server', async function () {
724 let baseVideo = null 698 let baseVideo = null
725 for (const server of servers) { 699 for (const server of servers) {
726 const res = await getVideo(server.url, videoUUID) 700 const video = await server.videos.get({ id: videoUUID })
727
728 const video = res.body
729 701
730 if (baseVideo === null) { 702 if (baseVideo === null) {
731 baseVideo = video 703 baseVideo = video
@@ -748,8 +720,7 @@ describe('Test multiple servers', function () {
748 720
749 it('Should get the preview from each server', async function () { 721 it('Should get the preview from each server', async function () {
750 for (const server of servers) { 722 for (const server of servers) {
751 const res = await getVideo(server.url, videoUUID) 723 const video = await server.videos.get({ id: videoUUID })
752 const video = res.body
753 724
754 await testImage(server.url, 'video_short1-preview.webm', video.previewPath) 725 await testImage(server.url, 'video_short1-preview.webm', video.previewPath)
755 } 726 }
@@ -764,36 +735,36 @@ describe('Test multiple servers', function () {
764 735
765 { 736 {
766 const text = 'my super first comment' 737 const text = 'my super first comment'
767 await addVideoCommentThread(servers[0].url, servers[0].accessToken, videoUUID, text) 738 await servers[0].comments.createThread({ videoId: videoUUID, text })
768 } 739 }
769 740
770 { 741 {
771 const text = 'my super second comment' 742 const text = 'my super second comment'
772 await addVideoCommentThread(servers[2].url, servers[2].accessToken, videoUUID, text) 743 await servers[2].comments.createThread({ videoId: videoUUID, text })
773 } 744 }
774 745
775 await waitJobs(servers) 746 await waitJobs(servers)
776 747
777 { 748 {
778 const threadId = await findCommentId(servers[1].url, videoUUID, 'my super first comment') 749 const threadId = await servers[1].comments.findCommentId({ videoId: videoUUID, text: 'my super first comment' })
779 750
780 const text = 'my super answer to thread 1' 751 const text = 'my super answer to thread 1'
781 await addVideoCommentReply(servers[1].url, servers[1].accessToken, videoUUID, threadId, text) 752 await servers[1].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text })
782 } 753 }
783 754
784 await waitJobs(servers) 755 await waitJobs(servers)
785 756
786 { 757 {
787 const threadId = await findCommentId(servers[2].url, videoUUID, 'my super first comment') 758 const threadId = await servers[2].comments.findCommentId({ videoId: videoUUID, text: 'my super first comment' })
788 759
789 const res2 = await getVideoThreadComments(servers[2].url, videoUUID, threadId) 760 const body = await servers[2].comments.getThread({ videoId: videoUUID, threadId })
790 const childCommentId = res2.body.children[0].comment.id 761 const childCommentId = body.children[0].comment.id
791 762
792 const text3 = 'my second answer to thread 1' 763 const text3 = 'my second answer to thread 1'
793 await addVideoCommentReply(servers[2].url, servers[2].accessToken, videoUUID, threadId, text3) 764 await servers[2].comments.addReply({ videoId: videoUUID, toCommentId: threadId, text: text3 })
794 765
795 const text2 = 'my super answer to answer of thread 1' 766 const text2 = 'my super answer to answer of thread 1'
796 await addVideoCommentReply(servers[2].url, servers[2].accessToken, videoUUID, childCommentId, text2) 767 await servers[2].comments.addReply({ videoId: videoUUID, toCommentId: childCommentId, text: text2 })
797 } 768 }
798 769
799 await waitJobs(servers) 770 await waitJobs(servers)
@@ -801,14 +772,14 @@ describe('Test multiple servers', function () {
801 772
802 it('Should have these threads', async function () { 773 it('Should have these threads', async function () {
803 for (const server of servers) { 774 for (const server of servers) {
804 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 775 const body = await server.comments.listThreads({ videoId: videoUUID })
805 776
806 expect(res.body.total).to.equal(2) 777 expect(body.total).to.equal(2)
807 expect(res.body.data).to.be.an('array') 778 expect(body.data).to.be.an('array')
808 expect(res.body.data).to.have.lengthOf(2) 779 expect(body.data).to.have.lengthOf(2)
809 780
810 { 781 {
811 const comment: VideoComment = res.body.data.find(c => c.text === 'my super first comment') 782 const comment = body.data.find(c => c.text === 'my super first comment')
812 expect(comment).to.not.be.undefined 783 expect(comment).to.not.be.undefined
813 expect(comment.inReplyToCommentId).to.be.null 784 expect(comment.inReplyToCommentId).to.be.null
814 expect(comment.account.name).to.equal('root') 785 expect(comment.account.name).to.equal('root')
@@ -819,7 +790,7 @@ describe('Test multiple servers', function () {
819 } 790 }
820 791
821 { 792 {
822 const comment: VideoComment = res.body.data.find(c => c.text === 'my super second comment') 793 const comment = body.data.find(c => c.text === 'my super second comment')
823 expect(comment).to.not.be.undefined 794 expect(comment).to.not.be.undefined
824 expect(comment.inReplyToCommentId).to.be.null 795 expect(comment.inReplyToCommentId).to.be.null
825 expect(comment.account.name).to.equal('root') 796 expect(comment.account.name).to.equal('root')
@@ -833,12 +804,11 @@ describe('Test multiple servers', function () {
833 804
834 it('Should have these comments', async function () { 805 it('Should have these comments', async function () {
835 for (const server of servers) { 806 for (const server of servers) {
836 const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 807 const body = await server.comments.listThreads({ videoId: videoUUID })
837 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id 808 const threadId = body.data.find(c => c.text === 'my super first comment').id
838 809
839 const res2 = await getVideoThreadComments(server.url, videoUUID, threadId) 810 const tree = await server.comments.getThread({ videoId: videoUUID, threadId })
840 811
841 const tree: VideoCommentThreadTree = res2.body
842 expect(tree.comment.text).equal('my super first comment') 812 expect(tree.comment.text).equal('my super first comment')
843 expect(tree.comment.account.name).equal('root') 813 expect(tree.comment.account.name).equal('root')
844 expect(tree.comment.account.host).equal('localhost:' + servers[0].port) 814 expect(tree.comment.account.host).equal('localhost:' + servers[0].port)
@@ -867,19 +837,17 @@ describe('Test multiple servers', function () {
867 it('Should delete a reply', async function () { 837 it('Should delete a reply', async function () {
868 this.timeout(10000) 838 this.timeout(10000)
869 839
870 await deleteVideoComment(servers[2].url, servers[2].accessToken, videoUUID, childOfFirstChild.comment.id) 840 await servers[2].comments.delete({ videoId: videoUUID, commentId: childOfFirstChild.comment.id })
871 841
872 await waitJobs(servers) 842 await waitJobs(servers)
873 }) 843 })
874 844
875 it('Should have this comment marked as deleted', async function () { 845 it('Should have this comment marked as deleted', async function () {
876 for (const server of servers) { 846 for (const server of servers) {
877 const res1 = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 847 const { data } = await server.comments.listThreads({ videoId: videoUUID })
878 const threadId = res1.body.data.find(c => c.text === 'my super first comment').id 848 const threadId = data.find(c => c.text === 'my super first comment').id
879
880 const res2 = await getVideoThreadComments(server.url, videoUUID, threadId)
881 849
882 const tree: VideoCommentThreadTree = res2.body 850 const tree = await server.comments.getThread({ videoId: videoUUID, threadId })
883 expect(tree.comment.text).equal('my super first comment') 851 expect(tree.comment.text).equal('my super first comment')
884 852
885 const firstChild = tree.children[0] 853 const firstChild = tree.children[0]
@@ -900,23 +868,23 @@ describe('Test multiple servers', function () {
900 it('Should delete the thread comments', async function () { 868 it('Should delete the thread comments', async function () {
901 this.timeout(10000) 869 this.timeout(10000)
902 870
903 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5) 871 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
904 const threadId = res.body.data.find(c => c.text === 'my super first comment').id 872 const commentId = data.find(c => c.text === 'my super first comment').id
905 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) 873 await servers[0].comments.delete({ videoId: videoUUID, commentId })
906 874
907 await waitJobs(servers) 875 await waitJobs(servers)
908 }) 876 })
909 877
910 it('Should have the threads marked as deleted on other servers too', async function () { 878 it('Should have the threads marked as deleted on other servers too', async function () {
911 for (const server of servers) { 879 for (const server of servers) {
912 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 880 const body = await server.comments.listThreads({ videoId: videoUUID })
913 881
914 expect(res.body.total).to.equal(2) 882 expect(body.total).to.equal(2)
915 expect(res.body.data).to.be.an('array') 883 expect(body.data).to.be.an('array')
916 expect(res.body.data).to.have.lengthOf(2) 884 expect(body.data).to.have.lengthOf(2)
917 885
918 { 886 {
919 const comment: VideoComment = res.body.data[0] 887 const comment = body.data[0]
920 expect(comment).to.not.be.undefined 888 expect(comment).to.not.be.undefined
921 expect(comment.inReplyToCommentId).to.be.null 889 expect(comment.inReplyToCommentId).to.be.null
922 expect(comment.account.name).to.equal('root') 890 expect(comment.account.name).to.equal('root')
@@ -927,7 +895,7 @@ describe('Test multiple servers', function () {
927 } 895 }
928 896
929 { 897 {
930 const deletedComment: VideoComment = res.body.data[1] 898 const deletedComment = body.data[1]
931 expect(deletedComment).to.not.be.undefined 899 expect(deletedComment).to.not.be.undefined
932 expect(deletedComment.isDeleted).to.be.true 900 expect(deletedComment.isDeleted).to.be.true
933 expect(deletedComment.deletedAt).to.not.be.null 901 expect(deletedComment.deletedAt).to.not.be.null
@@ -945,22 +913,22 @@ describe('Test multiple servers', function () {
945 it('Should delete a remote thread by the origin server', async function () { 913 it('Should delete a remote thread by the origin server', async function () {
946 this.timeout(5000) 914 this.timeout(5000)
947 915
948 const res = await getVideoCommentThreads(servers[0].url, videoUUID, 0, 5) 916 const { data } = await servers[0].comments.listThreads({ videoId: videoUUID })
949 const threadId = res.body.data.find(c => c.text === 'my super second comment').id 917 const commentId = data.find(c => c.text === 'my super second comment').id
950 await deleteVideoComment(servers[0].url, servers[0].accessToken, videoUUID, threadId) 918 await servers[0].comments.delete({ videoId: videoUUID, commentId })
951 919
952 await waitJobs(servers) 920 await waitJobs(servers)
953 }) 921 })
954 922
955 it('Should have the threads marked as deleted on other servers too', async function () { 923 it('Should have the threads marked as deleted on other servers too', async function () {
956 for (const server of servers) { 924 for (const server of servers) {
957 const res = await getVideoCommentThreads(server.url, videoUUID, 0, 5) 925 const body = await server.comments.listThreads({ videoId: videoUUID })
958 926
959 expect(res.body.total).to.equal(2) 927 expect(body.total).to.equal(2)
960 expect(res.body.data).to.have.lengthOf(2) 928 expect(body.data).to.have.lengthOf(2)
961 929
962 { 930 {
963 const comment: VideoComment = res.body.data[0] 931 const comment = body.data[0]
964 expect(comment.text).to.equal('') 932 expect(comment.text).to.equal('')
965 expect(comment.isDeleted).to.be.true 933 expect(comment.isDeleted).to.be.true
966 expect(comment.createdAt).to.not.be.null 934 expect(comment.createdAt).to.not.be.null
@@ -970,7 +938,7 @@ describe('Test multiple servers', function () {
970 } 938 }
971 939
972 { 940 {
973 const comment: VideoComment = res.body.data[1] 941 const comment = body.data[1]
974 expect(comment.text).to.equal('') 942 expect(comment.text).to.equal('')
975 expect(comment.isDeleted).to.be.true 943 expect(comment.isDeleted).to.be.true
976 expect(comment.createdAt).to.not.be.null 944 expect(comment.createdAt).to.not.be.null
@@ -989,17 +957,17 @@ describe('Test multiple servers', function () {
989 downloadEnabled: false 957 downloadEnabled: false
990 } 958 }
991 959
992 await updateVideo(servers[0].url, servers[0].accessToken, videoUUID, attributes) 960 await servers[0].videos.update({ id: videoUUID, attributes })
993 961
994 await waitJobs(servers) 962 await waitJobs(servers)
995 963
996 for (const server of servers) { 964 for (const server of servers) {
997 const res = await getVideo(server.url, videoUUID) 965 const video = await server.videos.get({ id: videoUUID })
998 expect(res.body.commentsEnabled).to.be.false 966 expect(video.commentsEnabled).to.be.false
999 expect(res.body.downloadEnabled).to.be.false 967 expect(video.downloadEnabled).to.be.false
1000 968
1001 const text = 'my super forbidden comment' 969 const text = 'my super forbidden comment'
1002 await addVideoCommentThread(server.url, server.accessToken, videoUUID, text, HttpStatusCode.CONFLICT_409) 970 await server.comments.createThread({ videoId: videoUUID, text, expectedStatus: HttpStatusCode.CONFLICT_409 })
1003 } 971 }
1004 }) 972 })
1005 }) 973 })
@@ -1024,8 +992,8 @@ describe('Test multiple servers', function () {
1024 await waitJobs(servers) 992 await waitJobs(servers)
1025 993
1026 for (const server of servers) { 994 for (const server of servers) {
1027 const res = await getVideosList(server.url) 995 const { data } = await server.videos.list()
1028 const video = res.body.data.find(v => v.name === 'minimum parameters') 996 const video = data.find(v => v.name === 'minimum parameters')
1029 997
1030 const isLocal = server.url === 'http://localhost:' + servers[1].port 998 const isLocal = server.url === 'http://localhost:' + servers[1].port
1031 const checkAttributes = { 999 const checkAttributes = {
@@ -1072,7 +1040,7 @@ describe('Test multiple servers', function () {
1072 } 1040 }
1073 ] 1041 ]
1074 } 1042 }
1075 await completeVideoCheck(server.url, video, checkAttributes) 1043 await completeVideoCheck(server, video, checkAttributes)
1076 } 1044 }
1077 }) 1045 })
1078 }) 1046 })