mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-06-22 04:11:55 +10:00
@@ -374,7 +374,6 @@ const getAuthConfig = () => {
|
||||
genericOAuth({ config: authConfigs }),
|
||||
twoFactor({ issuer: "Reactive Resume" }),
|
||||
apiKey({ enableSessionForAPIKeys: true, rateLimit: rateLimitConfig.betterAuth.apiKey }),
|
||||
dash({ apiKey: env.BETTER_AUTH_API_KEY, activityTracking: { enabled: true } }),
|
||||
oauthProvider({
|
||||
loginPage: "/auth/oauth",
|
||||
consentPage: "/auth/oauth",
|
||||
@@ -394,6 +393,9 @@ const getAuthConfig = () => {
|
||||
usernameValidator: (username) => /^[a-z0-9._-]+$/.test(username),
|
||||
validationOrder: { username: "post-normalization", displayUsername: "post-normalization" },
|
||||
}),
|
||||
...(env.BETTER_AUTH_API_KEY
|
||||
? [dash({ apiKey: env.BETTER_AUTH_API_KEY, activityTracking: { enabled: true } })]
|
||||
: []),
|
||||
],
|
||||
});
|
||||
};
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
import { ORPCError } from "@orpc/client";
|
||||
import { beforeEach, describe, expect, it, vi } from "vite-plus/test";
|
||||
|
||||
type StatisticsRow = {
|
||||
isPublic: boolean;
|
||||
views: number | null;
|
||||
downloads: number | null;
|
||||
lastViewedAt: Date | null;
|
||||
lastDownloadedAt: Date | null;
|
||||
};
|
||||
|
||||
const where = vi.fn<() => Promise<StatisticsRow[]>>();
|
||||
const rightJoin = vi.fn<() => { where: typeof where }>(() => ({ where }));
|
||||
const from = vi.fn<() => { rightJoin: typeof rightJoin }>(() => ({ rightJoin }));
|
||||
const select = vi.fn<() => { from: typeof from }>(() => ({ from }));
|
||||
|
||||
vi.mock("@/integrations/drizzle/client", () => ({
|
||||
db: {
|
||||
select,
|
||||
},
|
||||
}));
|
||||
|
||||
const { resumeService } = await import("./resume");
|
||||
|
||||
describe("resumeService.statistics.getById", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("throws not found when the resume does not exist for the user", async () => {
|
||||
where.mockResolvedValueOnce([]);
|
||||
|
||||
try {
|
||||
await resumeService.statistics.getById({ id: "resume-1", userId: "user-1" });
|
||||
throw new Error("Expected statistics lookup to throw");
|
||||
} catch (error) {
|
||||
expect(error).toBeInstanceOf(ORPCError);
|
||||
expect(error).toMatchObject({ code: "NOT_FOUND" });
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -50,6 +50,8 @@ const statistics = {
|
||||
.rightJoin(schema.resume, eq(schema.resumeStatistics.resumeId, schema.resume.id))
|
||||
.where(and(eq(schema.resume.id, input.id), eq(schema.resume.userId, input.userId)));
|
||||
|
||||
if (!statistics) throw new ORPCError("NOT_FOUND");
|
||||
|
||||
return {
|
||||
isPublic: statistics.isPublic,
|
||||
views: statistics.views ?? 0,
|
||||
@@ -95,6 +97,7 @@ const analysis = {
|
||||
.where(and(eq(schema.resume.id, input.id), eq(schema.resume.userId, input.userId)));
|
||||
|
||||
if (!result) throw new ORPCError("NOT_FOUND");
|
||||
|
||||
return result.analysis ?? null;
|
||||
},
|
||||
|
||||
|
||||
Reference in New Issue
Block a user