From a1bb73f9b591686b2ddfeb3291f305dae9f7fc6c Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 7 May 2021 11:53:46 +0200 Subject: Refactor a little bit live tests --- server/tests/api/live/live-constraints.ts | 70 ++++++++++--------------------- server/tests/api/live/live-permanent.ts | 21 ++-------- server/tests/api/live/live-save-replay.ts | 11 +---- 3 files changed, 27 insertions(+), 75 deletions(-) (limited to 'server') diff --git a/server/tests/api/live/live-constraints.ts b/server/tests/api/live/live-constraints.ts index 5569e6066..cc635de33 100644 --- a/server/tests/api/live/live-constraints.ts +++ b/server/tests/api/live/live-constraints.ts @@ -2,15 +2,15 @@ import 'mocha' import * as chai from 'chai' -import { User, VideoDetails, VideoPrivacy } from '@shared/models' +import { VideoDetails, VideoPrivacy } from '@shared/models' import { checkLiveCleanup, cleanupTests, createLive, - createUser, doubleFollow, flushAndRunMultipleServers, - getMyUserInformation, + generateUser, + getCustomConfigResolutions, getVideo, runAndTestFfmpegStreamError, ServerInfo, @@ -18,7 +18,6 @@ import { setDefaultVideoChannel, updateCustomSubConfig, updateUser, - userLogin, wait, waitJobs, waitUntilLivePublished @@ -62,6 +61,16 @@ describe('Test live constraints', function () { } } + function updateQuota (options: { total: number, daily: number }) { + return updateUser({ + url: servers[0].url, + accessToken: servers[0].accessToken, + userId, + videoQuota: options.total, + videoQuotaDaily: options.daily + }) + } + before(async function () { this.timeout(120000) @@ -82,27 +91,12 @@ describe('Test live constraints', function () { }) { - const user = { username: 'user1', password: 'superpassword' } - const res = await createUser({ - url: servers[0].url, - accessToken: servers[0].accessToken, - username: user.username, - password: user.password - }) - userId = res.body.user.id - - userAccessToken = await userLogin(servers[0], user) - - const resMe = await getMyUserInformation(servers[0].url, userAccessToken) - userChannelId = (resMe.body as User).videoChannels[0].id - - await updateUser({ - url: servers[0].url, - userId, - accessToken: servers[0].accessToken, - videoQuota: 1, - videoQuotaDaily: -1 - }) + const res = await generateUser(servers[0], 'user1') + userId = res.userId + userChannelId = res.userChannelId + userAccessToken = res.token + + await updateQuota({ total: 1, daily: -1 }) } // Server 1 and server 2 follow each other @@ -137,13 +131,7 @@ describe('Test live constraints', function () { // Wait for user quota memoize cache invalidation await wait(5000) - await updateUser({ - url: servers[0].url, - userId, - accessToken: servers[0].accessToken, - videoQuota: -1, - videoQuotaDaily: 1 - }) + await updateQuota({ total: -1, daily: 1 }) const userVideoLiveoId = await createLiveWrapper(true) await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, true) @@ -160,13 +148,7 @@ describe('Test live constraints', function () { // Wait for user quota memoize cache invalidation await wait(5000) - await updateUser({ - url: servers[0].url, - userId, - accessToken: servers[0].accessToken, - videoQuota: 10 * 1000 * 1000, - videoQuotaDaily: -1 - }) + await updateQuota({ total: 10 * 1000 * 1000, daily: -1 }) const userVideoLiveoId = await createLiveWrapper(true) await runAndTestFfmpegStreamError(servers[0].url, userAccessToken, userVideoLiveoId, false) @@ -182,15 +164,7 @@ describe('Test live constraints', function () { maxDuration: 1, transcoding: { enabled: true, - resolutions: { - '240p': true, - '360p': true, - '480p': true, - '720p': true, - '1080p': true, - '1440p': true, - '2160p': true - } + resolutions: getCustomConfigResolutions(true) } } }) diff --git a/server/tests/api/live/live-permanent.ts b/server/tests/api/live/live-permanent.ts index a5bda009f..d52e8c7e4 100644 --- a/server/tests/api/live/live-permanent.ts +++ b/server/tests/api/live/live-permanent.ts @@ -8,6 +8,7 @@ import { createLive, doubleFollow, flushAndRunMultipleServers, + getCustomConfigResolutions, getLive, getPlaylistsCount, getVideo, @@ -69,15 +70,7 @@ describe('Permenant live', function () { maxDuration: -1, transcoding: { enabled: true, - resolutions: { - '240p': true, - '360p': true, - '480p': true, - '720p': true, - '1080p': true, - '1440p': true, - '2160p': true - } + resolutions: getCustomConfigResolutions(true) } } }) @@ -159,15 +152,7 @@ describe('Permenant live', function () { maxDuration: -1, transcoding: { enabled: true, - resolutions: { - '240p': false, - '360p': false, - '480p': false, - '720p': false, - '1080p': false, - '1440p': false, - '2160p': false - } + resolutions: getCustomConfigResolutions(false) } } }) diff --git a/server/tests/api/live/live-save-replay.ts b/server/tests/api/live/live-save-replay.ts index 61c8e74dd..3d4736c8f 100644 --- a/server/tests/api/live/live-save-replay.ts +++ b/server/tests/api/live/live-save-replay.ts @@ -12,6 +12,7 @@ import { createLive, doubleFollow, flushAndRunMultipleServers, + getCustomConfigResolutions, getVideo, getVideosList, removeVideo, @@ -108,15 +109,7 @@ describe('Save replay setting', function () { maxDuration: -1, transcoding: { enabled: false, - resolutions: { - '240p': true, - '360p': true, - '480p': true, - '720p': true, - '1080p': true, - '1440p': true, - '2160p': true - } + resolutions: getCustomConfigResolutions(true) } } }) -- cgit v1.2.3