mirror of
https://github.com/MBombeck/HealthLog.git
synced 2026-11-11 13:52:20 +00:00
MCP `search` and `fetch` link a metric as `/insights?metric=<id>` and a lab value as `/labs?analyte=<name>`. Neither page read its query, so every link opened the overview or the full list. `/insights` now resolves the id server-side, in whichever spelling the result carries (a Coach source key such as `hrv` or `bp`, a signal or metric-status key such as `GRIP_STRENGTH`, a measurement type, or a sub-page slug), and redirects to the metric's page, or to its value list when no page focuses it. An id it cannot place renders the overview as before. `/labs` asks for the newest reading stored under the exact analyte name and opens its marker's page; a name with no reading keeps the list and drops the query.
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
|
|
import {
|
|
analyteFromQuery,
|
|
labHrefForAnalyteReading,
|
|
} from "@/lib/labs/analyte-deep-link";
|
|
import { queryKeys } from "@/lib/query-keys";
|
|
|
|
/**
|
|
* `/labs?analyte=<name>` (MCP deep links) opens the marker page of the newest
|
|
* reading stored under that name, and keeps the list otherwise.
|
|
*/
|
|
describe("labs analyte deep link", () => {
|
|
it("follows a named analyte and ignores an empty or oversized one", () => {
|
|
expect(analyteFromQuery(" Ferritin ")).toBe("Ferritin");
|
|
expect(analyteFromQuery(null)).toBeNull();
|
|
expect(analyteFromQuery(" ")).toBeNull();
|
|
expect(analyteFromQuery("x".repeat(121))).toBeNull();
|
|
});
|
|
|
|
it("opens the marker page of the reading, and nothing without one", () => {
|
|
expect(labHrefForAnalyteReading({ biomarkerId: "bm_1" })).toBe(
|
|
"/labs/bm_1",
|
|
);
|
|
expect(labHrefForAnalyteReading({ biomarkerId: null })).toBeNull();
|
|
expect(labHrefForAnalyteReading(undefined)).toBeNull();
|
|
});
|
|
|
|
it("keeps its read under the lab-results prefix, apart from the list", () => {
|
|
const key = queryKeys.labAnalyteLink("Ferritin");
|
|
expect(key[0]).toBe("lab-results");
|
|
expect(key).not.toEqual(
|
|
queryKeys.labResultsList({
|
|
analyte: "Ferritin",
|
|
panel: undefined,
|
|
from: undefined,
|
|
to: undefined,
|
|
page: 0,
|
|
sortDir: "desc",
|
|
}),
|
|
);
|
|
});
|
|
});
|