Files
boss/tests/android-chat-lightweight-realtime-refresh.test.ts
2026-06-08 12:22:50 +08:00

43 lines
1.8 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("BossApiClient exposes a lightweight project messages endpoint", async () => {
const source = await readSource("../android/app/src/main/java/com/hyzq/boss/BossApiClient.java");
assert.match(
source,
/public ApiResponse getProjectMessages\(String projectId\) throws IOException, JSONException \{/,
"expected Android client to expose a lightweight messages endpoint",
);
assert.match(
source,
/return requestWithRestoreRaw\(\s*"GET",\s*"\/api\/v1\/projects\/" \+ encode\(projectId\) \+ "\/messages",\s*null,\s*DEFAULT_CONNECT_TIMEOUT_MS,\s*CONVERSATIONS_READ_TIMEOUT_MS\s*\);/s,
"expected lightweight message refreshes to reuse the dedicated messages route",
);
});
test("ProjectDetailActivity reserves full realtime reloads for non-message events", async () => {
const source = await readSource("../android/app/src/main/java/com/hyzq/boss/ProjectDetailActivity.java");
assert.match(
source,
/private boolean realtimeReloadRequiresFullSnapshot;/,
"expected chat page debounce state to remember whether a full snapshot is required",
);
assert.match(
source,
/runOnUiThread\(\(\) -> scheduleRealtimeReload\(!"project\.messages\.updated"\.equals\(event\.eventName\)\)\);/,
"expected message-only realtime updates to avoid forcing a full snapshot",
);
assert.match(
source,
/void triggerRealtimeReload\(boolean requireFullSnapshot\) \{\s*if \(requireFullSnapshot\) \{\s*reloadInBackground\(false\);\s*return;\s*\}\s*reloadMessagesOnly\(\);\s*\}/s,
"expected debounced realtime reloads to choose between full and lightweight refresh paths",
);
});