Files
privacy.sexy/tests/unit/shared/Stubs/ScriptStub.ts
undergroundwires 949fac1a7c Refactor to enforce strictNullChecks
This commit applies `strictNullChecks` to the entire codebase to improve
maintainability and type safety. Key changes include:

- Remove some explicit null-checks where unnecessary.
- Add necessary null-checks.
- Refactor static factory functions for a more functional approach.
- Improve some test names and contexts for better debugging.
- Add unit tests for any additional logic introduced.
- Refactor `createPositionFromRegexFullMatch` to its own function as the
  logic is reused.
- Prefer `find` prefix on functions that may return `undefined` and
  `get` prefix for those that always return a value.
2023-11-12 22:54:00 +01:00

57 lines
1.4 KiB
TypeScript

import { BaseEntity } from '@/infrastructure/Entity/BaseEntity';
import { IScript } from '@/domain/IScript';
import { RecommendationLevel } from '@/domain/RecommendationLevel';
import { SelectedScript } from '@/application/Context/State/Selection/SelectedScript';
import { IScriptCode } from '@/domain/IScriptCode';
export class ScriptStub extends BaseEntity<string> implements IScript {
public name = `name${this.id}`;
public code: IScriptCode = {
execute: `REM execute-code (${this.id})`,
revert: `REM revert-code (${this.id})`,
};
public readonly docs = new Array<string>();
public level? = RecommendationLevel.Standard;
constructor(public readonly id: string) {
super(id);
}
public canRevert(): boolean {
return Boolean(this.code.revert);
}
public withLevel(value: RecommendationLevel | undefined): this {
this.level = value;
return this;
}
public withCode(value: string): this {
this.code = {
execute: value,
revert: this.code.revert,
};
return this;
}
public withName(name: string): this {
this.name = name;
return this;
}
public withRevertCode(revertCode?: string): this {
this.code = {
execute: this.code.execute,
revert: revertCode,
};
return this;
}
public toSelectedScript(isReverted = false): SelectedScript {
return new SelectedScript(this, isReverted);
}
}