Files
privacy.sexy/tests/unit/shared/Stubs/CodeValidatorStub.ts
undergroundwires c138f74460 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.
2024-06-12 12:36:40 +02:00

35 lines
1.2 KiB
TypeScript

import { expect } from 'vitest';
import type { Constructible } from '@/TypeHelpers';
import type { ICodeValidationRule } from '@/application/Parser/Executable/Script/Validation/ICodeValidationRule';
import type { ICodeValidator } from '@/application/Parser/Executable/Script/Validation/ICodeValidator';
export class CodeValidatorStub implements ICodeValidator {
public callHistory = new Array<{
code: string,
rules: readonly ICodeValidationRule[],
}>();
public throwIfInvalid(
code: string,
rules: readonly ICodeValidationRule[],
): void {
this.callHistory.push({
code,
rules: Array.from(rules),
});
}
public assertHistory(expectation: {
validatedCodes: readonly (string | undefined)[],
rules: readonly Constructible<ICodeValidationRule>[],
}) {
expect(this.callHistory).to.have.lengthOf(expectation.validatedCodes.length);
const actualValidatedCodes = this.callHistory.map((args) => args.code);
expect(actualValidatedCodes.sort()).deep.equal([...expectation.validatedCodes].sort());
for (const call of this.callHistory) {
const actualRules = call.rules.map((rule) => rule.constructor);
expect(actualRules.sort()).to.deep.equal([...expectation.rules].sort());
}
}
}