mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-09 08:11:09 +00:00
test: speed up cli and command suites
This commit is contained in:
@@ -1,43 +1,56 @@
|
||||
import { Command } from "commander";
|
||||
import { beforeAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { registerPairingCli } from "./pairing-cli.js";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
listChannelPairingRequests: vi.fn(),
|
||||
approveChannelPairingCode: vi.fn(),
|
||||
notifyPairingApproved: vi.fn(),
|
||||
normalizeChannelId: vi.fn((raw: string) => {
|
||||
if (!raw) {
|
||||
return null;
|
||||
}
|
||||
if (raw === "imsg") {
|
||||
return "imessage";
|
||||
}
|
||||
if (["telegram", "discord", "imessage"].includes(raw)) {
|
||||
return raw;
|
||||
}
|
||||
return null;
|
||||
}),
|
||||
getPairingAdapter: vi.fn((channel: string) => ({
|
||||
idLabel: pairingIdLabels[channel] ?? "userId",
|
||||
})),
|
||||
listPairingChannels: vi.fn(() => ["telegram", "discord", "imessage"]),
|
||||
}));
|
||||
|
||||
const {
|
||||
listChannelPairingRequests,
|
||||
approveChannelPairingCode,
|
||||
notifyPairingApproved,
|
||||
normalizeChannelId,
|
||||
getPairingAdapter,
|
||||
listPairingChannels,
|
||||
} = mocks;
|
||||
|
||||
const listChannelPairingRequests = vi.fn();
|
||||
const approveChannelPairingCode = vi.fn();
|
||||
const notifyPairingApproved = vi.fn();
|
||||
const pairingIdLabels: Record<string, string> = {
|
||||
telegram: "telegramUserId",
|
||||
discord: "discordUserId",
|
||||
};
|
||||
const normalizeChannelId = vi.fn((raw: string) => {
|
||||
if (!raw) {
|
||||
return null;
|
||||
}
|
||||
if (raw === "imsg") {
|
||||
return "imessage";
|
||||
}
|
||||
if (["telegram", "discord", "imessage"].includes(raw)) {
|
||||
return raw;
|
||||
}
|
||||
return null;
|
||||
});
|
||||
const getPairingAdapter = vi.fn((channel: string) => ({
|
||||
idLabel: pairingIdLabels[channel] ?? "userId",
|
||||
}));
|
||||
const listPairingChannels = vi.fn(() => ["telegram", "discord", "imessage"]);
|
||||
|
||||
vi.mock("../pairing/pairing-store.js", () => ({
|
||||
listChannelPairingRequests,
|
||||
approveChannelPairingCode,
|
||||
listChannelPairingRequests: mocks.listChannelPairingRequests,
|
||||
approveChannelPairingCode: mocks.approveChannelPairingCode,
|
||||
}));
|
||||
|
||||
vi.mock("../channels/plugins/pairing.js", () => ({
|
||||
listPairingChannels,
|
||||
notifyPairingApproved,
|
||||
getPairingAdapter,
|
||||
listPairingChannels: mocks.listPairingChannels,
|
||||
notifyPairingApproved: mocks.notifyPairingApproved,
|
||||
getPairingAdapter: mocks.getPairingAdapter,
|
||||
}));
|
||||
|
||||
vi.mock("../channels/plugins/index.js", () => ({
|
||||
normalizeChannelId,
|
||||
normalizeChannelId: mocks.normalizeChannelId,
|
||||
}));
|
||||
|
||||
vi.mock("../config/config.js", () => ({
|
||||
@@ -45,13 +58,6 @@ vi.mock("../config/config.js", () => ({
|
||||
}));
|
||||
|
||||
describe("pairing cli", () => {
|
||||
let registerPairingCli: typeof import("./pairing-cli.js").registerPairingCli;
|
||||
|
||||
beforeAll(async () => {
|
||||
vi.resetModules();
|
||||
({ registerPairingCli } = await import("./pairing-cli.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
listChannelPairingRequests.mockClear();
|
||||
listChannelPairingRequests.mockResolvedValue([]);
|
||||
|
||||
Reference in New Issue
Block a user