Add settings validator unit test #113

Merged
jakob.scheid merged 20 commits from testing/settings-validator into main 2026-06-04 17:48:09 +02:00
2 changed files with 10 additions and 4 deletions
Showing only changes of commit f4121bf419 - Show all commits
@@ -15,7 +15,7 @@ limitations under the License.
*/
import { describe, test, expect } from 'vitest';
import { assertType, assertString } from '../settingsValidator';
import { validateSelectionOptions, assertType, assertString } from '../settingsValidator';
describe('validateSettingsConfig', () => {
@@ -26,7 +26,13 @@ describe('validateEntry', () => {
});
describe('validateSelectionOptions', () => {
test.for([
[[{ name: 'test', i18n: 'test.label' }]],
[[{ name: 'test', i18n: 'test.label' }, { name: 'test2', i18n: 'test2.label' }]],
[[{ name: 'test', i18n: 'test.label' }, { name: 'test', i18n: 'test2.label' }, { name: 'test3', i18n: 'test.label' }]]
])('throws no error for the options %s', ([ options ]) => {
expect(() => validateSelectionOptions(options)).not.throws(Error);
});
});
describe('assertType', () => {
@@ -30,10 +30,10 @@ export const assertType = function assertType (value, path) {
}
}
function validateSelectionOptions(options, path) {
export const validateSelectionOptions = function validateSelectionOptions (options, path) {
if (!Array.isArray(options) || options.length === 0) {
throw new Error(`[settings] "${path}.options" must be a non-empty array`);
}
};
options.forEach((opt, i) => {
assertString(opt.name, `${path}.options[${i}].name`);
assertString(opt.i18n, `${path}.options[${i}].i18n`);