mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-26 09:05:14 +00:00
test: dedupe channel auth mock reads
This commit is contained in:
@@ -136,7 +136,7 @@ function expectLastReplaceConfig(enabled: boolean) {
|
||||
const calls = (replaceConfigFileMock as unknown as MockCalls).mock.calls;
|
||||
const [payload] = calls.at(-1) ?? [];
|
||||
const payloadRecord = requireRecord(payload, "replace config payload");
|
||||
expect(Object.keys(payloadRecord).sort()).toEqual(["afterWrite", "nextConfig"]);
|
||||
expect(Object.keys(payloadRecord).toSorted()).toEqual(["afterWrite", "nextConfig"]);
|
||||
expect(payloadRecord.afterWrite).toEqual({ mode: "auto" });
|
||||
expectPluginEnabledInConfig(payloadRecord.nextConfig, enabled);
|
||||
}
|
||||
@@ -145,7 +145,7 @@ function expectLastRegistryRefresh(enabled: boolean) {
|
||||
const calls = (refreshPluginRegistryAfterConfigMutationMock as unknown as MockCalls).mock.calls;
|
||||
const [payload] = calls.at(-1) ?? [];
|
||||
const payloadRecord = requireRecord(payload, "registry refresh payload");
|
||||
expect(Object.keys(payloadRecord).sort()).toEqual(["config", "logger", "reason"]);
|
||||
expect(Object.keys(payloadRecord).toSorted()).toEqual(["config", "logger", "reason"]);
|
||||
expect(payloadRecord.reason).toBe("policy-changed");
|
||||
const logger = getNestedRecord(payloadRecord, "logger", "registry refresh logger");
|
||||
expect(logger.warn).toEqual(expect.any(Function));
|
||||
|
||||
@@ -89,13 +89,18 @@ function expectFields(value: unknown, expected: Record<string, unknown>): void {
|
||||
}
|
||||
|
||||
function readFirstCallArg(mock: ReturnType<typeof vi.fn>): Record<string, unknown> {
|
||||
const [arg] = mock.mock.calls.at(0) ?? [];
|
||||
const [arg] = mock.mock.calls[0] ?? [];
|
||||
if (!arg || typeof arg !== "object") {
|
||||
throw new Error("expected first call argument object");
|
||||
}
|
||||
return arg as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function readFirstLogMessage(runtime: { log: ReturnType<typeof vi.fn> }): string {
|
||||
const [message] = runtime.log.mock.calls[0] ?? [];
|
||||
return String(message);
|
||||
}
|
||||
|
||||
function findCallArg(
|
||||
mock: ReturnType<typeof vi.fn>,
|
||||
predicate: (arg: Record<string, unknown>) => boolean,
|
||||
@@ -223,7 +228,7 @@ describe("channel-auth", () => {
|
||||
await runChannelLogin({ channel: "whatsapp", account: "acct-1" }, runtime);
|
||||
|
||||
expect(mocks.callGateway).not.toHaveBeenCalled();
|
||||
expect(String(runtime.log.mock.calls.at(0)?.[0])).toContain("Gateway is in remote mode");
|
||||
expect(readFirstLogMessage(runtime)).toContain("Gateway is in remote mode");
|
||||
});
|
||||
|
||||
it("keeps login successful when local gateway runtime reconcile fails", async () => {
|
||||
@@ -233,7 +238,7 @@ describe("channel-auth", () => {
|
||||
runChannelLogin({ channel: "whatsapp", account: "acct-1" }, runtime),
|
||||
).resolves.toBeUndefined();
|
||||
|
||||
expect(String(runtime.log.mock.calls.at(0)?.[0])).toContain(
|
||||
expect(readFirstLogMessage(runtime)).toContain(
|
||||
"running gateway did not restart it: gateway unreachable",
|
||||
);
|
||||
});
|
||||
@@ -565,7 +570,7 @@ describe("channel-auth", () => {
|
||||
account: { id: "resolved-account" },
|
||||
runtime,
|
||||
});
|
||||
expect(String(runtime.log.mock.calls.at(0)?.[0])).toContain(
|
||||
expect(readFirstLogMessage(runtime)).toContain(
|
||||
"running gateway did not stop it: gateway unreachable",
|
||||
);
|
||||
expect(mocks.setVerbose).not.toHaveBeenCalled();
|
||||
|
||||
Reference in New Issue
Block a user