mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 21:34:46 +00:00
test: tighten line send receipt assertions
This commit is contained in:
@@ -2,7 +2,7 @@ import {
|
||||
verifyChannelMessageAdapterCapabilityProofs,
|
||||
verifyChannelMessageReceiveAckPolicyAdapterProofs,
|
||||
} from "openclaw/plugin-sdk/channel-message";
|
||||
import { afterAll, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { afterAll, afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig, PluginRuntime } from "../api.js";
|
||||
import { linePlugin } from "./channel.js";
|
||||
import { lineConfigAdapter } from "./config-adapter.js";
|
||||
@@ -40,6 +40,7 @@ type LineRuntimeMocks = {
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
vi.setSystemTime(1_800_000_000_000);
|
||||
ssrfMocks.resolvePinnedHostnameWithPolicy.mockReset();
|
||||
ssrfMocks.resolvePinnedHostnameWithPolicy.mockResolvedValue({
|
||||
hostname: "example.com",
|
||||
@@ -47,6 +48,10 @@ beforeEach(() => {
|
||||
});
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
function lineResult(messageId: string, chatId = "c1") {
|
||||
return {
|
||||
messageId,
|
||||
@@ -259,8 +264,41 @@ describe("line outbound sendPayload", () => {
|
||||
["One", "Two"],
|
||||
{ verbose: false, accountId: "default", cfg },
|
||||
);
|
||||
expect(result).toMatchObject({ channel: "line", messageId: "m-quick", chatId: "c1" });
|
||||
expect(result.receipt?.primaryPlatformMessageId).toBe("m-quick");
|
||||
expect(result).toEqual({
|
||||
channel: "line",
|
||||
chatId: "c1",
|
||||
messageId: "m-quick",
|
||||
receipt: {
|
||||
parts: [
|
||||
{
|
||||
index: 0,
|
||||
kind: "text",
|
||||
platformMessageId: "m-quick",
|
||||
raw: {
|
||||
channel: "line",
|
||||
chatId: "c1",
|
||||
conversationId: "c1",
|
||||
messageId: "m-quick",
|
||||
meta: { messageCount: 1 },
|
||||
},
|
||||
threadId: "c1",
|
||||
},
|
||||
],
|
||||
platformMessageIds: ["m-quick"],
|
||||
primaryPlatformMessageId: "m-quick",
|
||||
raw: [
|
||||
{
|
||||
channel: "line",
|
||||
chatId: "c1",
|
||||
conversationId: "c1",
|
||||
messageId: "m-quick",
|
||||
meta: { messageCount: 1 },
|
||||
},
|
||||
],
|
||||
sentAt: 1_800_000_000_000,
|
||||
threadId: "c1",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("sends media before quick-reply text so buttons stay visible", async () => {
|
||||
|
||||
@@ -93,6 +93,8 @@ const LINE_TEST_CFG = {
|
||||
};
|
||||
|
||||
describe("LINE send helpers", () => {
|
||||
const fixedSentAt = 1_800_000_000_000;
|
||||
|
||||
beforeAll(async () => {
|
||||
sendModule = await import("./send.js");
|
||||
});
|
||||
@@ -109,6 +111,7 @@ describe("LINE send helpers", () => {
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
vi.setSystemTime(fixedSentAt);
|
||||
pushMessageMock.mockReset();
|
||||
replyMessageMock.mockReset();
|
||||
showLoadingAnimationMock.mockReset();
|
||||
@@ -176,8 +179,40 @@ describe("LINE send helpers", () => {
|
||||
direction: "outbound",
|
||||
});
|
||||
expect(logVerboseMock).toHaveBeenCalledWith("line: pushed image to U123");
|
||||
expect(result).toMatchObject({ messageId: "push", chatId: "U123" });
|
||||
expect(result.receipt.primaryPlatformMessageId).toBe("push");
|
||||
expect(result).toEqual({
|
||||
chatId: "U123",
|
||||
messageId: "push",
|
||||
receipt: {
|
||||
parts: [
|
||||
{
|
||||
index: 0,
|
||||
kind: "media",
|
||||
platformMessageId: "push",
|
||||
raw: {
|
||||
channel: "line",
|
||||
chatId: "U123",
|
||||
conversationId: "U123",
|
||||
messageId: "push",
|
||||
meta: { messageCount: 1 },
|
||||
},
|
||||
threadId: "U123",
|
||||
},
|
||||
],
|
||||
platformMessageIds: ["push"],
|
||||
primaryPlatformMessageId: "push",
|
||||
raw: [
|
||||
{
|
||||
channel: "line",
|
||||
chatId: "U123",
|
||||
conversationId: "U123",
|
||||
messageId: "push",
|
||||
meta: { messageCount: 1 },
|
||||
},
|
||||
],
|
||||
sentAt: fixedSentAt,
|
||||
threadId: "U123",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("replies when reply token is provided", async () => {
|
||||
@@ -205,10 +240,40 @@ describe("LINE send helpers", () => {
|
||||
],
|
||||
});
|
||||
expect(logVerboseMock).toHaveBeenCalledWith("line: replied to C1");
|
||||
expect(result).toMatchObject({ messageId: "reply", chatId: "C1" });
|
||||
expect(result.receipt.primaryPlatformMessageId).toBe("reply");
|
||||
expect(result.receipt.threadId).toBe("C1");
|
||||
expect(result.receipt.parts[0]?.kind).toBe("media");
|
||||
expect(result).toEqual({
|
||||
chatId: "C1",
|
||||
messageId: "reply",
|
||||
receipt: {
|
||||
parts: [
|
||||
{
|
||||
index: 0,
|
||||
kind: "media",
|
||||
platformMessageId: "reply",
|
||||
raw: {
|
||||
channel: "line",
|
||||
chatId: "C1",
|
||||
conversationId: "C1",
|
||||
messageId: "reply",
|
||||
meta: { messageCount: 2 },
|
||||
},
|
||||
threadId: "C1",
|
||||
},
|
||||
],
|
||||
platformMessageIds: ["reply"],
|
||||
primaryPlatformMessageId: "reply",
|
||||
raw: [
|
||||
{
|
||||
channel: "line",
|
||||
chatId: "C1",
|
||||
conversationId: "C1",
|
||||
messageId: "reply",
|
||||
meta: { messageCount: 2 },
|
||||
},
|
||||
],
|
||||
sentAt: fixedSentAt,
|
||||
threadId: "C1",
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("sends video with explicit image preview URL", async () => {
|
||||
|
||||
Reference in New Issue
Block a user