mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-12 06:06:10 +00:00
Reading a document, scanning a lab report and turning a medication description into a schedule follow documentAi, labsOcr and medicationExtract. Unavailable, the action is not offered. With only the document-reading consent missing, the place that reads asks for it and grants exactly that (ai_extraction), nothing wider. Refusals are read by meta.errorCode: a 403 is no longer always called a missing consent, and a spent daily budget no longer shows the rate-limit sentence.
63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import { shouldProbeOcrCapability } from "../use-ocr-extract";
|
|
|
|
describe("shouldProbeOcrCapability", () => {
|
|
it("runs the owner-only capability probe only when the scan control can render", () => {
|
|
const ownerControl = {
|
|
isAuthenticated: true,
|
|
isLoading: false,
|
|
labsEnabled: true,
|
|
mounted: true,
|
|
ownRecord: true,
|
|
labsOcr: { available: true, reason: null, onDeviceAllowed: true },
|
|
} as const;
|
|
|
|
expect(shouldProbeOcrCapability(ownerControl)).toBe(true);
|
|
expect(
|
|
shouldProbeOcrCapability({ ...ownerControl, isAuthenticated: false }),
|
|
).toBe(false);
|
|
expect(
|
|
shouldProbeOcrCapability({ ...ownerControl, ownRecord: false }),
|
|
).toBe(false);
|
|
expect(
|
|
shouldProbeOcrCapability({ ...ownerControl, labsEnabled: false }),
|
|
).toBe(false);
|
|
expect(shouldProbeOcrCapability({ ...ownerControl, mounted: false })).toBe(
|
|
false,
|
|
);
|
|
});
|
|
|
|
it("follows the labsOcr capability: probes when available or when only consent is missing", () => {
|
|
const base = {
|
|
isAuthenticated: true,
|
|
isLoading: false,
|
|
labsEnabled: true,
|
|
mounted: true,
|
|
ownRecord: true,
|
|
};
|
|
const state = (reason: string | null) =>
|
|
({
|
|
available: reason === null,
|
|
reason,
|
|
onDeviceAllowed: false,
|
|
}) as Parameters<typeof shouldProbeOcrCapability>[0]["labsOcr"];
|
|
|
|
// Consent is asked for inside the scan dialog, so the scan stays offered.
|
|
expect(
|
|
shouldProbeOcrCapability({ ...base, labsOcr: state("consent_required") }),
|
|
).toBe(true);
|
|
for (const reason of [
|
|
"operator_disabled",
|
|
"no_provider",
|
|
"module_disabled",
|
|
"not_permitted_for_record",
|
|
"check_failed",
|
|
]) {
|
|
expect(
|
|
shouldProbeOcrCapability({ ...base, labsOcr: state(reason) }),
|
|
).toBe(false);
|
|
}
|
|
});
|
|
});
|