






















@@ -35,6 +35,18 @@ function requireRecord(value: unknown, label: string): Record<string, unknown> {
3535return value as Record<string, unknown>;
3636}
373738+function requireMockCall<TArgs extends unknown[]>(
39+mock: { mock: { calls: TArgs[] } },
40+index: number,
41+label: string,
42+): TArgs {
43+const call = mock.mock.calls[index];
44+if (!call) {
45+throw new Error(`expected ${label}`);
46+}
47+return call;
48+}
49+3850describe("Synology channel wiring integration", () => {
3951beforeAll(async () => {
4052({ createSynologyChatPlugin } = await import("./channel.js"));
@@ -143,11 +155,8 @@ describe("Synology channel wiring integration", () => {
143155);
144156145157expect(registerPluginHttpRouteMock).toHaveBeenCalledTimes(2);
146-const alphaRoute = registerPluginHttpRouteMock.mock.calls[0]?.[0];
147-const betaRoute = registerPluginHttpRouteMock.mock.calls[1]?.[0];
148-if (!alphaRoute || !betaRoute) {
149-throw new Error("Expected both Synology Chat routes to register");
150-}
158+const [alphaRoute] = requireMockCall(registerPluginHttpRouteMock, 0, "alpha Synology route");
159+const [betaRoute] = requireMockCall(registerPluginHttpRouteMock, 1, "beta Synology route");
151160152161const alphaReq = makeReq(
153162"POST",
@@ -178,8 +187,8 @@ describe("Synology channel wiring integration", () => {
178187expect(dispatchReplyWithBufferedBlockDispatcher).toHaveBeenCalledTimes(2);
179188expect(finalizeInboundContextMock).toHaveBeenCalledTimes(2);
180189181-const alphaCtx = finalizeInboundContextMock.mock.calls[0]?.[0];
182-const betaCtx = finalizeInboundContextMock.mock.calls[1]?.[0];
190+const [alphaCtx] = requireMockCall(finalizeInboundContextMock, 0, "alpha inbound context");
191+const [betaCtx] = requireMockCall(finalizeInboundContextMock, 1, "beta inbound context");
183192const alphaContext = requireRecord(alphaCtx, "alpha inbound context");
184193expect(alphaContext.AccountId).toBe("alpha");
185194expect(alphaContext.SessionKey).toBe("agent:agent-alpha:synology-chat:alpha:direct:123");
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。