Job application tracker and AI-powered job search assistant. Helps job seekers manage their search journey with AI resume review, job matching, task logging, and application analytics, all while keeping your data private.
TypeScript ai-agentai-resume-analyzerapplication-trackerapplication-tracking-systematscareerjob-applicationjob-automationjob-huntingjob-searchjob-seeker-toolsjob-trackerjob-trackingjobsearchjobseekersmcpollamaresumeresume-reviewself-hosted
feat(profile): suggest a title for resume copies
Khuram Niaza178fe6ac27d
diff --git a/__tests__/resumeCopy.actions.spec.ts b/__tests__/resumeCopy.actions.spec.tsnew file mode 100644index 0000000..8fead82--- /dev/null+++ b/__tests__/resumeCopy.actions.spec.ts@@ -0,0 +1,85 @@+import { getResumeCopyTitleSuggestion } from "@/actions/profile.actions";+import { getCurrentUser } from "@/utils/user.utils";+import { PrismaClient } from "@prisma/client";++const prisma = new PrismaClient();++vi.mock("@prisma/client", () => {+ const mPrismaClient = {+ resume: {+ findUnique: vi.fn(),+ findFirst: vi.fn(),+ findMany: vi.fn(),+ create: vi.fn(),+ },+ contactInfo: { create: vi.fn() },+ resumeSection: { create: vi.fn() },+ workExperience: { createMany: vi.fn() },+ education: { createMany: vi.fn() },+ licenseOrCertification: { createMany: vi.fn() },+ otherSection: { createMany: vi.fn() },+ skill: { createMany: vi.fn() },+ $transaction: vi.fn(),+ };+ return {+ PrismaClient: vi.fn(function () {+ return mPrismaClient;+ }),+ };+});++vi.mock("@/utils/user.utils", () => ({ getCurrentUser: vi.fn() }));++describe("getResumeCopyTitleSuggestion", () => {+ beforeEach(() => {+ vi.clearAllMocks();+ (getCurrentUser as any).mockResolvedValue({ id: "user-1" });+ });++ it("suggests '(Copy)' based on the owned source resume title", async () => {+ (prisma.resume.findUnique as any).mockResolvedValue({+ title: "Backend Resume",+ });+ (prisma.resume.findMany as any).mockResolvedValue([+ { title: "Backend Resume" },+ ]);++ const result = await getResumeCopyTitleSuggestion("resume-1");++ expect(result).toEqual({ success: true, data: "Backend Resume (Copy)" });+ expect((prisma.resume.findUnique as any).mock.calls[0][0].where).toEqual({+ id: "resume-1",+ profile: { userId: "user-1" },+ });+ });++ it("numbers the suggestion when earlier copies exist", async () => {+ (prisma.resume.findUnique as any).mockResolvedValue({+ title: "Backend Resume",+ });+ (prisma.resume.findMany as any).mockResolvedValue([+ { title: "Backend Resume" },+ { title: "Backend Resume (Copy)" },+ ]);++ const result = await getResumeCopyTitleSuggestion("resume-1");++ expect(result).toEqual({ success: true, data: "Backend Resume (Copy 2)" });+ });++ it("fails when the resume is not owned by the current user", async () => {+ (prisma.resume.findUnique as any).mockResolvedValue(null);++ const result = await getResumeCopyTitleSuggestion("someone-elses-resume");++ expect(result.success).toBe(false);+ });++ it("fails when not authenticated", async () => {+ (getCurrentUser as any).mockResolvedValue(null);++ const result = await getResumeCopyTitleSuggestion("resume-1");++ expect(result.success).toBe(false);+ });+});diff --git a/src/actions/profile.actions.ts b/src/actions/profile.actions.tsindex 7b92cf5..ea5534f 100644--- a/src/actions/profile.actions.ts+++ b/src/actions/profile.actions.ts@@ -19,6 +19,7 @@ import {buildInsufficientSectionsMessage,hasMinResumeSections,} from "@/lib/resumeSections";+import { buildCopyTitle, ensureUniqueTitle } from "@/lib/resumeCopyTitle";import { revalidatePath } from "next/cache";import { z } from "zod";import path from "path";@@ -461,6 +462,42 @@ export const editResume = async (}};+export const getResumeCopyTitleSuggestion = async (+ resumeId: string,+): Promise<any | undefined> => {+ try {+ const user = await getCurrentUser();+ if (!user) {+ throw new Error("Not authenticated");+ }++ const source = await prisma.resume.findUnique({+ where: { id: resumeId, profile: { userId: user.id } },+ select: { title: true },+ });+ if (!source) {+ throw new Error("Resume not found or access denied");+ }++ // All titles, not just the current page, so the suggestion never collides+ const existing = await prisma.resume.findMany({+ where: { profile: { userId: user.id } },+ select: { title: true },+ });++ return {+ success: true,+ data: buildCopyTitle(+ source.title,+ existing.map((r) => r.title),+ ),+ };+ } catch (error) {+ const msg = "Failed to build a title for the copy.";+ return handleError(error, msg);+ }+};+export const deleteResumeById = async (resumeId: string,): Promise<any | undefined> => {