ci: add pull request quality gates
CI / install-and-build (pull_request) Successful in 1m29s
CI / format (pull_request) Successful in 51s
CI / typecheck-source (pull_request) Successful in 41s
CI / typecheck-tests (pull_request) Successful in 39s
CI / test (pull_request) Successful in 51s
CI / lint (pull_request) Successful in 21s
CI / install-and-build (pull_request) Successful in 1m29s
CI / format (pull_request) Successful in 51s
CI / typecheck-source (pull_request) Successful in 41s
CI / typecheck-tests (pull_request) Successful in 39s
CI / test (pull_request) Successful in 51s
CI / lint (pull_request) Successful in 21s
Co-Authored-By: gpt-5.6-terra <noreply@openai.com>
This commit was merged in pull request #12.
This commit is contained in:
+20
-14
@@ -8,7 +8,7 @@ import { jsonBody } from "../../src/webapi/middleware/jsonBody.js";
|
||||
|
||||
async function request(
|
||||
url: string,
|
||||
opts: { method?: string; body?: unknown; contentType?: string } = {}
|
||||
opts: { method?: string; body?: unknown; contentType?: string } = {},
|
||||
): Promise<{ status: number; body: unknown }> {
|
||||
const method = opts.method ?? "POST";
|
||||
const bodyStr =
|
||||
@@ -21,18 +21,19 @@ async function request(
|
||||
const res = await fetch(url, { method, headers, body: bodyStr });
|
||||
const text = await res.text();
|
||||
let parsed: unknown;
|
||||
try { parsed = JSON.parse(text); } catch { parsed = text; }
|
||||
try {
|
||||
parsed = JSON.parse(text);
|
||||
} catch {
|
||||
parsed = text;
|
||||
}
|
||||
return { status: res.status, body: parsed };
|
||||
}
|
||||
|
||||
async function makeTestServer() {
|
||||
const failValidator = Object.assign(
|
||||
(_obj: unknown): _obj is never => false,
|
||||
{
|
||||
errors: [{ message: "required" }] as unknown[],
|
||||
schema: { $id: "test-schema", title: "Test", description: "" },
|
||||
}
|
||||
);
|
||||
const failValidator = Object.assign((_obj: unknown): _obj is never => false, {
|
||||
errors: [{ message: "required" }] as unknown[],
|
||||
schema: { $id: "test-schema", title: "Test", description: "" },
|
||||
});
|
||||
|
||||
const app = new Koa();
|
||||
const router = new KoaRouter();
|
||||
@@ -48,7 +49,7 @@ async function makeTestServer() {
|
||||
async (ctx) => {
|
||||
ctx.status = 200;
|
||||
ctx.body = { ok: true };
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
router.post(
|
||||
@@ -57,7 +58,7 @@ async function makeTestServer() {
|
||||
async (ctx) => {
|
||||
ctx.status = 200;
|
||||
ctx.body = { ok: true, body: ctx.request.body };
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
app.use(router.routes());
|
||||
@@ -69,7 +70,7 @@ async function makeTestServer() {
|
||||
const url = `http://127.0.0.1:${port}`;
|
||||
const close = () =>
|
||||
new Promise<void>((resolve, reject) =>
|
||||
server.close((err) => (err ? reject(err) : resolve()))
|
||||
server.close((err) => (err ? reject(err) : resolve())),
|
||||
);
|
||||
return { url, close };
|
||||
}
|
||||
@@ -107,11 +108,16 @@ describe("jsonBody middleware", () => {
|
||||
});
|
||||
|
||||
it("failing validator → 400 jsonchema_validation_failed with schema and errors", async () => {
|
||||
const res = await request(url + "/fail-validate", { body: { any: "thing" } });
|
||||
const res = await request(url + "/fail-validate", {
|
||||
body: { any: "thing" },
|
||||
});
|
||||
assert.equal(res.status, 400);
|
||||
assert.equal((res.body as any).error, "jsonchema_validation_failed");
|
||||
assert.ok((res.body as any).schema, "response includes schema");
|
||||
assert.ok(Array.isArray((res.body as any).errors), "response includes errors");
|
||||
assert.ok(
|
||||
Array.isArray((res.body as any).errors),
|
||||
"response includes errors",
|
||||
);
|
||||
});
|
||||
|
||||
it("includeParams: param absent from body → merged in", async () => {
|
||||
|
||||
Reference in New Issue
Block a user