feat(sp25): extend useTailStream dispatch for acks + ta1_acks
The Acks page mounts two streams (useTailStream("acks") and
useTailStream("ta1_acks")) — the dispatcher now routes their item
events into the matching store slices (addAck / addTa1Ack) the same
way the claims / remittances / activity cases already do.
Two new tests assert that an acks item lands in the acks slice (not
in claims) and a ta1_acks item lands in the ta1Acks slice (not in
acks) — i.e. the routing is exclusive, so a payload keyed by id 7
won't bleed across the two ack tables.
This commit is contained in:
@@ -15,7 +15,7 @@ import {
|
|||||||
} from "vitest";
|
} from "vitest";
|
||||||
import { useTailStream } from "./useTailStream";
|
import { useTailStream } from "./useTailStream";
|
||||||
import { useTailStore } from "@/store/tail-store";
|
import { useTailStore } from "@/store/tail-store";
|
||||||
import type { Claim } from "@/types";
|
import type { Ack, Claim, Ta1Ack } from "@/types";
|
||||||
import type { TailEvent } from "@/lib/tail-stream";
|
import type { TailEvent } from "@/lib/tail-stream";
|
||||||
|
|
||||||
// ---------------------------------------------------------------------------
|
// ---------------------------------------------------------------------------
|
||||||
@@ -204,6 +204,34 @@ function makeClaim(id: string, patientName: string): Claim {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function makeAck(id: number, sourceBatchId: string): Ack {
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
sourceBatchId,
|
||||||
|
acceptedCount: 1,
|
||||||
|
rejectedCount: 0,
|
||||||
|
receivedCount: 1,
|
||||||
|
ackCode: "A",
|
||||||
|
parsedAt: "2026-07-02T12:00:00Z",
|
||||||
|
patientControlNumber: `PCN-${id}`,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function makeTa1Ack(id: number, controlNumber: string): Ta1Ack {
|
||||||
|
return {
|
||||||
|
id,
|
||||||
|
controlNumber,
|
||||||
|
ackCode: "A",
|
||||||
|
noteCode: "000",
|
||||||
|
interchangeDate: "2026-07-02",
|
||||||
|
interchangeTime: "1200",
|
||||||
|
senderId: "S",
|
||||||
|
receiverId: "R",
|
||||||
|
sourceBatchId: `TA1-${id}`,
|
||||||
|
parsedAt: "2026-07-02T12:00:00Z",
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
describe("useTailStream", () => {
|
describe("useTailStream", () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockStreamTail.mockReset();
|
mockStreamTail.mockReset();
|
||||||
@@ -212,6 +240,8 @@ describe("useTailStream", () => {
|
|||||||
useTailStore.getState().reset("claims");
|
useTailStore.getState().reset("claims");
|
||||||
useTailStore.getState().reset("remittances");
|
useTailStore.getState().reset("remittances");
|
||||||
useTailStore.getState().reset("activity");
|
useTailStore.getState().reset("activity");
|
||||||
|
useTailStore.getState().reset("acks");
|
||||||
|
useTailStore.getState().reset("ta1_acks");
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
@@ -400,4 +430,60 @@ describe("useTailStream", () => {
|
|||||||
|
|
||||||
unmount();
|
unmount();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
// SP25: the Acks page mounts useTailStream("acks") and
|
||||||
|
// useTailStream("ta1_acks"). The dispatcher must route their item events
|
||||||
|
// into the matching store slices.
|
||||||
|
// -------------------------------------------------------------------------
|
||||||
|
|
||||||
|
it("test_acks_item_event_lands_in_acks_slice", async () => {
|
||||||
|
const { ctrls } = trackCalls();
|
||||||
|
const { unmount } = renderHook(() => useTailStream("acks"));
|
||||||
|
|
||||||
|
await waitFor(() => ctrls.length === 1);
|
||||||
|
ctrls[0].push({ type: "snapshot_end", data: { count: 0 } });
|
||||||
|
await waitFor(() => useTailStore.getState().acks !== undefined);
|
||||||
|
|
||||||
|
ctrls[0].push({
|
||||||
|
type: "item",
|
||||||
|
data: makeAck(42, "BATCH-LIVE"),
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(
|
||||||
|
() => useTailStore.getState().acks["42"] !== undefined,
|
||||||
|
);
|
||||||
|
const stored = useTailStore.getState().acks["42"];
|
||||||
|
expect(stored).toBeDefined();
|
||||||
|
expect(stored?.sourceBatchId).toBe("BATCH-LIVE");
|
||||||
|
// The Acks page must NOT see this row in the claims slice.
|
||||||
|
expect(useTailStore.getState().claims["42"]).toBeUndefined();
|
||||||
|
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
|
|
||||||
|
it("test_ta1_acks_item_event_lands_in_ta1_acks_slice", async () => {
|
||||||
|
const { ctrls } = trackCalls();
|
||||||
|
const { unmount } = renderHook(() => useTailStream("ta1_acks"));
|
||||||
|
|
||||||
|
await waitFor(() => ctrls.length === 1);
|
||||||
|
ctrls[0].push({ type: "snapshot_end", data: { count: 0 } });
|
||||||
|
await waitFor(() => useTailStore.getState().ta1Acks !== undefined);
|
||||||
|
|
||||||
|
ctrls[0].push({
|
||||||
|
type: "item",
|
||||||
|
data: makeTa1Ack(7, "000000007"),
|
||||||
|
});
|
||||||
|
|
||||||
|
await waitFor(
|
||||||
|
() => useTailStore.getState().ta1Acks["7"] !== undefined,
|
||||||
|
);
|
||||||
|
const stored = useTailStore.getState().ta1Acks["7"];
|
||||||
|
expect(stored).toBeDefined();
|
||||||
|
expect(stored?.controlNumber).toBe("000000007");
|
||||||
|
// Must NOT bleed into the acks slice — keyed by id, separate dicts.
|
||||||
|
expect(useTailStore.getState().acks["7"]).toBeUndefined();
|
||||||
|
|
||||||
|
unmount();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -27,7 +27,7 @@
|
|||||||
import { useCallback, useEffect, useRef, useState } from "react";
|
import { useCallback, useEffect, useRef, useState } from "react";
|
||||||
import { streamTail, type TailResource } from "@/lib/tail-stream";
|
import { streamTail, type TailResource } from "@/lib/tail-stream";
|
||||||
import { useTailStore } from "@/store/tail-store";
|
import { useTailStore } from "@/store/tail-store";
|
||||||
import type { Activity, Claim, Remittance } from "@/types";
|
import type { Ack, Activity, Claim, Remittance, Ta1Ack } from "@/types";
|
||||||
|
|
||||||
export type TailStatus =
|
export type TailStatus =
|
||||||
| "connecting"
|
| "connecting"
|
||||||
@@ -74,6 +74,17 @@ function dispatch(resource: TailResource, data: unknown): void {
|
|||||||
case "activity":
|
case "activity":
|
||||||
store.addActivity(data as Activity);
|
store.addActivity(data as Activity);
|
||||||
break;
|
break;
|
||||||
|
// SP25: the Acks page opens two streams — one per ack flavor —
|
||||||
|
// and the live event payloads are the same shape as the list
|
||||||
|
// endpoint (to_ui_ack / to_ui_ta1_ack in store/ui.py). The first
|
||||||
|
// write wins, so a snapshot replay on reconnect won't trample
|
||||||
|
// the canonical row.
|
||||||
|
case "acks":
|
||||||
|
store.addAck(data as Ack);
|
||||||
|
break;
|
||||||
|
case "ta1_acks":
|
||||||
|
store.addTa1Ack(data as Ta1Ack);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user