






















@@ -31,14 +31,41 @@ let getLineRuntimeState: typeof import("./monitor.js").getLineRuntimeState;
3131let clearLineRuntimeStateForTests: typeof import("./monitor.js").clearLineRuntimeStateForTests;
3232let innerLineWebhookHandlerMock: ReturnType<typeof vi.fn<LineNodeWebhookHandler>>;
333334-function requireRegisteredRoute(): { handler: LineNodeWebhookHandler } {
35-const route = registerWebhookTargetWithPluginRouteMock.mock.calls[0]?.[0]?.route as
36-| { handler: LineNodeWebhookHandler }
34+type RegisteredRoute = {
35+accountId?: string;
36+auth?: string;
37+handler?: LineNodeWebhookHandler;
38+path?: string;
39+pluginId?: string;
40+replaceExisting?: boolean;
41+};
42+43+type RegisteredTarget = {
44+accountId?: string;
45+path: string;
46+};
47+48+type WebhookRegistration = {
49+route: RegisteredRoute;
50+target: RegisteredTarget;
51+};
52+53+function requireWebhookRegistration(): WebhookRegistration {
54+const registration = registerWebhookTargetWithPluginRouteMock.mock.calls[0]?.[0] as
55+| WebhookRegistration
3756| undefined;
38-if (!route) {
57+if (!registration) {
58+throw new Error("expected registered LINE webhook target");
59+}
60+return registration;
61+}
62+63+function requireRegisteredRoute(): { handler: LineNodeWebhookHandler } {
64+const route = requireWebhookRegistration().route;
65+if (!route.handler) {
3966throw new Error("expected registered LINE webhook route");
4067}
41-return route;
68+return { handler: route.handler };
4269}
43704471vi.mock("./bot.js", () => ({
@@ -205,9 +232,7 @@ describe("monitorLineProvider lifecycle", () => {
205232});
206233207234expect(registerWebhookTargetWithPluginRouteMock).toHaveBeenCalledTimes(1);
208-expect(registerWebhookTargetWithPluginRouteMock).toHaveBeenCalledWith(
209-expect.objectContaining({ route: expect.objectContaining({ auth: "plugin" }) }),
210-);
235+expect(requireWebhookRegistration().route.auth).toBe("plugin");
211236expect(resolved).toBe(false);
212237213238abort.abort();
@@ -224,19 +249,14 @@ describe("monitorLineProvider lifecycle", () => {
224249runtime: {} as RuntimeEnv,
225250});
226251227-const registration = registerWebhookTargetWithPluginRouteMock.mock.calls[0]?.[0];
228-expect(registration).toEqual(
229-expect.objectContaining({
230-target: expect.objectContaining({ accountId: "work", path: "/line/webhook" }),
231-route: expect.objectContaining({
232-accountId: "work",
233-auth: "plugin",
234-pluginId: "line",
235-}),
236-}),
237-);
238-expect(registration?.route).not.toHaveProperty("path");
239-expect(registration?.route).not.toHaveProperty("replaceExisting");
252+const registration = requireWebhookRegistration();
253+expect(registration.target.accountId).toBe("work");
254+expect(registration.target.path).toBe("/line/webhook");
255+expect(registration.route.accountId).toBe("work");
256+expect(registration.route.auth).toBe("plugin");
257+expect(registration.route.pluginId).toBe("line");
258+expect(registration.route).not.toHaveProperty("path");
259+expect(registration.route).not.toHaveProperty("replaceExisting");
240260monitor.stop();
241261});
242262@@ -289,11 +309,7 @@ describe("monitorLineProvider lifecycle", () => {
289309runtime: {} as RuntimeEnv,
290310});
291311292-expect(getLineRuntimeState("work")).toEqual(
293-expect.objectContaining({
294-running: true,
295-}),
296-);
312+expect(getLineRuntimeState("work")?.running).toBe(true);
297313expect(getLineRuntimeState("default")).toBeUndefined();
298314299315monitor.stop();
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。