Files
privacy.sexy/tests/unit/shared/Stubs/CategoryCollectionParserStub.ts
undergroundwires 48d6dbd700 Refactor to use string IDs for executables #262
This commit unifies the concepts of executables having same ID
structure. It paves the way for more complex ID structure and using IDs
in collection files as part of new ID solution (#262). Using string IDs
also leads to more expressive test code.

This commit also refactors the rest of the code to adopt to the changes.

This commit:

- Separate concerns from entities for data access (in repositories) and
  executables. Executables use `Identifiable` meanwhile repositories use
  `RepositoryEntity`.
- Refactor unnecessary generic parameters for enttities and ids,
  enforcing string gtype everwyhere.
- Changes numeric IDs to string IDs for categories to unify the
  retrieval and construction for executables, using pseudo-ids (their
  names) just like scripts.
- Remove `BaseEntity` for simplicity.
- Simplify usage and construction of executable objects.
  Move factories responsible for creation of category/scripts to domain
  layer. Do not longer export `CollectionCategorY` and
  `CollectionScript`.
- Use named typed for string IDs for better differentation of different
  ID contexts in code.
2024-07-08 23:23:05 +02:00

41 lines
1.5 KiB
TypeScript

import type { ProjectDetails } from '@/domain/Project/ProjectDetails';
import type { ICategoryCollection } from '@/domain/Collection/ICategoryCollection';
import { getEnumValues } from '@/application/Common/Enum';
import type { CollectionData } from '@/application/collections/';
import { OperatingSystem } from '@/domain/OperatingSystem';
import type { CategoryCollectionParser } from '@/application/Parser/CategoryCollectionParser';
import { CategoryCollectionStub } from './CategoryCollectionStub';
export class CategoryCollectionParserStub {
public readonly arguments = new Array<{
data: CollectionData,
projectDetails: ProjectDetails,
}>();
private readonly returnValues = new Map<CollectionData, ICategoryCollection>();
public withReturnValue(
data: CollectionData,
collection: ICategoryCollection,
): this {
this.returnValues.set(data, collection);
return this;
}
public getStub(): CategoryCollectionParser {
return (data: CollectionData, projectDetails: ProjectDetails): ICategoryCollection => {
this.arguments.push({ data, projectDetails });
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);
};
}
}