mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-24 19:35:28 -06:00
test(gateway): remove cron redaction casts
This commit is contained in:
@@ -23,6 +23,19 @@ vi.mock("../cron/delivery.js", async (importOriginal) => {
|
||||
|
||||
import { dispatchGatewayCronFinishedNotifications } from "./server-cron-notifications.js";
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (!value || typeof value !== "object") {
|
||||
throw new Error(`expected ${label}`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function webhookRequestBody() {
|
||||
const request = requireRecord(mocks.fetchWithSsrFGuard.mock.calls[0]?.[0], "webhook request");
|
||||
const init = requireRecord(request.init, "webhook request init");
|
||||
return JSON.parse(String(init.body));
|
||||
}
|
||||
|
||||
describe("dispatchGatewayCronFinishedNotifications", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
@@ -182,10 +195,7 @@ describe("dispatchGatewayCronFinishedNotifications", () => {
|
||||
});
|
||||
|
||||
await vi.waitFor(() => expect(mocks.fetchWithSsrFGuard).toHaveBeenCalledTimes(1));
|
||||
const [request] = mocks.fetchWithSsrFGuard.mock.calls[0] as unknown as [
|
||||
{ init?: { body?: string } },
|
||||
];
|
||||
const body = JSON.parse(String(request.init?.body));
|
||||
const body = webhookRequestBody();
|
||||
expect(body.summary).toContain("[redacted-url]");
|
||||
expect(body.summary).toContain("[redacted-code]");
|
||||
expect(body.summary).toContain("token=***");
|
||||
@@ -267,10 +277,7 @@ describe("dispatchGatewayCronFinishedNotifications", () => {
|
||||
});
|
||||
|
||||
await vi.waitFor(() => expect(mocks.fetchWithSsrFGuard).toHaveBeenCalledTimes(1));
|
||||
const [request] = mocks.fetchWithSsrFGuard.mock.calls[0] as unknown as [
|
||||
{ init?: { body?: string } },
|
||||
];
|
||||
const body = JSON.parse(String(request.init?.body));
|
||||
const body = webhookRequestBody();
|
||||
expect(body).toMatchObject({
|
||||
action: "finished",
|
||||
jobId: job.id,
|
||||
|
||||
@@ -620,12 +620,10 @@ describe("buildGatewayCronService", () => {
|
||||
runCronChangedMock.mockClear();
|
||||
await state.cron.run(job.id, "force");
|
||||
|
||||
const hookEvents = runCronChangedMock.mock.calls as unknown as Array<
|
||||
[{ action?: string; summary?: string }]
|
||||
>;
|
||||
const event = hookEvents.find(([hookEvent]) => hookEvent.action === "finished")?.[0];
|
||||
expect(event).toBeDefined();
|
||||
const summary = event?.summary ?? "";
|
||||
const event = runCronChangedMock.mock.calls
|
||||
.map((call) => requireRecord(call[0], "cron_changed event"))
|
||||
.find((hookEvent) => hookEvent.action === "finished");
|
||||
const summary = String(event?.summary ?? "");
|
||||
expect(summary).toContain("[redacted-url]");
|
||||
expect(summary).toContain("[redacted-code]");
|
||||
expect(summary).toContain("token=***");
|
||||
@@ -671,10 +669,11 @@ describe("buildGatewayCronService", () => {
|
||||
|
||||
await state.cron.run(job.id, "force");
|
||||
|
||||
const announceCalls = sendCronAnnouncePayloadStrictMock.mock.calls as unknown as Array<
|
||||
[{ message?: string }]
|
||||
>;
|
||||
const message = announceCalls[0]?.[0]?.message ?? "";
|
||||
const announcePayload = requireRecord(
|
||||
callArg(sendCronAnnouncePayloadStrictMock, 0, 0, "cron announce payload"),
|
||||
"cron announce payload",
|
||||
);
|
||||
const message = String(announcePayload.message ?? "");
|
||||
expect(message).toContain("token=***");
|
||||
expect(message).not.toContain("opaque-secret-value");
|
||||
} finally {
|
||||
@@ -714,10 +713,9 @@ describe("buildGatewayCronService", () => {
|
||||
|
||||
expect(sendCronAnnouncePayloadStrictMock).not.toHaveBeenCalled();
|
||||
|
||||
const hookEvents = runCronChangedMock.mock.calls as unknown as Array<
|
||||
[{ action?: string; summary?: string }]
|
||||
>;
|
||||
const event = hookEvents.find(([hookEvent]) => hookEvent.action === "finished")?.[0];
|
||||
const event = runCronChangedMock.mock.calls
|
||||
.map((call) => requireRecord(call[0], "cron_changed event"))
|
||||
.find((hookEvent) => hookEvent.action === "finished");
|
||||
expect(event?.summary).toBe(summary);
|
||||
} finally {
|
||||
state.cron.stop();
|
||||
|
||||
Reference in New Issue
Block a user