mirror of
https://github.com/Chocobozzz/PeerTube.git
synced 2025-12-05 01:10:36 +00:00
fix(config): Browse Videos custom config validation errors have missing details (#7302)
* test(config): add assertions for Browse Videos default sort validation errors * fix(config): fix Browse Videos default sort t function interpolation * style(config): fix eslint errors in config 'Browse videos section' tests * test(config): add assertion for config Browse Videos default scope validation error * fix(config): fix Browse Videos default scope t function interpolation
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
|
||||
import { expect } from 'chai'
|
||||
import { omit } from '@peertube/peertube-core-utils'
|
||||
import { ActorImageType, CustomConfig, HttpStatusCode, LogoType } from '@peertube/peertube-models'
|
||||
import { buildAbsoluteFixturePath } from '@peertube/peertube-node-utils'
|
||||
@@ -232,13 +233,18 @@ describe('Test config API validators', function () {
|
||||
}
|
||||
})
|
||||
|
||||
await makePutBodyRequest({
|
||||
const response = await makePutBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
fields: newUpdateParams,
|
||||
token: server.accessToken,
|
||||
expectedStatus: HttpStatusCode.BAD_REQUEST_400
|
||||
})
|
||||
|
||||
expect(response.body.detail).to.equal(
|
||||
'Browse videos default sort should be -publishedAt or -originallyPublishedAt ' +
|
||||
'or name or -trending or -hot or -likes or -views, instead of hello'
|
||||
)
|
||||
})
|
||||
|
||||
it('Should fail with a trending default sort & disabled trending algorithm', async function () {
|
||||
@@ -257,13 +263,18 @@ describe('Test config API validators', function () {
|
||||
}
|
||||
})
|
||||
|
||||
await makePutBodyRequest({
|
||||
const response = await makePutBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
fields: newUpdateParams,
|
||||
token: server.accessToken,
|
||||
expectedStatus: HttpStatusCode.BAD_REQUEST_400
|
||||
})
|
||||
|
||||
expect(response.body.detail).to.equal(
|
||||
'Trending videos algorithm most-viewed should be enabled ' +
|
||||
'if browse videos default sort is -trending'
|
||||
)
|
||||
})
|
||||
|
||||
it('Should fail with an invalid default scope', async function () {
|
||||
@@ -275,13 +286,17 @@ describe('Test config API validators', function () {
|
||||
}
|
||||
})
|
||||
|
||||
await makePutBodyRequest({
|
||||
const response = await makePutBodyRequest({
|
||||
url: server.url,
|
||||
path,
|
||||
fields: newUpdateParams,
|
||||
token: server.accessToken,
|
||||
expectedStatus: HttpStatusCode.BAD_REQUEST_400
|
||||
})
|
||||
|
||||
expect(response.body.detail).to.equal(
|
||||
'Browse videos default scope should be local or federated, instead of hello'
|
||||
)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
@@ -4,14 +4,14 @@ export function getBrowseVideosDefaultSortError (value: string, enabledTrendingA
|
||||
const availableOptions = [ '-publishedAt', '-originallyPublishedAt', 'name', '-trending', '-hot', '-likes', '-views' ]
|
||||
|
||||
if (availableOptions.includes(value) === false) {
|
||||
const options = availableOptions.join('\' or \'')
|
||||
const options = availableOptions.join(' or ')
|
||||
|
||||
// Only use `t` if language is provided, because i18n might not be initialized yet and can return `undefined`
|
||||
if (language) {
|
||||
return t(`Browse videos default sort should be {options}, instead of {value}`, language, { options, value })
|
||||
return t('Browse videos default sort should be {options}, instead of {value}', language, { options, value })
|
||||
}
|
||||
|
||||
return `Browse videos default sort should be '${options}', instead of '${value}'`
|
||||
return `Browse videos default sort should be ${options}, instead of ${value}`
|
||||
}
|
||||
|
||||
const trendingSortAlgorithmMap = new Map<string, string>([
|
||||
@@ -24,13 +24,13 @@ export function getBrowseVideosDefaultSortError (value: string, enabledTrendingA
|
||||
if (currentTrendingSortAlgorithm && enabledTrendingAlgorithms.includes(currentTrendingSortAlgorithm) === false) {
|
||||
if (language) {
|
||||
return t(
|
||||
`Trending videos algorithm {currentTrendingSortAlgorithm} should be enabled if browse videos default sort is {value}`,
|
||||
'Trending videos algorithm {currentTrendingSortAlgorithm} should be enabled if browse videos default sort is {value}',
|
||||
language,
|
||||
{ currentTrendingSortAlgorithm, value }
|
||||
)
|
||||
}
|
||||
|
||||
return `Trending videos algorithm '${currentTrendingSortAlgorithm}' should be enabled if browse videos default sort is '${value}'`
|
||||
return `Trending videos algorithm ${currentTrendingSortAlgorithm} should be enabled if browse videos default sort is ${value}`
|
||||
}
|
||||
|
||||
return null
|
||||
@@ -40,13 +40,13 @@ export function getBrowseVideosDefaultScopeError (value: string, language?: stri
|
||||
const availableOptions = [ 'local', 'federated' ]
|
||||
|
||||
if (availableOptions.includes(value) === false) {
|
||||
const options = availableOptions.join('\' or \'')
|
||||
const options = availableOptions.join(' or ')
|
||||
|
||||
if (language) {
|
||||
return t(`Browse videos default scope should be {options}, instead of {value}`, language, { options, value })
|
||||
return t('Browse videos default scope should be {options}, instead of {value}', language, { options, value })
|
||||
}
|
||||
|
||||
return `Browse videos default scope should be '${options}', instead of '${value}'`
|
||||
return `Browse videos default scope should be ${options}, instead of ${value}`
|
||||
}
|
||||
|
||||
return null
|
||||
|
||||
Reference in New Issue
Block a user