mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 15:48:28 +00:00
refactor(test): snapshot telegram action env in e2e suite
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||||
import type { OpenClawConfig } from "../../config/config.js";
|
import type { OpenClawConfig } from "../../config/config.js";
|
||||||
|
import { captureEnv } from "../../test-utils/env.js";
|
||||||
import { handleTelegramAction, readTelegramButtons } from "./telegram-actions.js";
|
import { handleTelegramAction, readTelegramButtons } from "./telegram-actions.js";
|
||||||
|
|
||||||
const reactMessageTelegram = vi.fn(async () => ({ ok: true }));
|
const reactMessageTelegram = vi.fn(async () => ({ ok: true }));
|
||||||
@@ -12,7 +13,7 @@ const sendStickerTelegram = vi.fn(async () => ({
|
|||||||
chatId: "123",
|
chatId: "123",
|
||||||
}));
|
}));
|
||||||
const deleteMessageTelegram = vi.fn(async () => ({ ok: true }));
|
const deleteMessageTelegram = vi.fn(async () => ({ ok: true }));
|
||||||
const originalToken = process.env.TELEGRAM_BOT_TOKEN;
|
let envSnapshot: ReturnType<typeof captureEnv>;
|
||||||
|
|
||||||
vi.mock("../../telegram/send.js", () => ({
|
vi.mock("../../telegram/send.js", () => ({
|
||||||
reactMessageTelegram: (...args: Parameters<typeof reactMessageTelegram>) =>
|
reactMessageTelegram: (...args: Parameters<typeof reactMessageTelegram>) =>
|
||||||
@@ -50,6 +51,7 @@ describe("handleTelegramAction", () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
|
envSnapshot = captureEnv(["TELEGRAM_BOT_TOKEN"]);
|
||||||
reactMessageTelegram.mockClear();
|
reactMessageTelegram.mockClear();
|
||||||
sendMessageTelegram.mockClear();
|
sendMessageTelegram.mockClear();
|
||||||
sendStickerTelegram.mockClear();
|
sendStickerTelegram.mockClear();
|
||||||
@@ -58,11 +60,7 @@ describe("handleTelegramAction", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
afterEach(() => {
|
afterEach(() => {
|
||||||
if (originalToken === undefined) {
|
envSnapshot.restore();
|
||||||
delete process.env.TELEGRAM_BOT_TOKEN;
|
|
||||||
} else {
|
|
||||||
process.env.TELEGRAM_BOT_TOKEN = originalToken;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("adds reactions when reactionLevel is minimal", async () => {
|
it("adds reactions when reactionLevel is minimal", async () => {
|
||||||
|
|||||||
Reference in New Issue
Block a user