67 lines
2.1 KiB
TypeScript
67 lines
2.1 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import {
|
|
extractOrganizationFactsFromRowsForTests,
|
|
resolveOrganizationNamesByRefsForTests
|
|
} from "../src/services/assistantService";
|
|
|
|
describe("assistant data scope probe parser", () => {
|
|
it("extracts organization name and guid from object-ref style row", () => {
|
|
const rows = [
|
|
{
|
|
Organization: {
|
|
_objectRef: true,
|
|
Guid: "5b516757-45d0-11e1-8c52-001e5848397d",
|
|
ObjectType: "CatalogRef.Organization",
|
|
Presentation: "OOO Alternativa Plus"
|
|
}
|
|
}
|
|
];
|
|
|
|
const facts = extractOrganizationFactsFromRowsForTests(rows as any);
|
|
|
|
expect(facts.names).toContain("OOO Alternativa Plus");
|
|
expect(facts.refs).toContain("5b516757-45d0-11e1-8c52-001e5848397d");
|
|
expect(
|
|
facts.pairs.some(
|
|
(item: any) =>
|
|
item.ref === "5b516757-45d0-11e1-8c52-001e5848397d" &&
|
|
item.name === "OOO Alternativa Plus"
|
|
)
|
|
).toBe(true);
|
|
});
|
|
|
|
it("extracts guid from hard-key payload (name is best-effort)", () => {
|
|
const rows = [
|
|
{
|
|
payload: {
|
|
_objectRef: true,
|
|
f1: "5b516757-45d0-11e1-8c52-001e5848397d",
|
|
f2: "CatalogRef.Organization",
|
|
f3: "OOO Alternativa Plus"
|
|
}
|
|
}
|
|
];
|
|
|
|
const facts = extractOrganizationFactsFromRowsForTests(rows as any);
|
|
|
|
expect(facts.refs).toContain("5b516757-45d0-11e1-8c52-001e5848397d");
|
|
});
|
|
|
|
it("resolves names by guid references from ref-name pairs", () => {
|
|
const names = resolveOrganizationNamesByRefsForTests(
|
|
["5b516757-45d0-11e1-8c52-001e5848397d", "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa"],
|
|
{
|
|
names: ["OOO Alternativa Plus", "OOO Drugaya"],
|
|
refs: ["5b516757-45d0-11e1-8c52-001e5848397d", "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb"],
|
|
pairs: [
|
|
{ ref: "5b516757-45d0-11e1-8c52-001e5848397d", name: "OOO Alternativa Plus" },
|
|
{ ref: "bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb", name: "OOO Drugaya" }
|
|
]
|
|
} as any
|
|
);
|
|
|
|
expect(names).toEqual(["OOO Alternativa Plus"]);
|
|
});
|
|
});
|
|
|