Files
growqr-backend/scripts/rq-score-contract.test.ts

24 lines
1.5 KiB
TypeScript

import assert from "node:assert/strict";
import { readFile } from "node:fs/promises";
const [proxy, latestRoute, servicesRoute, schema, migration, homeTypes] = await Promise.all([
readFile(new URL("../src/services/qscore-proxy.ts", import.meta.url), "utf8"),
readFile(new URL("../src/v1/qscore/qscore-routes.ts", import.meta.url), "utf8"),
readFile(new URL("../src/routes/services.ts", import.meta.url), "utf8"),
readFile(new URL("../src/db/schema.ts", import.meta.url), "utf8"),
readFile(new URL("../drizzle/0016_rq_score_snapshot.sql", import.meta.url), "utf8"),
readFile(new URL("../src/home/types.ts", import.meta.url), "utf8"),
]);
assert.match(proxy, /const rqScore = body\.rq_score;/, "service proxy must require rq_score");
assert.doesNotMatch(proxy, /body\.q_score/, "service proxy must not accept the old q_score field");
assert.match(latestRoute, /rq_score: result\.rq_score/, "latest API must expose rq_score");
assert.doesNotMatch(latestRoute, /\bscore: result\.rq_score/, "latest API must not alias RQ Score as score");
assert.match(servicesRoute, /rq_score: rqScore/, "gateway API must expose rq_score");
assert.match(schema, /rqScore: integer\("rq_score"\)/, "snapshot schema must map rq_score");
assert.match(migration, /RENAME COLUMN "score" TO "rq_score"/, "migration must preserve snapshot data while renaming the column");
assert.match(homeTypes, /rqScore: \{ from:/, "home API must expose rqScore");
assert.doesNotMatch(homeTypes, /\bqx:/, "home API must not expose the old qx field");
console.log("rq score API and database contract: ok");