mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 05:12:43 +00:00
refactor: add inbound context helpers
This commit is contained in:
30
src/channels/sender-identity.test.ts
Normal file
30
src/channels/sender-identity.test.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import type { MsgContext } from "../auto-reply/templating.js";
|
||||
import { validateSenderIdentity } from "./sender-identity.js";
|
||||
|
||||
describe("validateSenderIdentity", () => {
|
||||
it("allows direct messages without sender fields", () => {
|
||||
const ctx: MsgContext = { ChatType: "direct" };
|
||||
expect(validateSenderIdentity(ctx)).toEqual([]);
|
||||
});
|
||||
|
||||
it("requires some sender identity for non-direct chats", () => {
|
||||
const ctx: MsgContext = { ChatType: "group" };
|
||||
expect(validateSenderIdentity(ctx)).toContain("missing sender identity (SenderId/SenderName/SenderUsername/SenderE164)");
|
||||
});
|
||||
|
||||
it("validates SenderE164 and SenderUsername shape", () => {
|
||||
const ctx: MsgContext = {
|
||||
ChatType: "group",
|
||||
SenderE164: "123",
|
||||
SenderUsername: "@ada lovelace",
|
||||
};
|
||||
expect(validateSenderIdentity(ctx)).toEqual([
|
||||
"invalid SenderE164: 123",
|
||||
'SenderUsername should not include "@": @ada lovelace',
|
||||
"SenderUsername should not include whitespace: @ada lovelace",
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user