Refactor to unify scripts/categories as Executable
This commit consolidates scripts and categories under a unified 'Executable' concept. This simplifies the architecture and improves code readability. - Introduce subfolders within `src/domain` to segregate domain elements. - Update class and interface names by removing the 'I' prefix in alignment with new coding standards. - Replace 'Node' with 'Executable' to clarify usage; reserve 'Node' exclusively for the UI's tree component.
This commit is contained in:
57
tests/unit/shared/Stubs/ExecutableValidatorStub.ts
Normal file
57
tests/unit/shared/Stubs/ExecutableValidatorStub.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import type { ExecutableData } from '@/application/collections/';
|
||||
import type { ExecutableValidator, ExecutableValidatorFactory } from '@/application/Parser/Executable/Validation/ExecutableValidator';
|
||||
import { StubWithObservableMethodCalls } from './StubWithObservableMethodCalls';
|
||||
|
||||
export const createExecutableValidatorFactoryStub
|
||||
: ExecutableValidatorFactory = () => new ExecutableValidatorStub();
|
||||
|
||||
export class ExecutableValidatorStub
|
||||
extends StubWithObservableMethodCalls<ExecutableValidator>
|
||||
implements ExecutableValidator {
|
||||
private assertThrowsOnFalseCondition = true;
|
||||
|
||||
public withAssertThrowsOnFalseCondition(enableAssertThrows: boolean): this {
|
||||
this.assertThrowsOnFalseCondition = enableAssertThrows;
|
||||
return this;
|
||||
}
|
||||
|
||||
public assertValidName(nameValue: string): this {
|
||||
this.registerMethodCall({
|
||||
methodName: 'assertValidName',
|
||||
args: [nameValue],
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public assertDefined(data: ExecutableData): this {
|
||||
this.registerMethodCall({
|
||||
methodName: 'assertDefined',
|
||||
args: [data],
|
||||
});
|
||||
return this;
|
||||
}
|
||||
|
||||
public assert(
|
||||
validationPredicate: () => boolean,
|
||||
errorMessage: string,
|
||||
): this {
|
||||
this.registerMethodCall({
|
||||
methodName: 'assert',
|
||||
args: [validationPredicate, errorMessage],
|
||||
});
|
||||
if (this.assertThrowsOnFalseCondition) {
|
||||
if (!validationPredicate()) {
|
||||
throw new Error(`[${ExecutableValidatorStub.name}] Assert validation failed: ${errorMessage}`);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public createContextualErrorMessage(errorMessage: string): string {
|
||||
this.registerMethodCall({
|
||||
methodName: 'createContextualErrorMessage',
|
||||
args: [errorMessage],
|
||||
});
|
||||
return `${ExecutableValidatorStub.name}: ${errorMessage}`;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user