forked from bai/curriculum-project-hub
fix: resolve Feishu sender names via basic profile API
This commit is contained in:
@@ -2,7 +2,8 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { mkdtemp, rm, writeFile } from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import { join } from "node:path";
|
||||
import { sendFile, sendLongText, sendTextMessage, type FeishuRuntime } from "../../src/feishu/client.js";
|
||||
import { resolveSenderName, sendFile, sendLongText, sendTextMessage, type FeishuRuntime } from "../../src/feishu/client.js";
|
||||
import { SenderNameCache } from "../../src/feishu/senderCache.js";
|
||||
|
||||
describe("Feishu client helpers", () => {
|
||||
it("accepts top-level file_key from the Lark SDK file upload response", async () => {
|
||||
@@ -47,14 +48,41 @@ describe("Feishu client helpers", () => {
|
||||
});
|
||||
expect(sentTexts.map((text) => text.length)).toEqual([8000, 8000, 5]);
|
||||
});
|
||||
|
||||
it("resolves sender names through the basic contact API and caches hits", async () => {
|
||||
const contactBasicBatch = vi.fn(async () => ({ data: { users: [{ name: "Jiarong" }] } }));
|
||||
const request = vi.fn();
|
||||
const rt = mockRuntime({ fileCreate: vi.fn(), messageCreate: vi.fn(), contactBasicBatch, request });
|
||||
const cache = new SenderNameCache();
|
||||
|
||||
await expect(resolveSenderName(rt, "ou_user_1", cache)).resolves.toBe("Jiarong");
|
||||
await expect(resolveSenderName(rt, "ou_user_1", cache)).resolves.toBe("Jiarong");
|
||||
|
||||
expect(contactBasicBatch).toHaveBeenCalledTimes(1);
|
||||
expect(contactBasicBatch).toHaveBeenCalledWith({
|
||||
params: { user_id_type: "open_id" },
|
||||
data: { user_ids: ["ou_user_1"] },
|
||||
});
|
||||
expect(request).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
||||
function mockRuntime(options: {
|
||||
readonly fileCreate: (payload: unknown) => Promise<unknown>;
|
||||
readonly messageCreate: (payload: unknown) => Promise<unknown>;
|
||||
readonly contactBasicBatch?: (payload: unknown) => Promise<unknown>;
|
||||
readonly request?: (payload: unknown) => Promise<unknown>;
|
||||
}): FeishuRuntime {
|
||||
return {
|
||||
client: {
|
||||
request: options.request,
|
||||
contact: {
|
||||
v3: {
|
||||
user: {
|
||||
basicBatch: options.contactBasicBatch,
|
||||
},
|
||||
},
|
||||
},
|
||||
im: {
|
||||
v1: {
|
||||
file: { create: options.fileCreate },
|
||||
|
||||
Reference in New Issue
Block a user