Files
boss/tests/conversation-realtime-patch.test.ts
2026-06-08 12:22:50 +08:00

66 lines
2.3 KiB
TypeScript

import test from "node:test";
import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
async function readSource(path: string) {
return readFile(new URL(path, import.meta.url), "utf8");
}
test("events route enriches project conversation events with a visible home item patch", async () => {
const source = await readSource("../src/app/api/v1/events/route.ts");
assert.match(
source,
/getConversationHomeItemForProject/,
"expected realtime event route to resolve visible conversation items for project updates",
);
assert.match(
source,
/conversationItem:\s*getConversationHomeItemForProject\(state,\s*String\(payload\.projectId \?\? ""\)\)/,
"expected enriched event payload to carry a conversation item slot",
);
assert.match(
source,
/threadConversationItem:\s*getConversationThreadItemForProject\(state,\s*String\(payload\.projectId \?\? ""\)\)/,
"expected enriched event payload to carry a direct thread item slot for folder pages",
);
});
test("events route coalesces enriched payload building across realtime clients", async () => {
const source = await readSource("../src/app/api/v1/events/route.ts");
assert.match(
source,
/getSharedEventPayload/,
"expected realtime event route to share one enriched payload build across concurrent SSE clients",
);
assert.match(
source,
/sharedEventPayloads/,
"expected realtime event route to keep a short-lived shared payload cache",
);
});
test("MainActivity applies realtime conversation patches without forcing a network refresh", async () => {
const [mainActivity, mapper] = await Promise.all([
readSource("../android/app/src/main/java/com/hyzq/boss/MainActivity.java"),
readSource("../android/app/src/main/java/com/hyzq/boss/WechatSurfaceMapper.java"),
]);
assert.match(
mainActivity,
/tryApplyConversationRealtimePatch\(event\)/,
"expected root conversation page to try a local realtime patch before falling back to network refresh",
);
assert.match(
mainActivity,
/WechatSurfaceMapper\.mergeConversationHomeItem\(/,
"expected root conversation page to merge realtime conversation items locally",
);
assert.match(
mapper,
/public static JSONArray mergeConversationHomeItem\(/,
"expected surface mapper to expose a home-feed merge helper for realtime patches",
);
});