NODEDC_1C/llm_normalizer/backend/tests/addressMcpClientEncoding.te...

77 lines
2.3 KiB
TypeScript
Raw Permalink 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 { afterEach, describe, expect, it, vi } from "vitest";
import { executeAddressMcpMetadata, executeAddressMcpQuery } from "../src/services/addressMcpClient";
const ORIGINAL_FETCH = globalThis.fetch;
afterEach(() => {
globalThis.fetch = ORIGINAL_FETCH;
vi.restoreAllMocks();
});
describe("address MCP encoding repair", () => {
it("repairs UTF-8/CP1251 mojibake in object rows", async () => {
const payload = {
success: true,
data: [
{
"Период": "2020-07-30T12:00:00Z",
"Регистратор": "Поступление на расчетный счет 0001",
"СчетДт": "51",
"СчетКт": "62.01",
"РЎСѓРјРјР°": "20000",
"Контрагент": "Группа СВК"
}
]
};
globalThis.fetch = vi.fn(async () =>
new Response(JSON.stringify(payload), {
status: 200,
headers: {
"content-type": "application/json"
}
})
) as typeof fetch;
const result = await executeAddressMcpQuery({
query: "SELECT 1",
limit: 20,
account_scope: []
});
expect(result.error).toBeNull();
expect(result.fetched_rows).toBe(1);
expect(result.rows[0]?.["Контрагент"]).toBe("Группа СВК");
expect(result.rows[0]?.["Регистратор"]).toContain("Поступление");
});
it("parses get_metadata text-table payload", async () => {
const payload = {
success: true,
data: `[2]{"FullName","Synonym"}:
Document.VATDoc,VAT document
Register.VATRegister,VAT register`
};
globalThis.fetch = vi.fn(async () =>
new Response(JSON.stringify(payload), {
status: 200,
headers: {
"content-type": "application/json"
}
})
) as typeof fetch;
const result = await executeAddressMcpMetadata({
meta_type: "Документ",
name_mask: "ндс",
limit: 10
});
expect(result.error).toBeNull();
expect(result.fetched_rows).toBe(2);
expect(result.rows[0]?.["FullName"]).toBe("Document.VATDoc");
expect(result.rows[0]?.["Synonym"]).toBe("VAT document");
});
});