mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 20:24:33 +00:00
test: migrate suites to e2e coverage layout
This commit is contained in:
@@ -3,6 +3,12 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
const dispatchMock = vi.fn();
|
||||
const readAllowFromMock = vi.fn();
|
||||
|
||||
vi.mock("../auto-reply/dispatch.js", () => ({
|
||||
dispatchInboundMessage: (...args: unknown[]) => dispatchMock(...args),
|
||||
dispatchInboundMessageWithDispatcher: (...args: unknown[]) => dispatchMock(...args),
|
||||
dispatchInboundMessageWithBufferedDispatcher: (...args: unknown[]) => dispatchMock(...args),
|
||||
}));
|
||||
|
||||
vi.mock("../pairing/pairing-store.js", () => ({
|
||||
readChannelAllowFromStore: (...args: unknown[]) => readAllowFromMock(...args),
|
||||
upsertChannelPairingRequest: vi.fn(),
|
||||
@@ -19,10 +25,6 @@ describe("signal event handler sender prefix", () => {
|
||||
|
||||
it("prefixes group bodies with sender label", async () => {
|
||||
let capturedBody = "";
|
||||
const dispatchModule = await import("../auto-reply/dispatch.js");
|
||||
vi.spyOn(dispatchModule, "dispatchInboundMessage").mockImplementation(
|
||||
async (...args: unknown[]) => dispatchMock(...args),
|
||||
);
|
||||
dispatchMock.mockImplementationOnce(async ({ dispatcher, ctx }) => {
|
||||
capturedBody = ctx.Body ?? "";
|
||||
dispatcher.sendFinalReply({ text: "ok" });
|
||||
@@ -2,6 +2,12 @@ import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const sendTypingMock = vi.fn();
|
||||
const sendReadReceiptMock = vi.fn();
|
||||
const dispatchInboundMessageMock = vi.fn(
|
||||
async (params: { replyOptions?: { onReplyStart?: () => void } }) => {
|
||||
await Promise.resolve(params.replyOptions?.onReplyStart?.());
|
||||
return { queuedFinal: false, counts: { tool: 0, block: 0, final: 0 } };
|
||||
},
|
||||
);
|
||||
|
||||
vi.mock("./send.js", () => ({
|
||||
sendMessageSignal: vi.fn(),
|
||||
@@ -9,21 +15,12 @@ vi.mock("./send.js", () => ({
|
||||
sendReadReceiptSignal: (...args: unknown[]) => sendReadReceiptMock(...args),
|
||||
}));
|
||||
|
||||
vi.mock("../auto-reply/dispatch.js", async (importOriginal) => {
|
||||
const actual = await importOriginal<typeof import("../auto-reply/dispatch.js")>();
|
||||
const dispatchInboundMessage = vi.fn(
|
||||
async (params: { replyOptions?: { onReplyStart?: () => void } }) => {
|
||||
await Promise.resolve(params.replyOptions?.onReplyStart?.());
|
||||
return { queuedFinal: false, counts: { tool: 0, block: 0, final: 0 } };
|
||||
},
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
dispatchInboundMessage,
|
||||
dispatchInboundMessageWithDispatcher: dispatchInboundMessage,
|
||||
dispatchInboundMessageWithBufferedDispatcher: dispatchInboundMessage,
|
||||
};
|
||||
});
|
||||
vi.mock("../auto-reply/dispatch.js", () => ({
|
||||
dispatchInboundMessage: (...args: unknown[]) => dispatchInboundMessageMock(...args),
|
||||
dispatchInboundMessageWithDispatcher: (...args: unknown[]) => dispatchInboundMessageMock(...args),
|
||||
dispatchInboundMessageWithBufferedDispatcher: (...args: unknown[]) =>
|
||||
dispatchInboundMessageMock(...args),
|
||||
}));
|
||||
|
||||
vi.mock("../pairing/pairing-store.js", () => ({
|
||||
readChannelAllowFromStore: vi.fn().mockResolvedValue([]),
|
||||
@@ -35,10 +32,10 @@ describe("signal event handler typing + read receipts", () => {
|
||||
vi.useRealTimers();
|
||||
sendTypingMock.mockReset().mockResolvedValue(true);
|
||||
sendReadReceiptMock.mockReset().mockResolvedValue(true);
|
||||
dispatchInboundMessageMock.mockClear();
|
||||
});
|
||||
|
||||
it("sends typing + read receipt for allowed DMs", async () => {
|
||||
vi.resetModules();
|
||||
const { createSignalEventHandler } = await import("./monitor/event-handler.js");
|
||||
const handler = createSignalEventHandler({
|
||||
// oxlint-disable-next-line typescript/no-explicit-any
|
||||
Reference in New Issue
Block a user