mirror of
https://github.com/sinanyuntu/trade-message-center.git
synced 2026-09-17 13:22:11 +08:00
72 lines
2.6 KiB
TypeScript
72 lines
2.6 KiB
TypeScript
// 验证 rendered-card supplement 可独立于基础消息提交。
|
|
|
|
import assert from "node:assert/strict";
|
|
import test from "node:test";
|
|
|
|
import { createOneTalkRenderedCardContentFingerprint } from "@trade-message-center/onetalk-contract";
|
|
import { createOneTalkRenderedCardRepository } from "../src/onetalk/rendered-card-repository.ts";
|
|
|
|
const content = {
|
|
version: 1 as const,
|
|
kind: "rendered_order" as const,
|
|
title: "Order",
|
|
products: [],
|
|
productCount: 0,
|
|
status: { code: null, text: "Paid" },
|
|
payment: { totalDisplay: "$1", discountDisplay: null },
|
|
delivery: { shippingAddress: "Hangzhou", methodLabel: null, dateLabel: null },
|
|
action: { label: null, status: null },
|
|
};
|
|
|
|
test("stores a rendered-card supplement when its base message is absent", async () => {
|
|
const inserted: unknown[] = [];
|
|
const selectResults = [[], []];
|
|
const transaction = {
|
|
select: () => ({
|
|
from: () => ({
|
|
where: () => ({
|
|
limit: () => {
|
|
const result = selectResults.shift();
|
|
return Object.assign(Promise.resolve(result), { for: () => result });
|
|
},
|
|
}),
|
|
}),
|
|
}),
|
|
insert: () => ({
|
|
values: async (value: unknown) => inserted.push(value),
|
|
}),
|
|
update: () => assert.fail("unexpected update"),
|
|
};
|
|
const database = {
|
|
transaction: async (run: (value: typeof transaction) => Promise<unknown>) =>
|
|
run(transaction),
|
|
};
|
|
const repository = createOneTalkRenderedCardRepository(database as never);
|
|
|
|
const result = await repository.store({
|
|
channelAccountId: "account-1",
|
|
observation: {
|
|
conversationId: "conversation-1",
|
|
messageId: "message-1",
|
|
content,
|
|
contentFingerprint: createOneTalkRenderedCardContentFingerprint(content),
|
|
observedAtMs: 100,
|
|
},
|
|
receivedAt: new Date("2026-09-15T00:00:00.000Z"),
|
|
});
|
|
|
|
assert.deepEqual(result, { status: "accepted", renderedCardContent: content, message: null });
|
|
assert.deepEqual(inserted, [
|
|
{
|
|
channelAccountId: "account-1",
|
|
conversationId: "conversation-1",
|
|
messageId: "message-1",
|
|
renderedCardContent: content,
|
|
renderedCardContentFingerprint: createOneTalkRenderedCardContentFingerprint(content),
|
|
renderedCardObservedAtMs: 100,
|
|
firstConfirmedAt: new Date("2026-09-15T00:00:00.000Z"),
|
|
lastObservedAt: new Date("2026-09-15T00:00:00.000Z"),
|
|
},
|
|
]);
|
|
});
|