NODEDC_1C/llm_normalizer/backend/tests/addressInventoryPurchaseDoc...

104 lines
5.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";
const { executeAddressMcpQueryMock } = vi.hoisted(() => ({
executeAddressMcpQueryMock: vi.fn()
}));
vi.mock("../src/services/addressMcpClient", async () => {
const actual = await vi.importActual<typeof import("../src/services/addressMcpClient")>(
"../src/services/addressMcpClient"
);
return {
...actual,
executeAddressMcpQuery: executeAddressMcpQueryMock
};
});
import { AddressQueryService } from "../src/services/addressQueryService";
afterEach(() => {
executeAddressMcpQueryMock.mockReset();
vi.restoreAllMocks();
});
describe("inventory purchase provenance document route", () => {
it("uses document purchase route with native item resolution and snapshot upper bound for selected-object provenance", async () => {
executeAddressMcpQueryMock.mockResolvedValueOnce({
fetched_rows: 2,
matched_rows: 2,
raw_rows: [
{
Period: "2015-08-14T12:00:00Z",
Registrator: "Поступление товаров и услуг 00000000011 от 14.08.2015 12:00:00",
AccountDt: "41.01",
AccountKt: "",
Amount: 347680,
Quantity: 1,
Item: "Рабочая станция универсального специалиста (индивидуальное изготовление)",
Counterparty: "Мебельная ф-ка №1",
Contract: "Договор поставки № 5 от 10.08.2015",
Organization: "ООО \\Альтернатива Плюс\\"
},
{
Period: "2015-09-10T12:00:00Z",
Registrator: "Поступление товаров и услуг 00000000017 от 10.09.2015 12:00:00",
AccountDt: "41.01",
AccountKt: "",
Amount: 347680,
Quantity: 1,
Item: "Рабочая станция универсального специалиста (индивидуальное изготовление)",
Counterparty: "Авант мебель, ООО",
Contract: "Договор поставки № 8 от 01.09.2015",
Organization: "ООО \\Альтернатива Плюс\\"
}
],
rows: [],
error: null
});
const service = new AddressQueryService();
const result = await service.tryHandle(
'По выбранному объекту "Рабочая станция универсального специалиста (индивидуальное изготовление)": у кого куплено',
{
followupContext: {
previous_intent: "inventory_on_hand_as_of_date",
previous_filters: {
as_of_date: "2016-01-31",
period_from: "2016-01-01",
period_to: "2016-01-31",
organization: "ООО \\Альтернатива Плюс\\"
},
previous_anchor_type: "organization",
previous_anchor_value: "ООО \\Альтернатива Плюс\\"
}
}
);
expect(result?.handled).toBe(true);
expect(result?.response_type).toBe("FACTUAL_SUMMARY");
expect(result?.debug.detected_intent).toBe("inventory_purchase_provenance_for_item");
expect(result?.debug.selected_recipe).toBe("address_inventory_purchase_provenance_for_item_v1");
expect(result?.debug.extracted_filters?.item).toBe(
"Рабочая станция универсального специалиста (индивидуальное изготовление)"
);
expect(result?.debug.extracted_filters?.as_of_date).toBe("2016-01-31");
expect(result?.debug.reasons ?? []).not.toContain("lifecycle_execution_detached_from_snapshot_date");
expect(result?.debug.reasons ?? []).not.toContain("as_of_date_cleared_for_history_recovery");
expect(String(result?.reply_text ?? "")).toContain("до 31.01.2016 подтвержден поставщик");
expect(String(result?.reply_text ?? "")).toContain("Авант мебель, ООО");
expect(String(result?.reply_text ?? "")).toContain("Для ответа учтены закупочные документы не позже 31.01.2016.");
expect(executeAddressMcpQueryMock).toHaveBeenCalledTimes(1);
const query = String(executeAddressMcpQueryMock.mock.calls[0]?.[0]?.query ?? "");
expect(query).toContain("Документ.ПоступлениеТоваровУслуг.Товары КАК Товары");
expect(query).toContain("Товары.Номенклатура В (ВЫБРАТЬ Номенклатура.Ссылка");
expect(query).toContain(
'Номенклатура.Наименование = "Рабочая станция универсального специалиста (индивидуальное изготовление)"'
);
expect(query).toContain("Товары.Ссылка.Дата <= ДАТАВРЕМЯ(2016, 1, 31, 23, 59, 59)");
expect(query).toContain("ПРЕДСТАВЛЕНИЕ(Товары.Ссылка.Контрагент) КАК Контрагент");
expect(query).toContain("ПРЕДСТАВЛЕНИЕ(Товары.Ссылка.Организация) КАК Организация");
expect(query).not.toContain("РегистрБухгалтерии.Хозрасчетный.ДвиженияССубконто");
});
});