aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/videos
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/videos')
-rw-r--r--server/tests/api/videos/multiple-servers.ts42
-rw-r--r--server/tests/api/videos/resumable-upload.ts2
-rw-r--r--server/tests/api/videos/single-server.ts21
-rw-r--r--server/tests/api/videos/video-channel-syncs.ts11
-rw-r--r--server/tests/api/videos/video-channels.ts22
-rw-r--r--server/tests/api/videos/video-static-file-privacy.ts3
6 files changed, 57 insertions, 44 deletions
diff --git a/server/tests/api/videos/multiple-servers.ts b/server/tests/api/videos/multiple-servers.ts
index ff730287a..a52a04e07 100644
--- a/server/tests/api/videos/multiple-servers.ts
+++ b/server/tests/api/videos/multiple-servers.ts
@@ -5,6 +5,7 @@ import request from 'supertest'
5import { 5import {
6 checkTmpIsEmpty, 6 checkTmpIsEmpty,
7 checkVideoFilesWereRemoved, 7 checkVideoFilesWereRemoved,
8 checkWebTorrentWorks,
8 completeVideoCheck, 9 completeVideoCheck,
9 dateIsValid, 10 dateIsValid,
10 saveVideoInServers, 11 saveVideoInServers,
@@ -21,8 +22,7 @@ import {
21 setAccessTokensToServers, 22 setAccessTokensToServers,
22 setDefaultAccountAvatar, 23 setDefaultAccountAvatar,
23 setDefaultChannelAvatar, 24 setDefaultChannelAvatar,
24 waitJobs, 25 waitJobs
25 webtorrentAdd
26} from '@shared/server-commands' 26} from '@shared/server-commands'
27 27
28describe('Test multiple servers', function () { 28describe('Test multiple servers', function () {
@@ -134,7 +134,7 @@ describe('Test multiple servers', function () {
134 expect(data.length).to.equal(1) 134 expect(data.length).to.equal(1)
135 const video = data[0] 135 const video = data[0]
136 136
137 await completeVideoCheck(server, video, checkAttributes) 137 await completeVideoCheck({ server, originServer: servers[0], videoUUID: video.uuid, attributes: checkAttributes })
138 publishedAt = video.publishedAt as string 138 publishedAt = video.publishedAt as string
139 139
140 expect(video.channel.avatars).to.have.lengthOf(2) 140 expect(video.channel.avatars).to.have.lengthOf(2)
@@ -238,7 +238,7 @@ describe('Test multiple servers', function () {
238 expect(data.length).to.equal(2) 238 expect(data.length).to.equal(2)
239 const video = data[1] 239 const video = data[1]
240 240
241 await completeVideoCheck(server, video, checkAttributes) 241 await completeVideoCheck({ server, originServer: servers[1], videoUUID: video.uuid, attributes: checkAttributes })
242 } 242 }
243 }) 243 })
244 244
@@ -328,7 +328,7 @@ describe('Test multiple servers', function () {
328 } 328 }
329 ] 329 ]
330 } 330 }
331 await completeVideoCheck(server, video1, checkAttributesVideo1) 331 await completeVideoCheck({ server, originServer: servers[2], videoUUID: video1.uuid, attributes: checkAttributesVideo1 })
332 332
333 const checkAttributesVideo2 = { 333 const checkAttributesVideo2 = {
334 name: 'my super name for server 3-2', 334 name: 'my super name for server 3-2',
@@ -362,7 +362,7 @@ describe('Test multiple servers', function () {
362 } 362 }
363 ] 363 ]
364 } 364 }
365 await completeVideoCheck(server, video2, checkAttributesVideo2) 365 await completeVideoCheck({ server, originServer: servers[2], videoUUID: video2.uuid, attributes: checkAttributesVideo2 })
366 } 366 }
367 }) 367 })
368 }) 368 })
@@ -408,10 +408,8 @@ describe('Test multiple servers', function () {
408 toRemove.push(data[3]) 408 toRemove.push(data[3])
409 409
410 const videoDetails = await servers[2].videos.get({ id: video.id }) 410 const videoDetails = await servers[2].videos.get({ id: video.id })
411 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) 411
412 expect(torrent.files).to.be.an('array') 412 await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
413 expect(torrent.files.length).to.equal(1)
414 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
415 }) 413 })
416 414
417 it('Should add the file 2 by asking server 1', async function () { 415 it('Should add the file 2 by asking server 1', async function () {
@@ -422,10 +420,7 @@ describe('Test multiple servers', function () {
422 const video = data[1] 420 const video = data[1]
423 const videoDetails = await servers[0].videos.get({ id: video.id }) 421 const videoDetails = await servers[0].videos.get({ id: video.id })
424 422
425 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) 423 await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
426 expect(torrent.files).to.be.an('array')
427 expect(torrent.files.length).to.equal(1)
428 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
429 }) 424 })
430 425
431 it('Should add the file 3 by asking server 2', async function () { 426 it('Should add the file 3 by asking server 2', async function () {
@@ -436,10 +431,7 @@ describe('Test multiple servers', function () {
436 const video = data[2] 431 const video = data[2]
437 const videoDetails = await servers[1].videos.get({ id: video.id }) 432 const videoDetails = await servers[1].videos.get({ id: video.id })
438 433
439 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri, true) 434 await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
440 expect(torrent.files).to.be.an('array')
441 expect(torrent.files.length).to.equal(1)
442 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
443 }) 435 })
444 436
445 it('Should add the file 3-2 by asking server 1', async function () { 437 it('Should add the file 3-2 by asking server 1', async function () {
@@ -450,10 +442,7 @@ describe('Test multiple servers', function () {
450 const video = data[3] 442 const video = data[3]
451 const videoDetails = await servers[0].videos.get({ id: video.id }) 443 const videoDetails = await servers[0].videos.get({ id: video.id })
452 444
453 const torrent = await webtorrentAdd(videoDetails.files[0].magnetUri) 445 await checkWebTorrentWorks(videoDetails.files[0].magnetUri)
454 expect(torrent.files).to.be.an('array')
455 expect(torrent.files.length).to.equal(1)
456 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
457 }) 446 })
458 447
459 it('Should add the file 2 in 360p by asking server 1', async function () { 448 it('Should add the file 2 in 360p by asking server 1', async function () {
@@ -467,10 +456,7 @@ describe('Test multiple servers', function () {
467 const file = videoDetails.files.find(f => f.resolution.id === 360) 456 const file = videoDetails.files.find(f => f.resolution.id === 360)
468 expect(file).not.to.be.undefined 457 expect(file).not.to.be.undefined
469 458
470 const torrent = await webtorrentAdd(file.magnetUri) 459 await checkWebTorrentWorks(file.magnetUri)
471 expect(torrent.files).to.be.an('array')
472 expect(torrent.files.length).to.equal(1)
473 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
474 }) 460 })
475 }) 461 })
476 462
@@ -685,7 +671,7 @@ describe('Test multiple servers', function () {
685 thumbnailfile: 'thumbnail', 671 thumbnailfile: 'thumbnail',
686 previewfile: 'preview' 672 previewfile: 'preview'
687 } 673 }
688 await completeVideoCheck(server, videoUpdated, checkAttributes) 674 await completeVideoCheck({ server, originServer: servers[2], videoUUID: videoUpdated.uuid, attributes: checkAttributes })
689 } 675 }
690 }) 676 })
691 677
@@ -1087,7 +1073,7 @@ describe('Test multiple servers', function () {
1087 } 1073 }
1088 ] 1074 ]
1089 } 1075 }
1090 await completeVideoCheck(server, video, checkAttributes) 1076 await completeVideoCheck({ server, originServer: servers[1], videoUUID: video.uuid, attributes: checkAttributes })
1091 } 1077 }
1092 }) 1078 })
1093 }) 1079 })
diff --git a/server/tests/api/videos/resumable-upload.ts b/server/tests/api/videos/resumable-upload.ts
index 0cf1e6675..a70a7258b 100644
--- a/server/tests/api/videos/resumable-upload.ts
+++ b/server/tests/api/videos/resumable-upload.ts
@@ -261,7 +261,7 @@ describe('Test resumable upload', function () {
261 pathUploadId: uploadId, 261 pathUploadId: uploadId,
262 token: server.accessToken, 262 token: server.accessToken,
263 digestBuilder: () => 'sha=' + 'a'.repeat(40), 263 digestBuilder: () => 'sha=' + 'a'.repeat(40),
264 expectedStatus: 460 264 expectedStatus: 460 as any
265 }) 265 })
266 }) 266 })
267 267
diff --git a/server/tests/api/videos/single-server.ts b/server/tests/api/videos/single-server.ts
index e8e981e55..72f833ec2 100644
--- a/server/tests/api/videos/single-server.ts
+++ b/server/tests/api/videos/single-server.ts
@@ -164,14 +164,14 @@ describe('Test a single server', function () {
164 expect(data.length).to.equal(1) 164 expect(data.length).to.equal(1)
165 165
166 const video = data[0] 166 const video = data[0]
167 await completeVideoCheck(server, video, getCheckAttributes()) 167 await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: getCheckAttributes() })
168 }) 168 })
169 169
170 it('Should get the video by UUID', async function () { 170 it('Should get the video by UUID', async function () {
171 this.timeout(5000) 171 this.timeout(5000)
172 172
173 const video = await server.videos.get({ id: videoUUID }) 173 const video = await server.videos.get({ id: videoUUID })
174 await completeVideoCheck(server, video, getCheckAttributes()) 174 await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: getCheckAttributes() })
175 }) 175 })
176 176
177 it('Should have the views updated', async function () { 177 it('Should have the views updated', async function () {
@@ -360,7 +360,7 @@ describe('Test a single server', function () {
360 360
361 const video = await server.videos.get({ id: videoId }) 361 const video = await server.videos.get({ id: videoId })
362 362
363 await completeVideoCheck(server, video, updateCheckAttributes()) 363 await completeVideoCheck({ server, originServer: server, videoUUID: video.uuid, attributes: updateCheckAttributes() })
364 }) 364 })
365 365
366 it('Should update only the tags of a video', async function () { 366 it('Should update only the tags of a video', async function () {
@@ -371,7 +371,12 @@ describe('Test a single server', function () {
371 371
372 const video = await server.videos.get({ id: videoId }) 372 const video = await server.videos.get({ id: videoId })
373 373
374 await completeVideoCheck(server, video, Object.assign(updateCheckAttributes(), attributes)) 374 await completeVideoCheck({
375 server,
376 originServer: server,
377 videoUUID: video.uuid,
378 attributes: Object.assign(updateCheckAttributes(), attributes)
379 })
375 }) 380 })
376 381
377 it('Should update only the description of a video', async function () { 382 it('Should update only the description of a video', async function () {
@@ -382,8 +387,12 @@ describe('Test a single server', function () {
382 387
383 const video = await server.videos.get({ id: videoId }) 388 const video = await server.videos.get({ id: videoId })
384 389
385 const expectedAttributes = Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes) 390 await completeVideoCheck({
386 await completeVideoCheck(server, video, expectedAttributes) 391 server,
392 originServer: server,
393 videoUUID: video.uuid,
394 attributes: Object.assign(updateCheckAttributes(), { tags: [ 'supertag', 'tag1', 'tag2' ] }, attributes)
395 })
387 }) 396 })
388 397
389 it('Should like a video', async function () { 398 it('Should like a video', async function () {
diff --git a/server/tests/api/videos/video-channel-syncs.ts b/server/tests/api/videos/video-channel-syncs.ts
index dd483f95e..a31e48d1d 100644
--- a/server/tests/api/videos/video-channel-syncs.ts
+++ b/server/tests/api/videos/video-channel-syncs.ts
@@ -1,7 +1,7 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { FIXTURE_URLS } from '@server/tests/shared' 4import { FIXTURE_URLS, SQLCommand } from '@server/tests/shared'
5import { areHttpImportTestsDisabled } from '@shared/core-utils' 5import { areHttpImportTestsDisabled } from '@shared/core-utils'
6import { VideoChannelSyncState, VideoInclude, VideoPrivacy } from '@shared/models' 6import { VideoChannelSyncState, VideoInclude, VideoPrivacy } from '@shared/models'
7import { 7import {
@@ -23,6 +23,7 @@ describe('Test channel synchronizations', function () {
23 23
24 describe('Sync using ' + mode, function () { 24 describe('Sync using ' + mode, function () {
25 let servers: PeerTubeServer[] 25 let servers: PeerTubeServer[]
26 let sqlCommands: SQLCommand[]
26 27
27 let startTestDate: Date 28 let startTestDate: Date
28 29
@@ -36,7 +37,7 @@ describe('Test channel synchronizations', function () {
36 } 37 }
37 38
38 async function changeDateForSync (channelSyncId: number, newDate: string) { 39 async function changeDateForSync (channelSyncId: number, newDate: string) {
39 await servers[0].sql.updateQuery( 40 await sqlCommands[0].updateQuery(
40 `UPDATE "videoChannelSync" ` + 41 `UPDATE "videoChannelSync" ` +
41 `SET "createdAt"='${newDate}', "lastSyncAt"='${newDate}' ` + 42 `SET "createdAt"='${newDate}', "lastSyncAt"='${newDate}' ` +
42 `WHERE id=${channelSyncId}` 43 `WHERE id=${channelSyncId}`
@@ -82,6 +83,8 @@ describe('Test channel synchronizations', function () {
82 const { videoChannels } = await servers[0].users.getMyInfo({ token: userInfo.accessToken }) 83 const { videoChannels } = await servers[0].users.getMyInfo({ token: userInfo.accessToken })
83 userInfo.channelId = videoChannels[0].id 84 userInfo.channelId = videoChannels[0].id
84 } 85 }
86
87 sqlCommands = servers.map(s => new SQLCommand(s))
85 }) 88 })
86 89
87 it('Should fetch the latest channel videos of a remote channel', async function () { 90 it('Should fetch the latest channel videos of a remote channel', async function () {
@@ -302,6 +305,10 @@ describe('Test channel synchronizations', function () {
302 }) 305 })
303 306
304 after(async function () { 307 after(async function () {
308 for (const sqlCommand of sqlCommands) {
309 await sqlCommand.cleanup()
310 }
311
305 await killallServers(servers) 312 await killallServers(servers)
306 }) 313 })
307 }) 314 })
diff --git a/server/tests/api/videos/video-channels.ts b/server/tests/api/videos/video-channels.ts
index 64bd4d9ae..c82ad6f16 100644
--- a/server/tests/api/videos/video-channels.ts
+++ b/server/tests/api/videos/video-channels.ts
@@ -3,7 +3,7 @@
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { basename } from 'path' 4import { basename } from 'path'
5import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants' 5import { ACTOR_IMAGES_SIZE } from '@server/initializers/constants'
6import { testFileExistsOrNot, testImage } from '@server/tests/shared' 6import { SQLCommand, testFileExistsOrNot, testImage } from '@server/tests/shared'
7import { wait } from '@shared/core-utils' 7import { wait } from '@shared/core-utils'
8import { ActorImageType, User, VideoChannel } from '@shared/models' 8import { ActorImageType, User, VideoChannel } from '@shared/models'
9import { 9import {
@@ -25,6 +25,8 @@ async function findChannel (server: PeerTubeServer, channelId: number) {
25 25
26describe('Test video channels', function () { 26describe('Test video channels', function () {
27 let servers: PeerTubeServer[] 27 let servers: PeerTubeServer[]
28 let sqlCommands: SQLCommand[]
29
28 let userInfo: User 30 let userInfo: User
29 let secondVideoChannelId: number 31 let secondVideoChannelId: number
30 let totoChannel: number 32 let totoChannel: number
@@ -45,6 +47,8 @@ describe('Test video channels', function () {
45 await setDefaultAccountAvatar(servers) 47 await setDefaultAccountAvatar(servers)
46 48
47 await doubleFollow(servers[0], servers[1]) 49 await doubleFollow(servers[0], servers[1])
50
51 sqlCommands = servers.map(s => new SQLCommand(s))
48 }) 52 })
49 53
50 it('Should have one video channel (created with root)', async () => { 54 it('Should have one video channel (created with root)', async () => {
@@ -278,7 +282,9 @@ describe('Test video channels', function () {
278 282
279 await waitJobs(servers) 283 await waitJobs(servers)
280 284
281 for (const server of servers) { 285 for (let i = 0; i < servers.length; i++) {
286 const server = servers[i]
287
282 const videoChannel = await findChannel(server, secondVideoChannelId) 288 const videoChannel = await findChannel(server, secondVideoChannelId)
283 const expectedSizes = ACTOR_IMAGES_SIZE[ActorImageType.AVATAR] 289 const expectedSizes = ACTOR_IMAGES_SIZE[ActorImageType.AVATAR]
284 290
@@ -289,7 +295,7 @@ describe('Test video channels', function () {
289 await testImage(server.url, `avatar-resized-${avatar.width}x${avatar.width}`, avatarPaths[server.port], '.png') 295 await testImage(server.url, `avatar-resized-${avatar.width}x${avatar.width}`, avatarPaths[server.port], '.png')
290 await testFileExistsOrNot(server, 'avatars', basename(avatarPaths[server.port]), true) 296 await testFileExistsOrNot(server, 'avatars', basename(avatarPaths[server.port]), true)
291 297
292 const row = await server.sql.getActorImage(basename(avatarPaths[server.port])) 298 const row = await sqlCommands[i].getActorImage(basename(avatarPaths[server.port]))
293 299
294 expect(expectedSizes.some(({ height, width }) => row.height === height && row.width === width)).to.equal(true) 300 expect(expectedSizes.some(({ height, width }) => row.height === height && row.width === width)).to.equal(true)
295 } 301 }
@@ -309,14 +315,16 @@ describe('Test video channels', function () {
309 315
310 await waitJobs(servers) 316 await waitJobs(servers)
311 317
312 for (const server of servers) { 318 for (let i = 0; i < servers.length; i++) {
319 const server = servers[i]
320
313 const videoChannel = await server.channels.get({ channelName: 'second_video_channel@' + servers[0].host }) 321 const videoChannel = await server.channels.get({ channelName: 'second_video_channel@' + servers[0].host })
314 322
315 bannerPaths[server.port] = videoChannel.banners[0].path 323 bannerPaths[server.port] = videoChannel.banners[0].path
316 await testImage(server.url, 'banner-resized', bannerPaths[server.port]) 324 await testImage(server.url, 'banner-resized', bannerPaths[server.port])
317 await testFileExistsOrNot(server, 'avatars', basename(bannerPaths[server.port]), true) 325 await testFileExistsOrNot(server, 'avatars', basename(bannerPaths[server.port]), true)
318 326
319 const row = await server.sql.getActorImage(basename(bannerPaths[server.port])) 327 const row = await sqlCommands[i].getActorImage(basename(bannerPaths[server.port]))
320 expect(row.height).to.equal(ACTOR_IMAGES_SIZE[ActorImageType.BANNER][0].height) 328 expect(row.height).to.equal(ACTOR_IMAGES_SIZE[ActorImageType.BANNER][0].height)
321 expect(row.width).to.equal(ACTOR_IMAGES_SIZE[ActorImageType.BANNER][0].width) 329 expect(row.width).to.equal(ACTOR_IMAGES_SIZE[ActorImageType.BANNER][0].width)
322 } 330 }
@@ -546,6 +554,10 @@ describe('Test video channels', function () {
546 }) 554 })
547 555
548 after(async function () { 556 after(async function () {
557 for (const sqlCommand of sqlCommands) {
558 await sqlCommand.cleanup()
559 }
560
549 await cleanupTests(servers) 561 await cleanupTests(servers)
550 }) 562 })
551}) 563})
diff --git a/server/tests/api/videos/video-static-file-privacy.ts b/server/tests/api/videos/video-static-file-privacy.ts
index 2dcfbbc57..542848533 100644
--- a/server/tests/api/videos/video-static-file-privacy.ts
+++ b/server/tests/api/videos/video-static-file-privacy.ts
@@ -2,7 +2,7 @@
2 2
3import { expect } from 'chai' 3import { expect } from 'chai'
4import { decode } from 'magnet-uri' 4import { decode } from 'magnet-uri'
5import { checkVideoFileTokenReinjection, expectStartWith } from '@server/tests/shared' 5import { checkVideoFileTokenReinjection, expectStartWith, parseTorrentVideo } from '@server/tests/shared'
6import { getAllFiles, wait } from '@shared/core-utils' 6import { getAllFiles, wait } from '@shared/core-utils'
7import { HttpStatusCode, LiveVideo, VideoDetails, VideoPrivacy } from '@shared/models' 7import { HttpStatusCode, LiveVideo, VideoDetails, VideoPrivacy } from '@shared/models'
8import { 8import {
@@ -10,7 +10,6 @@ import {
10 createSingleServer, 10 createSingleServer,
11 findExternalSavedVideo, 11 findExternalSavedVideo,
12 makeRawRequest, 12 makeRawRequest,
13 parseTorrentVideo,
14 PeerTubeServer, 13 PeerTubeServer,
15 sendRTMPStream, 14 sendRTMPStream,
16 setAccessTokensToServers, 15 setAccessTokensToServers,