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

48 lines
1.5 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 { afterEach, describe, expect, it, vi } from "vitest";
import { 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("Поступление");
});
});