mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-26 12:26:38 -06:00
refactor: consolidate remaining coercion helpers (#122020)
This commit is contained in:
committed by
GitHub
parent
24bbb416b5
commit
cad77fb39c
@@ -1,4 +1,4 @@
|
||||
import { asOptionalObjectRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
||||
import { asRecord } from "openclaw/plugin-sdk/string-coerce-runtime";
|
||||
// Feishu helper module supports card test helpers behavior.
|
||||
import { expect } from "vitest";
|
||||
|
||||
@@ -10,6 +10,10 @@ function asArray(value: unknown): unknown[] {
|
||||
return Array.isArray(value) ? value : [];
|
||||
}
|
||||
|
||||
function readFeishuObjectRecord(value: unknown): Record<string, unknown> | undefined {
|
||||
return value !== null && typeof value === "object" ? asRecord(value) : undefined;
|
||||
}
|
||||
|
||||
export function expectFirstSentCardUsesFillWidthOnly(sendCardMock: {
|
||||
mock: { calls: unknown[][] };
|
||||
}) {
|
||||
@@ -33,17 +37,17 @@ export function expectFirstSentCardUsesFillWidthOnly(sendCardMock: {
|
||||
|
||||
export function expectSentCardHasP2pAction(sendCardMock: MockCalls) {
|
||||
const hasP2pAction = sendCardMock.mock.calls.some(([arg]) => {
|
||||
const card = asOptionalObjectRecord(asOptionalObjectRecord(arg)?.card);
|
||||
const body = asOptionalObjectRecord(card?.body);
|
||||
const card = readFeishuObjectRecord(readFeishuObjectRecord(arg)?.card);
|
||||
const body = readFeishuObjectRecord(card?.body);
|
||||
return asArray(body?.elements).some((element) => {
|
||||
const elementRecord = asOptionalObjectRecord(element);
|
||||
const elementRecord = readFeishuObjectRecord(element);
|
||||
if (elementRecord?.tag !== "action") {
|
||||
return false;
|
||||
}
|
||||
return asArray(elementRecord.actions).some((action) => {
|
||||
const actionRecord = asOptionalObjectRecord(action);
|
||||
const value = asOptionalObjectRecord(actionRecord?.value);
|
||||
const command = asOptionalObjectRecord(value?.c);
|
||||
const actionRecord = readFeishuObjectRecord(action);
|
||||
const value = readFeishuObjectRecord(actionRecord?.value);
|
||||
const command = readFeishuObjectRecord(value?.c);
|
||||
return command?.t === "p2p";
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user