test: enforce RQ Score API contract
This commit is contained in:
23
scripts/rq-score-contract.test.ts
Normal file
23
scripts/rq-score-contract.test.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
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/0015_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");
|
||||
Reference in New Issue
Block a user