mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-16 18:34:18 +00:00
test: guard chat extension null helpers
This commit is contained in:
@@ -85,10 +85,12 @@ describe("loadIMessageCatchupCursor / saveIMessageCatchupCursor", () => {
|
||||
lastSeenRowid: 42,
|
||||
});
|
||||
const cursor = await loadIMessageCatchupCursor("primary");
|
||||
expect(cursor).not.toBeNull();
|
||||
expect(cursor?.lastSeenMs).toBe(1_700_000_000_000);
|
||||
expect(cursor?.lastSeenRowid).toBe(42);
|
||||
expect(cursor?.failureRetries).toBeUndefined();
|
||||
if (!cursor) {
|
||||
throw new Error("expected iMessage catchup cursor");
|
||||
}
|
||||
expect(cursor.lastSeenMs).toBe(1_700_000_000_000);
|
||||
expect(cursor.lastSeenRowid).toBe(42);
|
||||
expect(cursor.failureRetries).toBeUndefined();
|
||||
});
|
||||
|
||||
it("round-trips a cursor with failureRetries", async () => {
|
||||
|
||||
@@ -124,8 +124,6 @@ function requireCapturedItemEventHandler() {
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
expect(typeof value).toBe("object");
|
||||
expect(value).not.toBeNull();
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
|
||||
@@ -2391,7 +2391,6 @@ describe("prepareSlackMessage sender prefix", () => {
|
||||
|
||||
const result = await prepareSenderPrefixMessage(ctx, "<@BOT> /new", "1700000000.0002");
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
if (!result) {
|
||||
throw new Error("expected sender prefix message result");
|
||||
}
|
||||
|
||||
@@ -199,8 +199,6 @@ function getCapturedReplyOptions() {
|
||||
}
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
expect(typeof value).toBe("object");
|
||||
expect(value).not.toBeNull();
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,13 @@ vi.mock("openclaw/plugin-sdk/channel-activity-runtime", async () => {
|
||||
};
|
||||
});
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
describe("createWebSendApi", () => {
|
||||
const sendMessage = vi.fn(
|
||||
async (
|
||||
@@ -38,15 +45,6 @@ describe("createWebSendApi", () => {
|
||||
});
|
||||
});
|
||||
|
||||
function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
expect(typeof value).toBe("object");
|
||||
expect(value).not.toBeNull();
|
||||
if (typeof value !== "object" || value === null) {
|
||||
throw new Error(`${label} was not an object`);
|
||||
}
|
||||
return value as Record<string, unknown>;
|
||||
}
|
||||
|
||||
function expectRecordFields(record: Record<string, unknown>, fields: Record<string, unknown>) {
|
||||
for (const [key, value] of Object.entries(fields)) {
|
||||
expect(record[key]).toEqual(value);
|
||||
@@ -423,9 +421,8 @@ describe("createWebSendApi LID resolution (issue #67378)", () => {
|
||||
});
|
||||
await api.sendPoll("+15555550000", { question: "Q?", options: ["a", "b"] });
|
||||
expect(sendMessage.mock.calls[0]?.[0]).toBe("987654@lid");
|
||||
expect(typeof sendMessage.mock.calls[0]?.[1]).toBe("object");
|
||||
expect(sendMessage.mock.calls[0]?.[1]).not.toBeNull();
|
||||
expect("poll" in (sendMessage.mock.calls[0]?.[1] as Record<string, unknown>)).toBe(true);
|
||||
const payload = requireRecord(sendMessage.mock.calls[0]?.[1], "send poll payload");
|
||||
expect("poll" in payload).toBe(true);
|
||||
});
|
||||
|
||||
it("resolves PN to LID for sendComposingTo presence", async () => {
|
||||
|
||||
Reference in New Issue
Block a user