mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2024-11-28 03:23:57 -06:00
Refactor a little bit live tests
This commit is contained in:
parent
bc4c9cc1d7
commit
a1bb73f9b5
@ -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
|
||||
const res = await generateUser(servers[0], 'user1')
|
||||
userId = res.userId
|
||||
userChannelId = res.userChannelId
|
||||
userAccessToken = res.token
|
||||
|
||||
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
|
||||
})
|
||||
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)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
@ -223,6 +223,18 @@ function updateCustomSubConfig (url: string, token: string, newConfig: DeepParti
|
||||
return updateCustomConfig(url, token, updateParams)
|
||||
}
|
||||
|
||||
function getCustomConfigResolutions (enabled: boolean) {
|
||||
return {
|
||||
'240p': enabled,
|
||||
'360p': enabled,
|
||||
'480p': enabled,
|
||||
'720p': enabled,
|
||||
'1080p': enabled,
|
||||
'1440p': enabled,
|
||||
'2160p': enabled
|
||||
}
|
||||
}
|
||||
|
||||
function deleteCustomConfig (url: string, token: string, statusCodeExpected = HttpStatusCode.OK_200) {
|
||||
const path = '/api/v1/config/custom'
|
||||
|
||||
@ -242,5 +254,6 @@ export {
|
||||
updateCustomConfig,
|
||||
getAbout,
|
||||
deleteCustomConfig,
|
||||
updateCustomSubConfig
|
||||
updateCustomSubConfig,
|
||||
getCustomConfigResolutions
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
import { omit } from 'lodash'
|
||||
import * as request from 'supertest'
|
||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||
import { UserUpdateMe } from '../../models/users'
|
||||
import { UserAdminFlag } from '../../models/users/user-flag.model'
|
||||
import { UserRegister } from '../../models/users/user-register.model'
|
||||
@ -7,9 +8,8 @@ import { UserRole } from '../../models/users/user-role'
|
||||
import { makeGetRequest, makePostBodyRequest, makePutBodyRequest, updateImageRequest } from '../requests/requests'
|
||||
import { ServerInfo } from '../server/servers'
|
||||
import { userLogin } from './login'
|
||||
import { HttpStatusCode } from '../../../shared/core-utils/miscs/http-error-codes'
|
||||
|
||||
type CreateUserArgs = {
|
||||
function createUser (parameters: {
|
||||
url: string
|
||||
accessToken: string
|
||||
username: string
|
||||
@ -19,8 +19,7 @@ type CreateUserArgs = {
|
||||
role?: UserRole
|
||||
adminFlags?: UserAdminFlag
|
||||
specialStatus?: number
|
||||
}
|
||||
function createUser (parameters: CreateUserArgs) {
|
||||
}) {
|
||||
const {
|
||||
url,
|
||||
accessToken,
|
||||
@ -52,6 +51,21 @@ function createUser (parameters: CreateUserArgs) {
|
||||
.expect(specialStatus)
|
||||
}
|
||||
|
||||
async function generateUser (server: ServerInfo, username: string) {
|
||||
const password = 'my super password'
|
||||
const resCreate = await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
|
||||
|
||||
const token = await userLogin(server, { username, password })
|
||||
|
||||
const resMe = await getMyUserInformation(server.url, token)
|
||||
|
||||
return {
|
||||
token,
|
||||
userId: resCreate.body.user.id,
|
||||
userChannelId: resMe.body.videoChannels[0].id
|
||||
}
|
||||
}
|
||||
|
||||
async function generateUserAccessToken (server: ServerInfo, username: string) {
|
||||
const password = 'my super password'
|
||||
await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
|
||||
@ -393,6 +407,7 @@ export {
|
||||
resetPassword,
|
||||
renewUserScopedTokens,
|
||||
updateMyAvatar,
|
||||
generateUser,
|
||||
askSendVerifyEmail,
|
||||
generateUserAccessToken,
|
||||
verifyEmail,
|
||||
|
Loading…
Reference in New Issue
Block a user