fix: resolve all TypeScript strict-mode errors in test files
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 21m52s
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 21m52s
- convert-sanitized: use 'as Record' cast for optional mock call args - error-responses: fix module path (database.js → db.js) and mock return type - recover-initial-db-fallback: fix mock return type (undefined → true) - render-timing: remove non-existent .prepare property check - usage-flush: cast mock request objects to any for test setup Zero tsc --noEmit errors. 608 tests passing.
This commit is contained in:
parent
c52dec2380
commit
54316d45cf
5 changed files with 13 additions and 13 deletions
|
|
@ -38,7 +38,7 @@ describe("convert routes use sanitized PDF options", () => {
|
||||||
.send({ html: "<h1>Test</h1>", format: "a4" });
|
.send({ html: "<h1>Test</h1>", format: "a4" });
|
||||||
|
|
||||||
expect(vi.mocked(renderPdf)).toHaveBeenCalledOnce();
|
expect(vi.mocked(renderPdf)).toHaveBeenCalledOnce();
|
||||||
const opts = vi.mocked(renderPdf).mock.calls[0][1];
|
const opts = vi.mocked(renderPdf).mock.calls[0]![1] as Record<string, unknown>;
|
||||||
expect(opts.format).toBe("A4");
|
expect(opts.format).toBe("A4");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -51,7 +51,7 @@ describe("convert routes use sanitized PDF options", () => {
|
||||||
.send({ markdown: "# Test", format: "letter" });
|
.send({ markdown: "# Test", format: "letter" });
|
||||||
|
|
||||||
expect(vi.mocked(renderPdf)).toHaveBeenCalledOnce();
|
expect(vi.mocked(renderPdf)).toHaveBeenCalledOnce();
|
||||||
const opts = vi.mocked(renderPdf).mock.calls[0][1];
|
const opts = vi.mocked(renderPdf).mock.calls[0]![1] as Record<string, unknown>;
|
||||||
expect(opts.format).toBe("Letter");
|
expect(opts.format).toBe("Letter");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -64,7 +64,7 @@ describe("convert routes use sanitized PDF options", () => {
|
||||||
.send({ url: "https://example.com", format: "a3" });
|
.send({ url: "https://example.com", format: "a3" });
|
||||||
|
|
||||||
expect(vi.mocked(renderUrlPdf)).toHaveBeenCalledOnce();
|
expect(vi.mocked(renderUrlPdf)).toHaveBeenCalledOnce();
|
||||||
const opts = vi.mocked(renderUrlPdf).mock.calls[0][1];
|
const opts = vi.mocked(renderUrlPdf).mock.calls[0]![1] as Record<string, unknown>;
|
||||||
expect(opts.format).toBe("A3");
|
expect(opts.format).toBe("A3");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
@ -79,7 +79,7 @@ describe("demo routes use sanitized PDF options", () => {
|
||||||
.send({ html: "<h1>Test</h1>", format: "a4" });
|
.send({ html: "<h1>Test</h1>", format: "a4" });
|
||||||
|
|
||||||
expect(vi.mocked(renderPdf)).toHaveBeenCalledOnce();
|
expect(vi.mocked(renderPdf)).toHaveBeenCalledOnce();
|
||||||
const opts = vi.mocked(renderPdf).mock.calls[0][1];
|
const opts = vi.mocked(renderPdf).mock.calls[0]![1] as Record<string, unknown>;
|
||||||
expect(opts.format).toBe("A4");
|
expect(opts.format).toBe("A4");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
@ -92,7 +92,7 @@ describe("demo routes use sanitized PDF options", () => {
|
||||||
.send({ markdown: "# Test", format: "a4" });
|
.send({ markdown: "# Test", format: "a4" });
|
||||||
|
|
||||||
expect(vi.mocked(renderPdf)).toHaveBeenCalledOnce();
|
expect(vi.mocked(renderPdf)).toHaveBeenCalledOnce();
|
||||||
const opts = vi.mocked(renderPdf).mock.calls[0][1];
|
const opts = vi.mocked(renderPdf).mock.calls[0]![1] as Record<string, unknown>;
|
||||||
expect(opts.format).toBe("A4");
|
expect(opts.format).toBe("A4");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -226,12 +226,12 @@ describe("Error Response Security - Admin Cleanup", () => {
|
||||||
const mockAdminAuth = (req: any, res: any, next: any) => next();
|
const mockAdminAuth = (req: any, res: any, next: any) => next();
|
||||||
|
|
||||||
// Mock database functions
|
// Mock database functions
|
||||||
vi.mock("../services/database.js", () => ({
|
vi.mock("../services/db.js", () => ({
|
||||||
cleanupStaleData: vi.fn(),
|
cleanupStaleData: vi.fn(),
|
||||||
}));
|
}));
|
||||||
|
|
||||||
const { cleanupStaleData } = await import("../services/database.js");
|
const { cleanupStaleData } = await import("../services/db.js");
|
||||||
vi.mocked(cleanupStaleData).mockResolvedValue({ deletedCount: 5 });
|
vi.mocked(cleanupStaleData).mockResolvedValue({ expiredVerifications: 3, orphanedUsage: 2 });
|
||||||
|
|
||||||
// Create minimal app
|
// Create minimal app
|
||||||
app = express();
|
app = express();
|
||||||
|
|
@ -250,7 +250,7 @@ describe("Error Response Security - Admin Cleanup", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it("does not expose error message (no 'message' field)", async () => {
|
it("does not expose error message (no 'message' field)", async () => {
|
||||||
const { cleanupStaleData } = await import("../services/database.js");
|
const { cleanupStaleData } = await import("../services/db.js");
|
||||||
const internalError = new Error("Database connection pool exhausted");
|
const internalError = new Error("Database connection pool exhausted");
|
||||||
vi.mocked(cleanupStaleData).mockRejectedValue(internalError);
|
vi.mocked(cleanupStaleData).mockRejectedValue(internalError);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -63,7 +63,7 @@ describe("POST /v1/recover DB fallback (BUG-110)", () => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
mockGetAllKeys.mockReturnValue([]);
|
mockGetAllKeys.mockReturnValue([]);
|
||||||
mockCreatePending.mockResolvedValue({ code: "123456" } as any);
|
mockCreatePending.mockResolvedValue({ code: "123456" } as any);
|
||||||
mockSendEmail.mockResolvedValue(undefined);
|
mockSendEmail.mockResolvedValue(true);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("sends verification email via DB fallback when key not in cache but exists in DB", async () => {
|
it("sends verification email via DB fallback when key not in cache but exists in DB", async () => {
|
||||||
|
|
|
||||||
|
|
@ -108,7 +108,7 @@ describe("PDF render timing", () => {
|
||||||
vi.mocked(renderPdf).mockResolvedValue({ pdf: Buffer.from("%PDF-1.4 mock"), durationMs: 30 } as any);
|
vi.mocked(renderPdf).mockResolvedValue({ pdf: Buffer.from("%PDF-1.4 mock"), durationMs: 30 } as any);
|
||||||
|
|
||||||
const dbMod = await import("../services/db.js");
|
const dbMod = await import("../services/db.js");
|
||||||
if (vi.isMockFunction(dbMod.default?.prepare)) {
|
if (vi.isMockFunction((dbMod as Record<string, unknown>).default)) {
|
||||||
// db is already mocked elsewhere
|
// db is already mocked elsewhere
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,8 @@ describe("flushDirtyEntries – independent key flushing", () => {
|
||||||
const next = vi.fn();
|
const next = vi.fn();
|
||||||
const res = { status: vi.fn(() => ({ json: vi.fn() })) };
|
const res = { status: vi.fn(() => ({ json: vi.fn() })) };
|
||||||
|
|
||||||
usageMod.usageMiddleware({ apiKeyInfo: { key: "key-good" } }, res, next);
|
usageMod.usageMiddleware({ apiKeyInfo: { key: "key-good" } } as any, res as any, next);
|
||||||
usageMod.usageMiddleware({ apiKeyInfo: { key: "key-bad" } }, res, next);
|
usageMod.usageMiddleware({ apiKeyInfo: { key: "key-bad" } } as any, res as any, next);
|
||||||
|
|
||||||
// Track which keys were successfully upserted
|
// Track which keys were successfully upserted
|
||||||
const flushedKeys: string[] = [];
|
const flushedKeys: string[] = [];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue