NODEDC_1C/llm_normalizer/backend/tests/assistantOrganizationMatche...

53 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, expect, it } from "vitest";
import {
mergeKnownOrganizations,
normalizeOrganizationScopeSearchText,
normalizeOrganizationScopeValue,
organizationsLikelySameEntity,
resolveOrganizationSelectionFromMessage,
scoreOrganizationMentionInMessage
} from "../src/services/assistantOrganizationMatcher";
describe("assistant organization matcher", () => {
it("deduplicates known organizations by normalized search key", () => {
expect(
mergeKnownOrganizations([
'ООО "Альтернатива Плюс"',
"ооо альтернатива плюс",
"ООО Лайсвуд"
])
).toEqual(['ООО "Альтернатива Плюс"', "ООО Лайсвуд"]);
});
it("repairs noisy display labels before exposing them to the user", () => {
expect(normalizeOrganizationScopeValue('ООО \\Альтернати"а Плюс\\')).toBe("ООО Альтернатива Плюс");
expect(normalizeOrganizationScopeValue('ООО \\Лайс"уд\\')).toBe("ООО Лайсвуд");
});
it("matches incomplete or reordered organization mention against live candidates", () => {
const resolved = resolveOrganizationSelectionFromMessage("дай что сегодня на складе в конторе кот ссыт", [
"ООО КОТ ССЫТ ВО ДВОРЕ",
"ООО Альтернатива Плюс"
]);
expect(resolved).toBe("ООО КОТ ССЫТ ВО ДВОРЕ");
});
it("scores direct and fuzzy token overlap above ambiguity threshold", () => {
const score = scoreOrganizationMentionInMessage(
normalizeOrganizationScopeSearchText("что на складе конторы альтернатива"),
'ООО "Альтернатива Плюс"'
);
expect(score).toBeGreaterThanOrEqual(90);
});
it("treats minor live label corruption as the same organization entity", () => {
expect(organizationsLikelySameEntity("Альтернатива Плюс", 'ООО "Альтернати"а Плюс"')).toBe(true);
});
it("does not merge different organizations with only one shared token", () => {
expect(organizationsLikelySameEntity('ООО "Альтернатива Плюс"', 'ООО "Альтернатива Минус"')).toBe(false);
});
});