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(company): add website, careers and industry fields and scope the delete guard by owner
Khuram Niaz4b9cf5263435
diff --git a/__tests__/AddCompany.spec.tsx b/__tests__/AddCompany.spec.tsxindex 05f8164..57f89cb 100644--- a/__tests__/AddCompany.spec.tsx+++ b/__tests__/AddCompany.spec.tsx@@ -77,6 +77,21 @@ describe("AddCompany Component", () => {);});+ it("renders the website, careers page and industry fields", async () => {+ render(+ <AddCompany+ reloadCompanies={mockReloadCompanies}+ resetEditCompany={mockResetEditCompany}+ dialogOpen={true}+ setDialogOpen={mockSetDialogOpen}+ />,+ );++ expect(await screen.findByLabelText(/website/i)).toBeInTheDocument();+ expect(screen.getByLabelText(/careers page/i)).toBeInTheDocument();+ expect(screen.getByLabelText(/industry/i)).toBeInTheDocument();+ });+it("should call addCompany function when submitting the form for new company", async () => {render(<AddCompany@@ -106,6 +121,9 @@ describe("AddCompany Component", () => {expect(addCompany).toHaveBeenCalledWith({company: "New Test Company",logoUrl: "http://example.com/new-logo.png",+ websiteUrl: "",+ careersUrl: "",+ industry: "",});});});@@ -153,6 +171,9 @@ describe("AddCompany Component", () => {company: "Edited Test Company",logoUrl: "http://example.com/edited-logo.png",createdBy: "user-id",+ websiteUrl: "",+ careersUrl: "",+ industry: "",});});});diff --git a/__tests__/addCompanyForm.schema.spec.ts b/__tests__/addCompanyForm.schema.spec.tsindex 93e6803..fbef80a 100644--- a/__tests__/addCompanyForm.schema.spec.ts+++ b/__tests__/addCompanyForm.schema.spec.ts@@ -116,6 +116,63 @@ describe("AddCompanyFormSchema", () => {});});+ describe("websiteUrl and careersUrl fields", () => {+ it("accepts an absolute https URL", () => {+ const result = AddCompanyFormSchema.parse({+ company: "Tech Company",+ websiteUrl: "https://example.com",+ careersUrl: "https://example.com/careers",+ });+ expect(result.websiteUrl).toBe("https://example.com");+ expect(result.careersUrl).toBe("https://example.com/careers");+ });++ it("accepts empty values", () => {+ const result = AddCompanyFormSchema.parse({+ company: "Tech Company",+ websiteUrl: "",+ careersUrl: "",+ });+ expect(result.websiteUrl).toBe("");+ });++ it("rejects a site-relative path as a website", () => {+ expect(() =>+ AddCompanyFormSchema.parse({+ company: "Tech Company",+ websiteUrl: "/careers",+ }),+ ).toThrow();+ });++ it("rejects a non-http protocol", () => {+ expect(() =>+ AddCompanyFormSchema.parse({+ company: "Tech Company",+ careersUrl: "ftp://example.com/jobs",+ }),+ ).toThrow();+ });++ it("still accepts a site-relative logo path", () => {+ const result = AddCompanyFormSchema.parse({+ company: "Tech Company",+ logoUrl: "/icons/logo.svg",+ });+ expect(result.logoUrl).toBe("/icons/logo.svg");+ });+ });++ describe("industry field", () => {+ it("accepts free text", () => {+ const result = AddCompanyFormSchema.parse({+ company: "Tech Company",+ industry: "Financial Services",+ });+ expect(result.industry).toBe("Financial Services");+ });+ });+describe("optional fields", () => {it("should accept id field", () => {const validData = {@@ -146,7 +203,12 @@ describe("AddCompanyFormSchema", () => {};const result = AddCompanyFormSchema.parse(validData);- expect(result).toEqual(validData);+ expect(result).toEqual({+ ...validData,+ websiteUrl: "",+ careersUrl: "",+ industry: "",+ });});});});diff --git a/__tests__/company.actions.spec.ts b/__tests__/company.actions.spec.tsindex d37988e..4d7c76c 100644--- a/__tests__/company.actions.spec.ts+++ b/__tests__/company.actions.spec.ts@@ -380,6 +380,52 @@ describe("Company Actions", () => {expect(revalidatePath).toHaveBeenCalledWith("/dashboard/myjobs", "page");});+ it("persists the three company attributes", async () => {+ (getCurrentUser as any).mockResolvedValue(mockUser);+ (prisma.company.findFirst as any).mockResolvedValue(null);+ (prisma.company.create as any).mockResolvedValue({ id: "c1" });++ await addCompany({+ company: "Acme",+ websiteUrl: "https://acme.example.com",+ careersUrl: "https://acme.example.com/careers",+ industry: "Widgets",+ } as any);++ expect(prisma.company.create).toHaveBeenCalledWith({+ data: expect.objectContaining({+ websiteUrl: "https://acme.example.com",+ careersUrl: "https://acme.example.com/careers",+ industry: "Widgets",+ }),+ });+ });++ it("rejects a site-relative website URL", async () => {+ (getCurrentUser as any).mockResolvedValue(mockUser);++ const res = await addCompany({+ company: "Acme",+ websiteUrl: "/careers",+ } as any);++ expect(res.success).toBe(false);+ expect(prisma.company.create).not.toHaveBeenCalled();+ });++ it("still accepts a site-relative logo URL", async () => {+ (getCurrentUser as any).mockResolvedValue(mockUser);+ (prisma.company.findFirst as any).mockResolvedValue(null);+ (prisma.company.create as any).mockResolvedValue({ id: "c1" });++ const res = await addCompany({+ company: "Acme",+ logoUrl: "/icons/logo.svg",+ } as any);++ expect(res.success).toBe(true);+ });+it("should return an error if the user is not authenticated", async () => {(getCurrentUser as any).mockResolvedValue(null);@@ -837,6 +883,25 @@ describe("Company Actions", () => {});});+ it("counts only the current user's work experience rows", async () => {+ (getCurrentUser as any).mockResolvedValue(mockUser);+ (prisma.workExperience.count as any).mockResolvedValue(0);+ (prisma.job.count as any).mockResolvedValue(0);+ (prisma.company.delete as any).mockResolvedValue({ id: "c1" });++ await deleteCompanyById("c1");++ expect(prisma.workExperience.count).toHaveBeenCalledWith({+ where: {+ companyId: "c1",+ OR: [+ { ResumeSection: { Resume: { profile: { userId: mockUser.id } } } },+ { resumeSectionId: null },+ ],+ },+ });+ });+it("should return error for unauthenticated user", async () => {(getCurrentUser as any).mockResolvedValue(null);diff --git a/src/actions/company/mutations.ts b/src/actions/company/mutations.tsindex d8b41fc..ded2db2 100644--- a/src/actions/company/mutations.ts+++ b/src/actions/company/mutations.ts@@ -21,13 +21,24 @@ const isValidImageUrl = (url: string): boolean => {}};+// Absolute http(s) only — an employer URL is never a bundled asset path.+const isValidHttpUrl = (url: string): boolean => {+ if (!url) return true;+ try {+ const urlObj = new URL(url);+ return ["http:", "https:"].includes(urlObj.protocol);+ } catch {+ return false;+ }+};+export const addCompany = async (data: z.infer<typeof AddCompanyFormSchema>,): Promise<any | undefined> => {try {const user = await requireUser();- const { company, logoUrl } = data;+ const { company, logoUrl, websiteUrl, careersUrl, industry } = data;// Validate image URLif (logoUrl && !isValidImageUrl(logoUrl)) {@@ -36,6 +47,13 @@ export const addCompany = async ();}+ if (websiteUrl && !isValidHttpUrl(websiteUrl)) {+ throw new Error("Website must be a full http or https URL.");+ }+ if (careersUrl && !isValidHttpUrl(careersUrl)) {+ throw new Error("Careers page must be a full http or https URL.");+ }+const value = canonicalizeEntityValue(company.trim(), { stripLegalSuffix: true });const companyExists = await prisma.company.findFirst({@@ -55,6 +73,9 @@ export const addCompany = async (value,label: company,logoUrl,+ websiteUrl,+ careersUrl,+ industry,},});revalidatePath("/dashboard/myjobs", "page");@@ -71,7 +92,8 @@ export const updateCompany = async (try {const user = await requireUser();- const { id, company, logoUrl, createdBy } = data;+ const { id, company, logoUrl, createdBy, websiteUrl, careersUrl, industry } =+ data;if (!id) {throw new Error("Company id is required");@@ -84,6 +106,13 @@ export const updateCompany = async ();}+ if (websiteUrl && !isValidHttpUrl(websiteUrl)) {+ throw new Error("Website must be a full http or https URL.");+ }+ if (careersUrl && !isValidHttpUrl(careersUrl)) {+ throw new Error("Careers page must be a full http or https URL.");+ }+const existingCompany = await prisma.company.findFirst({where: {id,@@ -126,6 +155,9 @@ export const updateCompany = async (value,label: company,logoUrl,+ websiteUrl,+ careersUrl,+ industry,},});@@ -142,9 +174,16 @@ export const deleteCompanyById = async (try {const user = await requireUser();+ // WorkExperience has no userId, so ownership runs through the resume+ // chain. The null-section arm keeps unsectioned rows blocking deletion+ // rather than letting it fail later on the foreign key.const experiences = await prisma.workExperience.count({where: {companyId,+ OR: [+ { ResumeSection: { Resume: { profile: { userId: user.id } } } },+ { resumeSectionId: null },+ ],},});if (experiences > 0) {diff --git a/src/components/admin/AddCompany.tsx b/src/components/admin/AddCompany.tsxindex 6eb0c99..fe995fe 100644--- a/src/components/admin/AddCompany.tsx+++ b/src/components/admin/AddCompany.tsx@@ -51,6 +51,9 @@ function AddCompany({defaultValues: {company: "",logoUrl: "",+ websiteUrl: "",+ careersUrl: "",+ industry: "",id: undefined,createdBy: undefined,},@@ -66,6 +69,9 @@ function AddCompany({company: editCompany?.label ?? "",createdBy: editCompany?.createdBy,logoUrl: editCompany?.logoUrl ?? "",+ websiteUrl: editCompany?.websiteUrl ?? "",+ careersUrl: editCompany?.careersUrl ?? "",+ industry: editCompany?.industry ?? "",},{ keepDefaultValues: true },);@@ -161,6 +167,56 @@ function AddCompany({)}/></div>+ {/* COMPANY WEBSITE */}+ <FormField+ control={form.control}+ name="websiteUrl"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Website</FormLabel>+ <FormControl>+ <Input placeholder="https://example.com" {...field} />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />++ {/* CAREERS PAGE */}+ <FormField+ control={form.control}+ name="careersUrl"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Careers Page</FormLabel>+ <FormControl>+ <Input+ placeholder="https://example.com/careers"+ {...field}+ />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />++ {/* INDUSTRY */}+ <div className="md:col-span-2">+ <FormField+ control={form.control}+ name="industry"+ render={({ field }) => (+ <FormItem>+ <FormLabel>Industry</FormLabel>+ <FormControl>+ <Input placeholder="Financial Services" {...field} />+ </FormControl>+ <FormMessage />+ </FormItem>+ )}+ />+ </div>+<div className="md:col-span-2 mt-4"><DialogFooter// className="md:col-spandiff --git a/src/models/addCompanyForm.schema.ts b/src/models/addCompanyForm.schema.tsindex 2d29d6a..58099e0 100644--- a/src/models/addCompanyForm.schema.ts+++ b/src/models/addCompanyForm.schema.ts@@ -9,6 +9,27 @@ const isValidUrl = (url: string) => {}};+// Absolute http(s) only. Deliberately not a flag on isValidUrl: a logo may be+// a bundled asset like /icons/logo.svg, an employer's website never is.+const isValidHttpUrl = (url: string) => {+ try {+ const parsed = new URL(url);+ return ["http:", "https:"].includes(parsed.protocol);+ } catch {+ return false;+ }+};++const httpUrlField = (label: string) =>+ z+ .string()+ .default("")+ .optional()+ .refine(+ (url) => !url || isValidHttpUrl(url),+ `Please enter a full ${label} URL starting with https://`,+ );+export const AddCompanyFormSchema = z.object({id: z.string().optional(),createdBy: z.string().optional(),@@ -25,4 +46,7 @@ export const AddCompanyFormSchema = z.object({(url) => !url || url.startsWith("/") || isValidUrl(url),"Please enter a valid URL (e.g., https://example.com/logo.png or /icons/logo.svg)",),+ websiteUrl: httpUrlField("website"),+ careersUrl: httpUrlField("careers page"),+ industry: z.string().default("").optional(),});