52 lines
1.7 KiB
TypeScript
52 lines
1.7 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
||
|
||
import {
|
||
finalizeComposeReplyResult,
|
||
inferAddressReplyType,
|
||
joinComposeReplyLines
|
||
} from "../src/services/address_runtime/replyPackaging";
|
||
|
||
describe("replyPackaging", () => {
|
||
it("joins reply lines without changing their order", () => {
|
||
expect(joinComposeReplyLines(["Первая строка", "Вторая строка"])).toBe("Первая строка\nВторая строка");
|
||
});
|
||
|
||
it("applies numeric emphasis line-by-line only when requested", () => {
|
||
const result = finalizeComposeReplyResult(
|
||
{
|
||
responseType: "FACTUAL_SUMMARY",
|
||
text: "Сумма 1500\nОстаток 22",
|
||
semantics: { result_mode: "aggregate" }
|
||
},
|
||
{
|
||
emphasizeNumbers: true,
|
||
emphasizeNumericTokens: (line) => line.replace(/\d+/g, (match) => `**${match}**`)
|
||
}
|
||
);
|
||
|
||
expect(result.text).toBe("Сумма **1500**\nОстаток **22**");
|
||
expect(result.semantics).toEqual({ result_mode: "aggregate" });
|
||
});
|
||
|
||
it("keeps reply text unchanged when emphasis is disabled", () => {
|
||
const result = finalizeComposeReplyResult(
|
||
{
|
||
responseType: "FACTUAL_SUMMARY",
|
||
text: "Сумма 1500"
|
||
},
|
||
{
|
||
emphasizeNumbers: false,
|
||
emphasizeNumericTokens: () => "не должно примениться"
|
||
}
|
||
);
|
||
|
||
expect(result.text).toBe("Сумма 1500");
|
||
});
|
||
|
||
it("maps factual response types away from partial coverage", () => {
|
||
expect(inferAddressReplyType("FACTUAL_LIST")).toBe("factual");
|
||
expect(inferAddressReplyType("FACTUAL_SUMMARY")).toBe("factual");
|
||
expect(inferAddressReplyType("SOFT_REFUSAL")).toBe("partial_coverage");
|
||
});
|
||
});
|