Add more and unify tests for absent object cases
- Unify test data for nonexistence of an object/string and collection. - Introduce more test through adding missing test data to existing tests. - Improve logic for checking absence of values to match tests. - Add missing tests for absent value validation. - Update documentation to include shared test functionality.
This commit is contained in:
@@ -23,19 +23,16 @@ export class Application implements IApplication {
|
||||
|
||||
function validateInformation(info: IProjectInformation) {
|
||||
if (!info) {
|
||||
throw new Error('undefined project information');
|
||||
throw new Error('missing project information');
|
||||
}
|
||||
}
|
||||
|
||||
function validateCollections(collections: readonly ICategoryCollection[]) {
|
||||
if (!collections) {
|
||||
throw new Error('undefined collections');
|
||||
}
|
||||
if (collections.length === 0) {
|
||||
throw new Error('no collection in the list');
|
||||
if (!collections || !collections.length) {
|
||||
throw new Error('missing collections');
|
||||
}
|
||||
if (collections.filter((c) => !c).length > 0) {
|
||||
throw new Error('undefined collection in the list');
|
||||
throw new Error('missing collection in the list');
|
||||
}
|
||||
const osList = collections.map((c) => c.os);
|
||||
const duplicates = getDuplicates(osList);
|
||||
|
||||
@@ -37,7 +37,7 @@ function parseScriptsRecursively(category: ICategory): ReadonlyArray<IScript> {
|
||||
|
||||
function validateCategory(category: ICategory) {
|
||||
if (!category.name) {
|
||||
throw new Error('undefined or empty name');
|
||||
throw new Error('missing name');
|
||||
}
|
||||
if (
|
||||
(!category.subCategories || category.subCategories.length === 0)
|
||||
|
||||
@@ -20,7 +20,7 @@ export class CategoryCollection implements ICategoryCollection {
|
||||
public readonly scripting: IScriptingDefinition,
|
||||
) {
|
||||
if (!scripting) {
|
||||
throw new Error('undefined scripting definition');
|
||||
throw new Error('missing scripting definition');
|
||||
}
|
||||
this.queryable = makeQueryable(actions);
|
||||
assertInRange(os, OperatingSystem);
|
||||
@@ -34,12 +34,7 @@ export class CategoryCollection implements ICategoryCollection {
|
||||
}
|
||||
|
||||
public getScriptsByLevel(level: RecommendationLevel): readonly IScript[] {
|
||||
if (level === undefined) {
|
||||
throw new Error('undefined level');
|
||||
}
|
||||
if (!(level in RecommendationLevel)) {
|
||||
throw new Error(`invalid level: ${level}`);
|
||||
}
|
||||
assertInRange(level, RecommendationLevel);
|
||||
return this.queryable.scriptsByLevel.get(level);
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ export class Script extends BaseEntity<string> implements IScript {
|
||||
) {
|
||||
super(name);
|
||||
if (!code) {
|
||||
throw new Error(`undefined code (script: ${name})`);
|
||||
throw new Error(`missing code (script: ${name})`);
|
||||
}
|
||||
validateLevel(level);
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ export class ScriptCode implements IScriptCode {
|
||||
public readonly revert: string,
|
||||
syntax: ILanguageSyntax,
|
||||
) {
|
||||
if (!syntax) { throw new Error('undefined syntax'); }
|
||||
if (!syntax) { throw new Error('missing syntax'); }
|
||||
validateCode(execute, syntax);
|
||||
validateRevertCode(revert, execute, syntax);
|
||||
}
|
||||
@@ -33,7 +33,7 @@ function validateRevertCode(revertCode: string, execute: string, syntax: ILangua
|
||||
|
||||
function validateCode(code: string, syntax: ILanguageSyntax): void {
|
||||
if (!code || code.length === 0) {
|
||||
throw new Error('code is empty or undefined');
|
||||
throw new Error('missing code');
|
||||
}
|
||||
ensureNoEmptyLines(code);
|
||||
ensureCodeHasUniqueLines(code, syntax);
|
||||
|
||||
@@ -28,6 +28,6 @@ function findExtension(language: ScriptingLanguage): string {
|
||||
|
||||
function validateCode(code: string, name: string) {
|
||||
if (!code) {
|
||||
throw new Error(`undefined ${name}`);
|
||||
throw new Error(`missing ${name}`);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user