mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-17 02:37:33 +00:00
test: guard synology chat mock calls
This commit is contained in:
@@ -35,6 +35,18 @@ function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function requireMockCall<TArgs extends unknown[]>(
|
||||
mock: { mock: { calls: TArgs[] } },
|
||||
index: number,
|
||||
label: string,
|
||||
): TArgs {
|
||||
const call = mock.mock.calls[index];
|
||||
if (!call) {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
||||
describe("Synology channel wiring integration", () => {
|
||||
beforeAll(async () => {
|
||||
({ createSynologyChatPlugin } = await import("./channel.js"));
|
||||
@@ -143,11 +155,8 @@ describe("Synology channel wiring integration", () => {
|
||||
);
|
||||
|
||||
expect(registerPluginHttpRouteMock).toHaveBeenCalledTimes(2);
|
||||
const alphaRoute = registerPluginHttpRouteMock.mock.calls[0]?.[0];
|
||||
const betaRoute = registerPluginHttpRouteMock.mock.calls[1]?.[0];
|
||||
if (!alphaRoute || !betaRoute) {
|
||||
throw new Error("Expected both Synology Chat routes to register");
|
||||
}
|
||||
const [alphaRoute] = requireMockCall(registerPluginHttpRouteMock, 0, "alpha Synology route");
|
||||
const [betaRoute] = requireMockCall(registerPluginHttpRouteMock, 1, "beta Synology route");
|
||||
|
||||
const alphaReq = makeReq(
|
||||
"POST",
|
||||
@@ -178,8 +187,8 @@ describe("Synology channel wiring integration", () => {
|
||||
expect(dispatchReplyWithBufferedBlockDispatcher).toHaveBeenCalledTimes(2);
|
||||
expect(finalizeInboundContextMock).toHaveBeenCalledTimes(2);
|
||||
|
||||
const alphaCtx = finalizeInboundContextMock.mock.calls[0]?.[0];
|
||||
const betaCtx = finalizeInboundContextMock.mock.calls[1]?.[0];
|
||||
const [alphaCtx] = requireMockCall(finalizeInboundContextMock, 0, "alpha inbound context");
|
||||
const [betaCtx] = requireMockCall(finalizeInboundContextMock, 1, "beta inbound context");
|
||||
const alphaContext = requireRecord(alphaCtx, "alpha inbound context");
|
||||
expect(alphaContext.AccountId).toBe("alpha");
|
||||
expect(alphaContext.SessionKey).toBe("agent:agent-alpha:synology-chat:alpha:direct:123");
|
||||
|
||||
Reference in New Issue
Block a user