type safety: complete catch(err:unknown) migration + extract admin routes
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 17m50s
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 17m50s
- All remaining catch(err) and catch(error) blocks now use : unknown across keys.ts, email.ts, usage.ts, index.ts (shutdown handlers) - Extract admin/usage routes from index.ts (459→391 lines) into new src/routes/admin.ts with authMiddleware + adminAuth per-route - Remove unused imports from index.ts (getConcurrencyStats, isProKey, getUsageForKey, getUsageStats, NextFunction) - 10 new TDD tests (7 error helper, 3 admin router) - 608 total tests, all passing
This commit is contained in:
parent
5a7ee79316
commit
c52dec2380
7 changed files with 153 additions and 82 deletions
19
src/__tests__/admin-routes.test.ts
Normal file
19
src/__tests__/admin-routes.test.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import { adminRouter } from "../routes/admin.js";
|
||||
|
||||
describe("admin router extraction", () => {
|
||||
it("exports adminRouter", () => {
|
||||
expect(adminRouter).toBeDefined();
|
||||
});
|
||||
|
||||
it("adminRouter is an Express Router", () => {
|
||||
// Express routers have a stack property
|
||||
expect((adminRouter as any).stack).toBeDefined();
|
||||
expect(Array.isArray((adminRouter as any).stack)).toBe(true);
|
||||
});
|
||||
|
||||
it("has routes registered", () => {
|
||||
const stack = (adminRouter as any).stack;
|
||||
expect(stack.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
35
src/__tests__/catch-type-safety.test.ts
Normal file
35
src/__tests__/catch-type-safety.test.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
import { describe, it, expect } from "vitest";
|
||||
import { errorMessage, errorCode } from "../utils/errors.js";
|
||||
|
||||
describe("catch type safety helpers", () => {
|
||||
it("errorMessage handles Error instances", () => {
|
||||
expect(errorMessage(new Error("test error"))).toBe("test error");
|
||||
});
|
||||
|
||||
it("errorMessage handles string errors", () => {
|
||||
expect(errorMessage("raw string error")).toBe("raw string error");
|
||||
});
|
||||
|
||||
it("errorMessage handles non-Error objects", () => {
|
||||
expect(errorMessage({ code: "ENOENT" })).toBe("[object Object]");
|
||||
});
|
||||
|
||||
it("errorMessage handles null/undefined", () => {
|
||||
expect(errorMessage(null)).toBe("null");
|
||||
expect(errorMessage(undefined)).toBe("undefined");
|
||||
});
|
||||
|
||||
it("errorCode extracts code from Error with code", () => {
|
||||
const err = Object.assign(new Error("fail"), { code: "ECONNREFUSED" });
|
||||
expect(errorCode(err)).toBe("ECONNREFUSED");
|
||||
});
|
||||
|
||||
it("errorCode returns undefined for plain Error", () => {
|
||||
expect(errorCode(new Error("no code"))).toBeUndefined();
|
||||
});
|
||||
|
||||
it("errorCode returns undefined for non-Error", () => {
|
||||
expect(errorCode("string error")).toBeUndefined();
|
||||
expect(errorCode(42)).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue