mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 23:58:25 +00:00
test(line): dedupe event fixtures and cover room postback routing
This commit is contained in:
@@ -20,6 +20,38 @@ describe("buildLineMessageContext", () => {
|
|||||||
config: {},
|
config: {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const createMessageEvent = (
|
||||||
|
source: MessageEvent["source"],
|
||||||
|
overrides?: Partial<MessageEvent>,
|
||||||
|
): MessageEvent =>
|
||||||
|
({
|
||||||
|
type: "message",
|
||||||
|
message: { id: "1", type: "text", text: "hello" },
|
||||||
|
replyToken: "reply-token",
|
||||||
|
timestamp: Date.now(),
|
||||||
|
source,
|
||||||
|
mode: "active",
|
||||||
|
webhookEventId: "evt-1",
|
||||||
|
deliveryContext: { isRedelivery: false },
|
||||||
|
...overrides,
|
||||||
|
}) as MessageEvent;
|
||||||
|
|
||||||
|
const createPostbackEvent = (
|
||||||
|
source: PostbackEvent["source"],
|
||||||
|
overrides?: Partial<PostbackEvent>,
|
||||||
|
): PostbackEvent =>
|
||||||
|
({
|
||||||
|
type: "postback",
|
||||||
|
postback: { data: "action=select" },
|
||||||
|
replyToken: "reply-token",
|
||||||
|
timestamp: Date.now(),
|
||||||
|
source,
|
||||||
|
mode: "active",
|
||||||
|
webhookEventId: "evt-2",
|
||||||
|
deliveryContext: { isRedelivery: false },
|
||||||
|
...overrides,
|
||||||
|
}) as PostbackEvent;
|
||||||
|
|
||||||
beforeEach(async () => {
|
beforeEach(async () => {
|
||||||
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-line-context-"));
|
tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), "openclaw-line-context-"));
|
||||||
storePath = path.join(tmpDir, "sessions.json");
|
storePath = path.join(tmpDir, "sessions.json");
|
||||||
@@ -36,16 +68,7 @@ describe("buildLineMessageContext", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("routes group message replies to the group id", async () => {
|
it("routes group message replies to the group id", async () => {
|
||||||
const event = {
|
const event = createMessageEvent({ type: "group", groupId: "group-1", userId: "user-1" });
|
||||||
type: "message",
|
|
||||||
message: { id: "1", type: "text", text: "hello" },
|
|
||||||
replyToken: "reply-token",
|
|
||||||
timestamp: Date.now(),
|
|
||||||
source: { type: "group", groupId: "group-1", userId: "user-1" },
|
|
||||||
mode: "active",
|
|
||||||
webhookEventId: "evt-1",
|
|
||||||
deliveryContext: { isRedelivery: false },
|
|
||||||
} as MessageEvent;
|
|
||||||
|
|
||||||
const context = await buildLineMessageContext({
|
const context = await buildLineMessageContext({
|
||||||
event,
|
event,
|
||||||
@@ -63,16 +86,7 @@ describe("buildLineMessageContext", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it("routes group postback replies to the group id", async () => {
|
it("routes group postback replies to the group id", async () => {
|
||||||
const event = {
|
const event = createPostbackEvent({ type: "group", groupId: "group-2", userId: "user-2" });
|
||||||
type: "postback",
|
|
||||||
postback: { data: "action=select" },
|
|
||||||
replyToken: "reply-token",
|
|
||||||
timestamp: Date.now(),
|
|
||||||
source: { type: "group", groupId: "group-2", userId: "user-2" },
|
|
||||||
mode: "active",
|
|
||||||
webhookEventId: "evt-2",
|
|
||||||
deliveryContext: { isRedelivery: false },
|
|
||||||
} as PostbackEvent;
|
|
||||||
|
|
||||||
const context = await buildLinePostbackContext({
|
const context = await buildLinePostbackContext({
|
||||||
event,
|
event,
|
||||||
@@ -83,4 +97,17 @@ describe("buildLineMessageContext", () => {
|
|||||||
expect(context?.ctxPayload.OriginatingTo).toBe("line:group:group-2");
|
expect(context?.ctxPayload.OriginatingTo).toBe("line:group:group-2");
|
||||||
expect(context?.ctxPayload.To).toBe("line:group:group-2");
|
expect(context?.ctxPayload.To).toBe("line:group:group-2");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("routes room postback replies to the room id", async () => {
|
||||||
|
const event = createPostbackEvent({ type: "room", roomId: "room-1", userId: "user-3" });
|
||||||
|
|
||||||
|
const context = await buildLinePostbackContext({
|
||||||
|
event,
|
||||||
|
cfg,
|
||||||
|
account,
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(context?.ctxPayload.OriginatingTo).toBe("line:room:room-1");
|
||||||
|
expect(context?.ctxPayload.To).toBe("line:room:room-1");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user