Adds missing tests for undoUseCase, redoUseCase, and setTempHpUseCase, bringing application layer coverage from ~81% to 97%. Removes autoUpdate from coverage thresholds and sets floors to actual values so they enforce a real minimum. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
77 lines
1.8 KiB
TypeScript
77 lines
1.8 KiB
TypeScript
import type {
|
|
Encounter,
|
|
PlayerCharacter,
|
|
UndoRedoState,
|
|
} from "@initiative/domain";
|
|
import { EMPTY_UNDO_REDO_STATE, isDomainError } from "@initiative/domain";
|
|
import type {
|
|
EncounterStore,
|
|
PlayerCharacterStore,
|
|
UndoRedoStore,
|
|
} from "../ports.js";
|
|
|
|
export function requireSaved<T>(value: T | null): T {
|
|
if (value === null) throw new Error("Expected store.saved to be non-null");
|
|
return value;
|
|
}
|
|
|
|
export function expectSuccess<T>(
|
|
result: T,
|
|
): asserts result is Exclude<T, { kind: "domain-error" }> {
|
|
if (isDomainError(result)) {
|
|
throw new Error(`Expected success, got domain error: ${result.message}`);
|
|
}
|
|
}
|
|
|
|
export function expectError(result: unknown): asserts result is {
|
|
kind: "domain-error";
|
|
code: string;
|
|
message: string;
|
|
} {
|
|
if (!isDomainError(result)) {
|
|
throw new Error("Expected domain error");
|
|
}
|
|
}
|
|
|
|
export function stubEncounterStore(
|
|
initial: Encounter,
|
|
): EncounterStore & { saved: Encounter | null } {
|
|
const stub = {
|
|
saved: null as Encounter | null,
|
|
get: () => initial,
|
|
save: (e: Encounter) => {
|
|
stub.saved = e;
|
|
stub.get = () => e;
|
|
},
|
|
};
|
|
return stub;
|
|
}
|
|
|
|
export function stubPlayerCharacterStore(
|
|
initial: readonly PlayerCharacter[],
|
|
): PlayerCharacterStore & { saved: readonly PlayerCharacter[] | null } {
|
|
const stub = {
|
|
saved: null as readonly PlayerCharacter[] | null,
|
|
getAll: () => [...initial],
|
|
save: (characters: PlayerCharacter[]) => {
|
|
stub.saved = characters;
|
|
stub.getAll = () => [...characters];
|
|
},
|
|
};
|
|
return stub;
|
|
}
|
|
|
|
export function stubUndoRedoStore(
|
|
initial: UndoRedoState = EMPTY_UNDO_REDO_STATE,
|
|
): UndoRedoStore & { saved: UndoRedoState | null } {
|
|
const stub = {
|
|
saved: null as UndoRedoState | null,
|
|
get: () => initial,
|
|
save: (state: UndoRedoState) => {
|
|
stub.saved = state;
|
|
stub.get = () => state;
|
|
},
|
|
};
|
|
return stub;
|
|
}
|