mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 23:40:45 +00:00
* Tests: stabilize detect-secrets fixtures * Tests: fix rebased detect-secrets false positives * Docs: keep snippets valid under detect-secrets * Tests: finalize detect-secrets false-positive fixes * Tests: reduce detect-secrets false positives * Tests: keep detect-secrets pragmas inline * Tests: remediate next detect-secrets batch * Tests: tighten detect-secrets allowlists * Tests: stabilize detect-secrets formatter drift
84 lines
2.4 KiB
TypeScript
84 lines
2.4 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import { createStartAccountContext } from "../../test-utils/start-account-context.js";
|
|
import type { ResolvedNextcloudTalkAccount } from "./accounts.js";
|
|
|
|
const hoisted = vi.hoisted(() => ({
|
|
monitorNextcloudTalkProvider: vi.fn(),
|
|
}));
|
|
|
|
vi.mock("./monitor.js", async () => {
|
|
const actual = await vi.importActual<typeof import("./monitor.js")>("./monitor.js");
|
|
return {
|
|
...actual,
|
|
monitorNextcloudTalkProvider: hoisted.monitorNextcloudTalkProvider,
|
|
};
|
|
});
|
|
|
|
import { nextcloudTalkPlugin } from "./channel.js";
|
|
|
|
function buildAccount(): ResolvedNextcloudTalkAccount {
|
|
return {
|
|
accountId: "default",
|
|
enabled: true,
|
|
baseUrl: "https://nextcloud.example.com",
|
|
secret: "secret", // pragma: allowlist secret
|
|
secretSource: "config", // pragma: allowlist secret
|
|
config: {
|
|
baseUrl: "https://nextcloud.example.com",
|
|
botSecret: "secret", // pragma: allowlist secret
|
|
webhookPath: "/nextcloud-talk-webhook",
|
|
webhookPort: 8788,
|
|
},
|
|
};
|
|
}
|
|
|
|
describe("nextcloudTalkPlugin gateway.startAccount", () => {
|
|
afterEach(() => {
|
|
vi.clearAllMocks();
|
|
});
|
|
|
|
it("keeps startAccount pending until abort, then stops the monitor", async () => {
|
|
const stop = vi.fn();
|
|
hoisted.monitorNextcloudTalkProvider.mockResolvedValue({ stop });
|
|
const abort = new AbortController();
|
|
|
|
const task = nextcloudTalkPlugin.gateway!.startAccount!(
|
|
createStartAccountContext({
|
|
account: buildAccount(),
|
|
abortSignal: abort.signal,
|
|
}),
|
|
);
|
|
let settled = false;
|
|
void task.then(() => {
|
|
settled = true;
|
|
});
|
|
await vi.waitFor(() => {
|
|
expect(hoisted.monitorNextcloudTalkProvider).toHaveBeenCalledOnce();
|
|
});
|
|
expect(settled).toBe(false);
|
|
expect(stop).not.toHaveBeenCalled();
|
|
|
|
abort.abort();
|
|
await task;
|
|
|
|
expect(stop).toHaveBeenCalledOnce();
|
|
});
|
|
|
|
it("stops immediately when startAccount receives an already-aborted signal", async () => {
|
|
const stop = vi.fn();
|
|
hoisted.monitorNextcloudTalkProvider.mockResolvedValue({ stop });
|
|
const abort = new AbortController();
|
|
abort.abort();
|
|
|
|
await nextcloudTalkPlugin.gateway!.startAccount!(
|
|
createStartAccountContext({
|
|
account: buildAccount(),
|
|
abortSignal: abort.signal,
|
|
}),
|
|
);
|
|
|
|
expect(hoisted.monitorNextcloudTalkProvider).toHaveBeenCalledOnce();
|
|
expect(stop).toHaveBeenCalledOnce();
|
|
});
|
|
});
|