fix(15): convert auth service/tests to async PGlite pattern
The executor agents wrote sync SQLite-style calls (.get(), .all(), .run()) instead of the async Postgres pattern established in Phase 14. Fixed: - auth.service.ts: use await + destructuring for all DB operations - auth routes: await listApiKeys - All auth test files: async createTestDb(), await service calls Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -21,10 +21,10 @@ mock.module("../../src/server/services/oauth.service", () => ({
|
||||
// Import middleware AFTER mocks are set up
|
||||
const { requireAuth } = await import("../../src/server/middleware/auth");
|
||||
|
||||
let db: ReturnType<typeof createTestDb>;
|
||||
let db: Awaited<ReturnType<typeof createTestDb>>;
|
||||
|
||||
beforeEach(() => {
|
||||
db = createTestDb();
|
||||
beforeEach(async () => {
|
||||
db = await createTestDb();
|
||||
mockGetAuth.mockReset();
|
||||
mockGetAuth.mockReturnValue(null);
|
||||
mockVerifyAccessToken.mockReset();
|
||||
|
||||
@@ -20,8 +20,8 @@ mock.module("../../src/server/services/oauth.service", () => ({
|
||||
// Import routes AFTER mocks
|
||||
const { authRoutes } = await import("../../src/server/routes/auth.ts");
|
||||
|
||||
function createTestApp() {
|
||||
const db = createTestDb();
|
||||
async function createTestApp() {
|
||||
const db = await createTestDb();
|
||||
const app = new Hono<{ Variables: { db?: any } }>();
|
||||
|
||||
app.use("*", async (c, next) => {
|
||||
@@ -35,10 +35,10 @@ function createTestApp() {
|
||||
|
||||
describe("Auth Routes", () => {
|
||||
let app: Hono;
|
||||
let db: ReturnType<typeof createTestDb>;
|
||||
let db: Awaited<ReturnType<typeof createTestDb>>;
|
||||
|
||||
beforeEach(() => {
|
||||
const testApp = createTestApp();
|
||||
beforeEach(async () => {
|
||||
const testApp = await createTestApp();
|
||||
app = testApp.app;
|
||||
db = testApp.db;
|
||||
mockGetAuth.mockReset();
|
||||
|
||||
@@ -8,10 +8,10 @@ import {
|
||||
import { createTestDb } from "../helpers/db.ts";
|
||||
|
||||
describe("Auth Service", () => {
|
||||
let db: ReturnType<typeof createTestDb>;
|
||||
let db: Awaited<ReturnType<typeof createTestDb>>;
|
||||
|
||||
beforeEach(() => {
|
||||
db = createTestDb();
|
||||
beforeEach(async () => {
|
||||
db = await createTestDb();
|
||||
});
|
||||
|
||||
describe("API Key Management", () => {
|
||||
@@ -41,7 +41,7 @@ describe("Auth Service", () => {
|
||||
|
||||
it("deletes key so it is no longer valid", async () => {
|
||||
const result = await createApiKey(db, "test-key");
|
||||
deleteApiKey(db, result.id);
|
||||
await deleteApiKey(db, result.id);
|
||||
|
||||
const isValid = await verifyApiKey(db, result.rawKey);
|
||||
expect(isValid).toBe(false);
|
||||
@@ -51,7 +51,7 @@ describe("Auth Service", () => {
|
||||
await createApiKey(db, "key-one");
|
||||
await createApiKey(db, "key-two");
|
||||
|
||||
const keys = listApiKeys(db);
|
||||
const keys = await listApiKeys(db);
|
||||
expect(keys).toHaveLength(2);
|
||||
expect(keys[0].name).toBe("key-one");
|
||||
expect(keys[1].name).toBe("key-two");
|
||||
|
||||
Reference in New Issue
Block a user