43 lines
1.4 KiB
TypeScript
43 lines
1.4 KiB
TypeScript
// Local type aliases mirroring exports from `@repo/core-dsr`.
|
|
// Kept inline to avoid a build-graph cycle between core-testing (tooling)
|
|
// and core-dsr (optional core). Same pattern used by RecordingAuditLog,
|
|
// RecordingConsent, and other recording doubles.
|
|
|
|
/** Recorded setRestriction call. */
|
|
export type RecordedRestrictionSet = {
|
|
subjectId: string;
|
|
granted: boolean;
|
|
};
|
|
|
|
/**
|
|
* Test-side recording double for IProcessingRestriction. Records all
|
|
* setRestriction / isRestricted calls for assertion while maintaining the same
|
|
* state semantics as the real impl (isRestricted returns true after
|
|
* setRestriction(true), false after setRestriction(false)).
|
|
*
|
|
* Use directly via constructor injection:
|
|
* const restriction = new RecordingProcessingRestriction();
|
|
* const uc = myUseCase(restriction);
|
|
* await uc({ ... });
|
|
* expect(restriction.sets[0]?.granted).toBe(true);
|
|
* expect(await restriction.isRestricted("alice")).toBe(true);
|
|
*/
|
|
export class RecordingProcessingRestriction {
|
|
public sets: RecordedRestrictionSet[] = [];
|
|
private readonly state = new Map<string, boolean>();
|
|
|
|
async setRestriction(subjectId: string, granted: boolean): Promise<void> {
|
|
this.sets.push({ subjectId, granted });
|
|
this.state.set(subjectId, granted);
|
|
}
|
|
|
|
async isRestricted(subjectId: string): Promise<boolean> {
|
|
return this.state.get(subjectId) ?? false;
|
|
}
|
|
|
|
reset(): void {
|
|
this.sets = [];
|
|
this.state.clear();
|
|
}
|
|
}
|