mirror of
https://github.com/DayuanJiang/next-ai-draw-io.git
synced 2026-10-07 18:27:47 +08:00
package.json moved to Biome 2.5.7 but the auto-format job stayed on 2.4.13. The two format some files differently, so on this PR the bot reformatted tests/unit/log-save-route.test.ts with 2.4.13 and the lint job, on 2.5.7, then failed on it. The pin now matches package.json, as its comment asks, and the file is back in 2.5.7's format.
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
// @vitest-environment node
|
|
import { describe, expect, it, vi } from "vitest"
|
|
import { POST as logSave } from "@/app/api/log-save/route"
|
|
|
|
// A Langfuse client with a trace to attach the save score to
|
|
const batch = vi.fn(async () => ({}))
|
|
vi.mock("@/lib/langfuse", () => ({
|
|
getLangfuseClient: () => ({
|
|
api: {
|
|
trace: { list: async () => ({ data: [{ id: "trace-1" }] }) },
|
|
ingestion: { batch },
|
|
},
|
|
}),
|
|
}))
|
|
|
|
function post(body: unknown): Request {
|
|
return new Request("http://localhost/api/log-save", {
|
|
method: "POST",
|
|
headers: { "Content-Type": "application/json" },
|
|
body: JSON.stringify(body),
|
|
})
|
|
}
|
|
|
|
describe("POST /api/log-save", () => {
|
|
it.each(["drawio", "png", "svg", "xmlsvg"])(
|
|
"logs a save in %s format",
|
|
async (format) => {
|
|
const res = await logSave(
|
|
post({ filename: "diagram", format, sessionId: "s1" }),
|
|
)
|
|
expect(res.status).toBe(200)
|
|
expect(await res.json()).toEqual({ success: true, logged: true })
|
|
},
|
|
)
|
|
|
|
it("rejects an unknown format", async () => {
|
|
const res = await logSave(
|
|
post({ filename: "diagram", format: "pdf", sessionId: "s1" }),
|
|
)
|
|
expect(res.status).toBe(400)
|
|
})
|
|
})
|