Files
privacy.sexy/tests/unit/shared/Stubs/CategoryCollectionParserStub.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

42 lines
1.5 KiB
TypeScript

import { IProjectInformation } from '@/domain/IProjectInformation';
import { ProjectInformation } from '@/domain/ProjectInformation';
import { ICategoryCollection } from '@/domain/ICategoryCollection';
import { getEnumValues } from '@/application/Common/Enum';
import type { CollectionData } from '@/application/collections/';
import { CategoryCollectionParserType } from '@/application/Parser/ApplicationParser';
import { OperatingSystem } from '@/domain/OperatingSystem';
import { CategoryCollectionStub } from './CategoryCollectionStub';
export class CategoryCollectionParserStub {
public readonly arguments = new Array<{
data: CollectionData,
info: ProjectInformation,
}>();
private readonly returnValues = new Map<CollectionData, ICategoryCollection>();
public withReturnValue(
data: CollectionData,
collection: ICategoryCollection,
): this {
this.returnValues.set(data, collection);
return this;
}
public getStub(): CategoryCollectionParserType {
return (data: CollectionData, info: IProjectInformation): ICategoryCollection => {
this.arguments.push({ data, info });
const foundReturnValue = this.returnValues.get(data);
if (foundReturnValue) {
return foundReturnValue;
}
// Get next OS with a unique OS so mock does not result in an invalid app due to duplicated OS
// collections.
const currentRun = this.arguments.length - 1;
const nextOs = getEnumValues(OperatingSystem)[currentRun];
return new CategoryCollectionStub()
.withOs(nextOs);
};
}
}