feat: route invoice analysis through referentiel ia
This commit is contained in:
79
server/referentialIa.test.ts
Normal file
79
server/referentialIa.test.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import {
|
||||
invokeReferentialIa,
|
||||
testReferentialIaConnection,
|
||||
type ReferentielIaConnection,
|
||||
} from "./referentialIa";
|
||||
|
||||
const connection: ReferentielIaConnection = {
|
||||
baseUrl: "https://referentiel-ia.recette.santinova-soft.org",
|
||||
token: "test-token",
|
||||
};
|
||||
|
||||
function jsonResponse(body: unknown, status = 200) {
|
||||
return new Response(JSON.stringify(body), {
|
||||
status,
|
||||
headers: { "content-type": "application/json" },
|
||||
});
|
||||
}
|
||||
|
||||
describe("Référentiel IA", () => {
|
||||
it("transmet une requête OpenAI-compatible à la passerelle sélectionnée", async () => {
|
||||
let receivedUrl = "";
|
||||
let receivedInit: RequestInit | undefined;
|
||||
const result = await invokeReferentialIa(
|
||||
{
|
||||
messages: [{ role: "user", content: "Extrais la facture" }],
|
||||
max_tokens: 1200,
|
||||
},
|
||||
connection,
|
||||
async (url, init) => {
|
||||
receivedUrl = String(url);
|
||||
receivedInit = init;
|
||||
return jsonResponse({
|
||||
id: "ref-1",
|
||||
created: 1,
|
||||
model: "selected-by-reference",
|
||||
choices: [{ index: 0, message: { role: "assistant", content: "{}" }, finish_reason: "stop" }],
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
expect(receivedUrl).toBe("https://referentiel-ia.recette.santinova-soft.org/api/integration/v1/invoke");
|
||||
expect(receivedInit?.headers).toMatchObject({ authorization: "Bearer test-token" });
|
||||
expect(JSON.parse(String(receivedInit?.body))).toMatchObject({
|
||||
payload: {
|
||||
messages: [{ role: "user", content: "Extrais la facture" }],
|
||||
max_tokens: 1200,
|
||||
stream: false,
|
||||
},
|
||||
});
|
||||
expect(result.choices[0]?.message.content).toBe("{}");
|
||||
});
|
||||
|
||||
it("retourne un diagnostic non sensible lorsqu'aucun jeton n'est configuré", async () => {
|
||||
await expect(
|
||||
invokeReferentialIa({ messages: [{ role: "user", content: "test" }] }, { baseUrl: "", token: "" }),
|
||||
).rejects.toThrow("Référentiel IA");
|
||||
});
|
||||
|
||||
it("confirme le moteur choisi sans déclencher d'analyse de facture", async () => {
|
||||
const result = await testReferentialIaConnection(
|
||||
connection,
|
||||
async (_url, init) => {
|
||||
expect(JSON.parse(String(init?.body))).toEqual({
|
||||
useCase: "texte",
|
||||
optimizeCost: true,
|
||||
needsFreeTier: false,
|
||||
includeConnection: false,
|
||||
});
|
||||
return jsonResponse({
|
||||
application: { name: "Démat. Facturation DSI" },
|
||||
decision: { selected: { engine: { name: "Manus Forge", slug: "manus-forge" }, connection: undefined } },
|
||||
});
|
||||
},
|
||||
);
|
||||
|
||||
expect(result).toEqual({ applicationName: "Démat. Facturation DSI", engineName: "Manus Forge", model: null });
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user