Files
privacy.sexy/tests/unit/shared/Stubs/CollectionDataStub.ts
undergroundwires dc03bff324 Add schema validation for collection files #369
This commit improves collection file editing and error detection
directly in the IDE. It adds YAML schema, IDE configuration and
automatic tests to validate it.

- Introduce a YAML schema for collection file.
- Use `yaml-language-server` for enhanced YAML support in VSCode.
- Add telemetry disabling in `configure_vscode.py` to respect user
  privacy.
- Add automated checks to validate YAML file structure against the
  schema.
- Remove unused properties and do not allow them in compiler.
2024-06-17 14:01:07 +02:00

64 lines
1.7 KiB
TypeScript

import type {
CategoryData, ScriptData, CollectionData, ScriptingDefinitionData, FunctionData,
} from '@/application/collections/';
import { RecommendationLevel } from '@/domain/Executables/Script/RecommendationLevel';
import { ScriptingLanguage } from '@/domain/ScriptingLanguage';
import { createScriptDataWithCode } from './ScriptDataStub';
export class CollectionDataStub implements CollectionData {
public os = 'windows';
public actions: readonly CategoryData[] = [getCategoryStub()];
public scripting: ScriptingDefinitionData = getTestDefinitionStub();
public functions?: ReadonlyArray<FunctionData>;
public withActions(actions: readonly CategoryData[]): this {
this.actions = actions;
return this;
}
public withOs(os: string): this {
this.os = os;
return this;
}
public withScripting(scripting: ScriptingDefinitionData): this {
this.scripting = scripting;
return this;
}
public withFunctions(functions: ReadonlyArray<FunctionData>) {
this.functions = functions;
return this;
}
}
export function getCategoryStub(scriptPrefix = 'testScript'): CategoryData {
return {
category: 'category name',
children: [
getScriptStub(`${scriptPrefix}-standard`, RecommendationLevel.Standard),
getScriptStub(`${scriptPrefix}-strict`, RecommendationLevel.Strict),
],
};
}
function getTestDefinitionStub(): ScriptingDefinitionData {
return {
language: ScriptingLanguage[ScriptingLanguage.batchfile],
startCode: 'start',
endCode: 'end',
};
}
function getScriptStub(
scriptName: string,
level: RecommendationLevel = RecommendationLevel.Standard,
): ScriptData {
return createScriptDataWithCode()
.withName(scriptName)
.withRecommend(RecommendationLevel[level].toLowerCase());
}