Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions apps/web/__tests__/ai-detect-recurring-pattern.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,6 @@ import { getEmailAccount } from "@/__tests__/helpers";
const TIMEOUT = 15_000;

vi.mock("server-only", () => ({}));
vi.mock("@/utils/logger", () => ({
createScopedLogger: () => ({
trace: vi.fn(),
error: vi.fn(),
}),
}));
vi.mock("@/utils/braintrust", () => ({
Braintrust: class {
insertToDataset() {}
Expand Down
13 changes: 13 additions & 0 deletions apps/web/__tests__/setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { vi } from "vitest";

// Mock next/server's after() to just run synchronously in tests
vi.mock("next/server", async () => {
const actual = await vi.importActual("next/server");
return {
...actual,
after: async (fn: () => void | Promise<void>) => {
// In tests, just run the function synchronously
return await fn();
},
};
Comment thread
coderabbitai[bot] marked this conversation as resolved.
});
9 changes: 3 additions & 6 deletions apps/web/app/api/ai/models/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ import OpenAI from "openai";
import prisma from "@/utils/prisma";
import { withEmailAccount } from "@/utils/middleware";
import { Provider } from "@/utils/llms/config";
import { createScopedLogger } from "@/utils/logger";

const logger = createScopedLogger("api/ai/models");

export type OpenAiModelsResponse = Awaited<ReturnType<typeof getOpenAiModels>>;

Expand All @@ -17,8 +14,8 @@ async function getOpenAiModels({ apiKey }: { apiKey: string }) {
return models.data;
}

export const GET = withEmailAccount(async (request) => {
const emailAccountId = request.auth.emailAccountId;
export const GET = withEmailAccount("api/ai/models", async (req) => {
const { emailAccountId } = req.auth;

const emailAccount = await prisma.emailAccount.findUnique({
where: { id: emailAccountId },
Expand All @@ -38,7 +35,7 @@ export const GET = withEmailAccount(async (request) => {
});
return NextResponse.json(result);
} catch (error) {
logger.error("Failed to get OpenAI models", { error });
req.logger.error("Failed to get OpenAI models", { error });
return NextResponse.json([]);
}
});
10 changes: 0 additions & 10 deletions apps/web/app/api/sso/signin/route.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,6 @@ vi.mock("@/utils/auth", () => ({
},
}));

// Mock the logger
vi.mock("@/utils/logger", () => ({
createScopedLogger: vi.fn(() => ({
info: vi.fn(),
error: vi.fn(),
})),
}));

// Mock Prisma
vi.mock("@/utils/prisma", () => ({
default: {
Expand All @@ -30,12 +22,10 @@ vi.mock("@/utils/prisma", () => ({
import { NextRequest } from "next/server";
import { beforeEach, describe, expect, test, vi } from "vitest";
import { betterAuthConfig } from "@/utils/auth";
import { createScopedLogger } from "@/utils/logger";
import prisma from "@/utils/prisma";
import { GET } from "./route";

const mockBetterAuthConfig = vi.mocked(betterAuthConfig);
const mockLogger = vi.mocked(createScopedLogger);

describe("SSO Signin Route", () => {
const mockContext = { params: Promise.resolve({}) };
Expand Down
7 changes: 0 additions & 7 deletions apps/web/utils/auth.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,6 @@ vi.mock("@/utils/error", () => ({
captureException: vi.fn(),
}));

vi.mock("@/utils/logger", () => ({
createScopedLogger: () => ({
info: vi.fn(),
error: vi.fn(),
}),
}));

// Import the real function from auth.ts for testing

describe("handleReferralOnSignUp", () => {
Expand Down
4 changes: 0 additions & 4 deletions apps/web/utils/cron.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,6 @@ vi.mock("@/env", () => ({
env: { CRON_SECRET: "test-secret-123" },
}));

vi.mock("@/utils/logger", () => ({
createScopedLogger: () => ({ error: vi.fn() }),
}));

describe("hasCronSecret", () => {
let request: Request;

Expand Down
8 changes: 0 additions & 8 deletions apps/web/utils/encryption.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,6 @@ import { encryptToken, decryptToken } from "./encryption";
// Mock server-only as it's required for tests
vi.mock("server-only", () => ({}));

// Mock the logger to prevent actual logging during tests
vi.mock("@/utils/logger", () => ({
createScopedLogger: () => ({
error: vi.fn(),
log: vi.fn(),
}),
}));

// Mock environment variables
vi.mock("@/env", () => ({
env: {
Expand Down
3 changes: 3 additions & 0 deletions apps/web/utils/logger.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export function createScopedLogger(scope: string) {
},
with: (newFields: Record<string, unknown>) =>
createLogger({ ...fields, ...newFields }),
flush: () => Promise.resolve(), // No-op for console logger
};
};

Expand Down Expand Up @@ -103,6 +104,7 @@ function createAxiomLogger(scope: string) {
},
with: (newFields: Record<string, unknown>) =>
createLogger({ ...fields, ...newFields }),
flush: () => log.flush(),
});

return createLogger();
Expand All @@ -115,6 +117,7 @@ function createNullLogger() {
warn: () => {},
trace: () => {},
with: () => createNullLogger(),
flush: () => Promise.resolve(),
};
}

Expand Down
Loading
Loading