Add object property validation in parser #369
This commit introduces stricter type validation across the application to reject objects with unexpected properties, enhancing the robustness and predictability of data handling. Changes include: - Implement a common utility to validate object types. - Refactor across various parsers and data handlers to utilize the new validations. - Update error messages for better clarity and troubleshooting.
This commit is contained in:
34
tests/unit/shared/Stubs/CategoryParserStub.ts
Normal file
34
tests/unit/shared/Stubs/CategoryParserStub.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import type { CategoryParser } from '@/application/Parser/Executable/CategoryParser';
|
||||
import type { CategoryData } from '@/application/collections/';
|
||||
import type { Category } from '@/domain/Executables/Category/Category';
|
||||
import type { CategoryCollectionSpecificUtilities } from '@/application/Parser/Executable/CategoryCollectionSpecificUtilities';
|
||||
import { CategoryStub } from './CategoryStub';
|
||||
|
||||
export class CategoryParserStub {
|
||||
private configuredParseResults = new Map<CategoryData, Category>();
|
||||
|
||||
private usedUtilities = new Array<CategoryCollectionSpecificUtilities>();
|
||||
|
||||
public get(): CategoryParser {
|
||||
return (category, utilities) => {
|
||||
const result = this.configuredParseResults.get(category);
|
||||
this.usedUtilities.push(utilities);
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
return new CategoryStub(5489);
|
||||
};
|
||||
}
|
||||
|
||||
public withConfiguredParseResult(
|
||||
givenCategory: CategoryData,
|
||||
parsedCategory: Category,
|
||||
): this {
|
||||
this.configuredParseResults.set(givenCategory, parsedCategory);
|
||||
return this;
|
||||
}
|
||||
|
||||
public getUsedUtilities(): readonly CategoryCollectionSpecificUtilities[] {
|
||||
return this.usedUtilities;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user