mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-26 20:35:39 -06:00
test: guard feishu mock helpers
This commit is contained in:
@@ -241,8 +241,10 @@ function mockCallArg<T>(
|
||||
_type?: (value: unknown) => value is T,
|
||||
): T {
|
||||
const call = mock.mock.calls[callIndex];
|
||||
expect(call).toBeDefined();
|
||||
return call?.[argIndex] as T;
|
||||
if (!call) {
|
||||
throw new Error(`Expected mock call at index ${callIndex}`);
|
||||
}
|
||||
return call[argIndex] as T;
|
||||
}
|
||||
|
||||
type FeishuRoutePeer = { id: string; kind: "direct" | "group" };
|
||||
|
||||
@@ -149,7 +149,9 @@ describe("createFeishuCommentReplyDispatcher", () => {
|
||||
|
||||
expect(status).toBe("done");
|
||||
const client = createFeishuClientMock.mock.results[0]?.value;
|
||||
expect(client).toBeDefined();
|
||||
if (!client) {
|
||||
throw new Error("Expected Feishu client");
|
||||
}
|
||||
expect(deliverCommentThreadTextMock).toHaveBeenCalledWith(client, {
|
||||
file_token: "doc_token_1",
|
||||
file_type: "docx",
|
||||
|
||||
@@ -72,8 +72,10 @@ function requireRecord(value: unknown, label: string): Record<string, unknown> {
|
||||
function callArg(mock: unknown, callIndex: number, argIndex: number, label: string) {
|
||||
const calls = (mock as { mock?: { calls?: Array<Array<unknown>> } }).mock?.calls ?? [];
|
||||
const call = calls.at(callIndex);
|
||||
expect(call, label).toBeDefined();
|
||||
return call?.[argIndex];
|
||||
if (!call) {
|
||||
throw new Error(`Expected ${label}`);
|
||||
}
|
||||
return call[argIndex];
|
||||
}
|
||||
|
||||
function expectLoadWebMediaCall(fileName: string, localRoots: unknown[] | undefined) {
|
||||
|
||||
@@ -52,8 +52,10 @@ function mockCallArg<T>(
|
||||
_type?: (value: unknown) => value is T,
|
||||
): T {
|
||||
const call = mock.mock.calls[callIndex];
|
||||
expect(call).toBeDefined();
|
||||
return call?.[argIndex] as T;
|
||||
if (!call) {
|
||||
throw new Error(`Expected mock call at index ${callIndex}`);
|
||||
}
|
||||
return call[argIndex] as T;
|
||||
}
|
||||
|
||||
type FeishuDriveRequest = {
|
||||
@@ -633,7 +635,9 @@ describe("registerFeishuDriveTools", () => {
|
||||
client?: unknown;
|
||||
deliveryContext?: { channel?: string; threadId?: string; to?: string };
|
||||
}>(cleanupAmbientCommentTypingReactionMock, 0, 0);
|
||||
expect(cleanupRequest.client).toBeDefined();
|
||||
if (!cleanupRequest.client) {
|
||||
throw new Error("Expected cleanup request client");
|
||||
}
|
||||
expect(cleanupRequest.deliveryContext).toEqual({
|
||||
channel: "feishu",
|
||||
to: "comment:docx:doc_1:c1",
|
||||
@@ -707,7 +711,9 @@ describe("registerFeishuDriveTools", () => {
|
||||
client?: unknown;
|
||||
deliveryContext?: { channel?: string; threadId?: string; to?: string };
|
||||
}>(cleanupAmbientCommentTypingReactionMock, 0, 0);
|
||||
expect(cleanupRequest.client).toBeDefined();
|
||||
if (!cleanupRequest.client) {
|
||||
throw new Error("Expected cleanup request client");
|
||||
}
|
||||
expect(cleanupRequest.deliveryContext).toEqual({
|
||||
channel: "feishu",
|
||||
to: "comment:docx:doc_1:c1",
|
||||
|
||||
@@ -91,8 +91,10 @@ function mockCallArg<T>(
|
||||
_type?: (value: unknown) => value is T,
|
||||
): T {
|
||||
const call = mock.mock.calls[callIndex];
|
||||
expect(call).toBeDefined();
|
||||
return call?.[argIndex] as T;
|
||||
if (!call) {
|
||||
throw new Error(`Expected mock call at index ${callIndex}`);
|
||||
}
|
||||
return call[argIndex] as T;
|
||||
}
|
||||
|
||||
function callData<T>(
|
||||
@@ -101,7 +103,9 @@ function callData<T>(
|
||||
_type?: (value: unknown) => value is T,
|
||||
): T {
|
||||
const arg = mockCallArg<{ data?: unknown }>(mock, callIndex, 0);
|
||||
expect(arg.data).toBeDefined();
|
||||
if (arg.data === undefined) {
|
||||
throw new Error(`Expected mock call data at index ${callIndex}`);
|
||||
}
|
||||
return arg.data as T;
|
||||
}
|
||||
|
||||
|
||||
@@ -801,8 +801,11 @@ describe("feishuOutbound comment-thread routing", () => {
|
||||
|
||||
expect(status).toBe("done");
|
||||
expect(deliverCommentThreadTextMock).toHaveBeenCalled();
|
||||
expect(cleanupReactionCall()?.client).toBeDefined();
|
||||
expect(cleanupReactionCall()?.deliveryContext).toEqual({
|
||||
const cleanupCall = cleanupReactionCall();
|
||||
if (!cleanupCall?.client) {
|
||||
throw new Error("Expected cleanup reaction client");
|
||||
}
|
||||
expect(cleanupCall.deliveryContext).toEqual({
|
||||
channel: "feishu",
|
||||
to: "comment:docx:doxcn123:7623358762119646411",
|
||||
threadId: "reply_ambient_1",
|
||||
|
||||
@@ -245,7 +245,9 @@ describe("createFeishuReplyDispatcher streaming behavior", () => {
|
||||
expected: Record<string, unknown>,
|
||||
): Record<string, unknown> {
|
||||
const start = streamingInstances[instanceIndex]?.start;
|
||||
expect(start, "streaming instance must exist").toBeDefined();
|
||||
if (!start) {
|
||||
throw new Error(`Expected streaming instance ${instanceIndex}`);
|
||||
}
|
||||
expect(start.mock.calls[0]?.[0]).toBe("oc_chat");
|
||||
expect(start.mock.calls[0]?.[1]).toBe("chat_id");
|
||||
return expectRecordFields(start.mock.calls[0]?.[2], "streaming start options", expected);
|
||||
|
||||
Reference in New Issue
Block a user