fix: update database queries to use 'template' instead of 'template_id' and adjust related references in ai_generate_plan function
This commit is contained in:
@@ -53,7 +53,9 @@ Deno.test("ai_generate_plan creates plan and returns structured data", async ()
|
||||
.select("id")
|
||||
.limit(1)
|
||||
.single();
|
||||
if (carreraError) throw new Error("Failed to fetch carrera: " + carreraError.message);
|
||||
if (carreraError) {
|
||||
throw new Error("Failed to fetch carrera: " + carreraError.message);
|
||||
}
|
||||
if (!carrera) throw new Error("No carrera found");
|
||||
|
||||
const datosBasicos = {
|
||||
@@ -94,38 +96,49 @@ Deno.test("ai_generate_plan creates plan and returns structured data", async ()
|
||||
);
|
||||
assertEquals(data.plan_datos.duracion_del_ciclo_escolar, "16"); // Semestre -> 16
|
||||
});
|
||||
/*
|
||||
Deno.test("ai-structured (multipart + file)", async () => {
|
||||
|
||||
Deno.test("ai_generate_plan (multipart with files)", async () => {
|
||||
const { client, accessToken } = await getAuthedClient();
|
||||
|
||||
// Lee un PDF local (ajusta path)
|
||||
const bytes = await Deno.readFile("files/carta.pdf");
|
||||
const file = new File([bytes], "carta.pdf", { type: "application/pdf" });
|
||||
const { data: carrera, error: carreraError } = await client
|
||||
.from("carreras")
|
||||
.select("id")
|
||||
.limit(1)
|
||||
.single();
|
||||
if (carreraError) {
|
||||
throw new Error("Failed to fetch carrera: " + carreraError.message);
|
||||
}
|
||||
if (!carrera) throw new Error("No carrera found");
|
||||
|
||||
const datosBasicos = {
|
||||
nombrePlan: "Plan de estudios generado con referencias",
|
||||
carreraId: carrera.id,
|
||||
nivel: "Maestría",
|
||||
tipoCiclo: "Semestre",
|
||||
numCiclos: 4,
|
||||
};
|
||||
|
||||
const iaConfig = {
|
||||
descripcionEnfoque: "Programa de postgrado enfocado en tecnología",
|
||||
notasAdicionales: "Considerar tendencias actuales en IA",
|
||||
};
|
||||
|
||||
// Create a simple test file
|
||||
const fileContent = "Sample curriculum reference document";
|
||||
const file = new File([fileContent], "reference.txt", { type: "text/plain" });
|
||||
|
||||
const payload = {
|
||||
response: { input: "Resume estos documentos en JSON.", model: "gpt-5" },
|
||||
structured: {
|
||||
type: "json_schema",
|
||||
name: "resumen",
|
||||
strict: true,
|
||||
schema: {
|
||||
type: "object",
|
||||
properties: { resumen: { type: "string" } },
|
||||
required: ["resumen"],
|
||||
additionalProperties: false,
|
||||
},
|
||||
},
|
||||
storage: { prefix: "tmp" },
|
||||
datosBasicos,
|
||||
iaConfig,
|
||||
};
|
||||
|
||||
const fd = new FormData();
|
||||
fd.append("payload", JSON.stringify(payload));
|
||||
fd.append("files", file);
|
||||
|
||||
const { data, error } = await client.functions.invoke("ai-structured", {
|
||||
const { data, error } = await client.functions.invoke("ai_generate_plan", {
|
||||
headers: {
|
||||
Authorization: `Bearer ${accessToken}`, // 👈 necesario
|
||||
// NO pongas Content-Type: fetch lo setea con boundary para FormData ✅
|
||||
Authorization: `Bearer ${accessToken}`,
|
||||
},
|
||||
method: "POST",
|
||||
body: fd,
|
||||
@@ -135,10 +148,11 @@ Deno.test("ai-structured (multipart + file)", async () => {
|
||||
assert(data, "Expected data from function");
|
||||
|
||||
assertEquals(data.ok, true);
|
||||
assert(typeof data.output?.resumen === "string");
|
||||
assert(data.output.resumen.length > 0);
|
||||
assert(data.plan);
|
||||
assertEquals(data.plan.nombre, datosBasicos.nombrePlan);
|
||||
assertEquals(data.plan.nivel, "Maestría");
|
||||
assertEquals(data.plan.numero_ciclos, datosBasicos.numCiclos);
|
||||
|
||||
// opcional: valida que registró upload(s) a storage
|
||||
assert(Array.isArray(data.references?.uploadedToStorage));
|
||||
assert(data.references);
|
||||
assertEquals(data.references.tempFilesCount, 1);
|
||||
});
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user