mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-24 20:31:18 +00:00
* test(shared): add unit tests for normalizeNodePresenceAliveReason * fix(test): add missing bg_app_refresh and significant_location assertions
41 lines
1.8 KiB
TypeScript
41 lines
1.8 KiB
TypeScript
// Node presence tests cover alive reason normalization for heartbeat metadata.
|
|
import { describe, expect, it } from "vitest";
|
|
import { NODE_PRESENCE_ALIVE_EVENT, normalizeNodePresenceAliveReason } from "./node-presence.js";
|
|
|
|
describe("NODE_PRESENCE_ALIVE_EVENT", () => {
|
|
it("is the expected gateway event name", () => {
|
|
expect(NODE_PRESENCE_ALIVE_EVENT).toBe("node.presence.alive");
|
|
});
|
|
});
|
|
|
|
describe("normalizeNodePresenceAliveReason", () => {
|
|
it("passes through known canonical reasons", () => {
|
|
expect(normalizeNodePresenceAliveReason("background")).toBe("background");
|
|
expect(normalizeNodePresenceAliveReason("silent_push")).toBe("silent_push");
|
|
expect(normalizeNodePresenceAliveReason("manual")).toBe("manual");
|
|
expect(normalizeNodePresenceAliveReason("connect")).toBe("connect");
|
|
expect(normalizeNodePresenceAliveReason("bg_app_refresh")).toBe("bg_app_refresh");
|
|
expect(normalizeNodePresenceAliveReason("significant_location")).toBe("significant_location");
|
|
});
|
|
|
|
it("is case-insensitive", () => {
|
|
expect(normalizeNodePresenceAliveReason("MANUAL")).toBe("manual");
|
|
expect(normalizeNodePresenceAliveReason("Background")).toBe("background");
|
|
});
|
|
|
|
it("trims whitespace from input", () => {
|
|
expect(normalizeNodePresenceAliveReason(" manual ")).toBe("manual");
|
|
});
|
|
|
|
it("defaults to background for unknown values", () => {
|
|
expect(normalizeNodePresenceAliveReason("unknown")).toBe("background");
|
|
expect(normalizeNodePresenceAliveReason("")).toBe("background");
|
|
});
|
|
|
|
it("defaults to background for non-string values", () => {
|
|
expect(normalizeNodePresenceAliveReason(undefined)).toBe("background");
|
|
expect(normalizeNodePresenceAliveReason(null)).toBe("background");
|
|
expect(normalizeNodePresenceAliveReason(123)).toBe("background");
|
|
});
|
|
});
|