Add comprehensive test suite for express modules
Tests for: - user.ts: User class, roles, permissions, status checks - util.ts: loadFile utility - handlers.ts: multiHandler - types.ts: methodParser, requireAuth, requirePermission - logging.ts: module structure - database.ts: connectionConfig, raw queries, PostgresAuthStore - auth/token.ts: generateToken, hashToken, parseAuthorizationHeader - auth/password.ts: hashPassword, verifyPassword (scrypt) - auth/types.ts: Zod parsers, Session class, tokenLifetimes - auth/store.ts: InMemoryAuthStore - auth/service.ts: AuthService (login, register, verify, reset) - basic/*.ts: route structure tests Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
24
express/basic/login.spec.ts
Normal file
24
express/basic/login.spec.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// Tests for basic/login.ts
|
||||
// These tests verify the route structure and export
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import { loginRoute } from "./login";
|
||||
|
||||
describe("basic/login", () => {
|
||||
describe("loginRoute", () => {
|
||||
it("has correct path", () => {
|
||||
assert.equal(loginRoute.path, "/login");
|
||||
});
|
||||
|
||||
it("handles GET and POST methods", () => {
|
||||
assert.ok(loginRoute.methods.includes("GET"));
|
||||
assert.ok(loginRoute.methods.includes("POST"));
|
||||
assert.equal(loginRoute.methods.length, 2);
|
||||
});
|
||||
|
||||
it("has a handler function", () => {
|
||||
assert.equal(typeof loginRoute.handler, "function");
|
||||
});
|
||||
});
|
||||
});
|
||||
24
express/basic/logout.spec.ts
Normal file
24
express/basic/logout.spec.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// Tests for basic/logout.ts
|
||||
// These tests verify the route structure and export
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import { logoutRoute } from "./logout";
|
||||
|
||||
describe("basic/logout", () => {
|
||||
describe("logoutRoute", () => {
|
||||
it("has correct path", () => {
|
||||
assert.equal(logoutRoute.path, "/logout");
|
||||
});
|
||||
|
||||
it("handles GET and POST methods", () => {
|
||||
assert.ok(logoutRoute.methods.includes("GET"));
|
||||
assert.ok(logoutRoute.methods.includes("POST"));
|
||||
assert.equal(logoutRoute.methods.length, 2);
|
||||
});
|
||||
|
||||
it("has a handler function", () => {
|
||||
assert.equal(typeof logoutRoute.handler, "function");
|
||||
});
|
||||
});
|
||||
});
|
||||
73
express/basic/routes.spec.ts
Normal file
73
express/basic/routes.spec.ts
Normal file
@@ -0,0 +1,73 @@
|
||||
// Tests for basic/routes.ts
|
||||
// These tests verify the route structure and exports
|
||||
|
||||
import assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
import { routes } from "./routes";
|
||||
|
||||
describe("basic/routes", () => {
|
||||
describe("routes object", () => {
|
||||
it("exports routes as an object", () => {
|
||||
assert.equal(typeof routes, "object");
|
||||
});
|
||||
|
||||
it("contains hello route", () => {
|
||||
assert.ok("hello" in routes);
|
||||
assert.equal(routes.hello.path, "/hello");
|
||||
assert.ok(routes.hello.methods.includes("GET"));
|
||||
});
|
||||
|
||||
it("contains home route", () => {
|
||||
assert.ok("home" in routes);
|
||||
assert.equal(routes.home.path, "/");
|
||||
assert.ok(routes.home.methods.includes("GET"));
|
||||
});
|
||||
|
||||
it("contains login route", () => {
|
||||
assert.ok("login" in routes);
|
||||
assert.equal(routes.login.path, "/login");
|
||||
});
|
||||
|
||||
it("contains logout route", () => {
|
||||
assert.ok("logout" in routes);
|
||||
assert.equal(routes.logout.path, "/logout");
|
||||
});
|
||||
|
||||
it("all routes have handlers", () => {
|
||||
for (const [name, route] of Object.entries(routes)) {
|
||||
assert.equal(
|
||||
typeof route.handler,
|
||||
"function",
|
||||
`Route ${name} should have a handler function`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("all routes have methods array", () => {
|
||||
for (const [name, route] of Object.entries(routes)) {
|
||||
assert.ok(
|
||||
Array.isArray(route.methods),
|
||||
`Route ${name} should have methods array`,
|
||||
);
|
||||
assert.ok(
|
||||
route.methods.length > 0,
|
||||
`Route ${name} should have at least one method`,
|
||||
);
|
||||
}
|
||||
});
|
||||
|
||||
it("all routes have path string", () => {
|
||||
for (const [name, route] of Object.entries(routes)) {
|
||||
assert.equal(
|
||||
typeof route.path,
|
||||
"string",
|
||||
`Route ${name} should have a path string`,
|
||||
);
|
||||
assert.ok(
|
||||
route.path.startsWith("/"),
|
||||
`Route ${name} path should start with /`,
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user