Files
DeepTutor/web/tests/reading-notebook-capture.test.ts
Mohammad Hijjawi 151a7292fe fix: post reading workspace "Save to notebook" to the backend route
sendReadingToNotebook posted to /api/reading/workspaces/{id}/notebooks,
but the backend only registers POST /api/reading/workspaces/{id}/notebook
(capture_reading_to_notebook), so saving a reading workspace to a notebook
always failed with 404 Not Found. Point the client at the real route and add
a test that checks the path against the generated OpenAPI contract.
2026-09-28 13:50:05 +01:00

24 lines
846 B
TypeScript

import assert from "node:assert/strict";
import fs from "node:fs";
import path from "node:path";
import test from "node:test";
function source(file: string): string {
return fs.readFileSync(path.resolve(process.cwd(), file), "utf8");
}
test("save to notebook posts to the backend's workspace notebook route", () => {
const client = source("lib/reading-workspace-api.ts");
const fn = client.slice(
client.indexOf("export async function sendReadingToNotebook"),
);
const match = fn.match(/json\(`(\/workspaces\/\$\{workspaceId\}\/[^`]+)`/);
assert.ok(match, "sendReadingToNotebook should call json() with a path");
const route = `/api/reading${match[1].replace("${workspaceId}", "{workspace_id}")}`;
assert.ok(
source("contracts/generated/api.ts").includes(`"${route}":`),
`${route} is not a backend route`,
);
});