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
test: add unit tests for resume import and text extraction functionalities
Khuram Niazb05c9677d2f6
diff --git a/__tests__/extract-text.spec.ts b/__tests__/extract-text.spec.tsnew file mode 100644index 0000000..b69a086--- /dev/null+++ b/__tests__/extract-text.spec.ts@@ -0,0 +1,278 @@+import { describe, it, expect, vi, beforeEach } from "vitest";+import {+ sniffFileType,+ extractText,+ PDF_MAGIC,+ ZIP_MAGIC,+} from "@/lib/ai/import/extract-text";+import { APP_CONSTANTS } from "@/lib/constants";++// Hoist mock fns so they're available in the vi.mock factory+const { mockGetDocumentProxy, mockPdfExtractText, mockMammothExtractRawText } =+ vi.hoisted(() => ({+ mockGetDocumentProxy: vi.fn(),+ mockPdfExtractText: vi.fn(),+ mockMammothExtractRawText: vi.fn(),+ }));++vi.mock("unpdf", () => ({+ getDocumentProxy: mockGetDocumentProxy,+ extractText: mockPdfExtractText,+}));++vi.mock("mammoth", () => ({+ extractRawText: mockMammothExtractRawText,+}));++// Minimal valid ZIP buffer (no CD entries) — passes preflightZip bomb checks+function makeDocxBuf(): Buffer {+ // [4 bytes ZIP magic] [22 bytes EOCD]+ const buf = Buffer.alloc(26);+ ZIP_MAGIC.copy(buf, 0);+ const eocd = 4; // buf.length - 22 = 4+ buf.writeUInt32LE(0x06054b50, eocd); // EOCD signature+ buf.writeUInt16LE(0, eocd + 4); // disk number+ buf.writeUInt16LE(0, eocd + 6); // disk with CD start+ buf.writeUInt16LE(0, eocd + 8); // entries on disk+ buf.writeUInt16LE(0, eocd + 10); // total entries+ buf.writeUInt32LE(0, eocd + 12); // CD size+ buf.writeUInt32LE(0, eocd + 16); // CD offset (0 → no CD sig at 0, loop exits)+ buf.writeUInt16LE(0, eocd + 20); // comment length+ return buf;+}++// ZIP buffer with N real central-directory entries (each claiming uncompressedSize bytes)+function makeDocxBufWithEntries(n: number, uncompressedSizeEach = 0): Buffer {+ const CD_ENTRY = 46; // min CD entry size (no filename/extra/comment)+ const cdSize = n * CD_ENTRY;+ const buf = Buffer.alloc(4 + cdSize + 22); // magic + CD + EOCD+ ZIP_MAGIC.copy(buf, 0);++ const cdOffset = 4;+ for (let i = 0; i < n; i++) {+ const off = cdOffset + i * CD_ENTRY;+ buf.writeUInt32LE(0x02014b50, off); // CD signature+ buf.writeUInt32LE(uncompressedSizeEach, off + 24); // uncompressed size+ }++ const eocdOffset = 4 + cdSize;+ buf.writeUInt32LE(0x06054b50, eocdOffset);+ buf.writeUInt16LE(n, eocdOffset + 8); // entries on disk+ buf.writeUInt16LE(n, eocdOffset + 10); // total entries+ buf.writeUInt32LE(cdSize, eocdOffset + 12);+ buf.writeUInt32LE(cdOffset, eocdOffset + 16); // CD starts at offset 4+ return buf;+}++function makePdfBuf(): Buffer {+ const buf = Buffer.alloc(8);+ PDF_MAGIC.copy(buf);+ return buf;+}++beforeEach(() => {+ vi.clearAllMocks();+});++// --- sniffFileType ---++describe("sniffFileType", () => {+ it("identifies PDF by magic bytes", () => {+ const buf = Buffer.alloc(8);+ PDF_MAGIC.copy(buf);+ expect(sniffFileType(buf)).toBe("pdf");+ });++ it("identifies DOCX by ZIP magic bytes", () => {+ const buf = Buffer.alloc(8);+ ZIP_MAGIC.copy(buf);+ expect(sniffFileType(buf)).toBe("docx");+ });++ it("returns null for unknown format", () => {+ expect(sniffFileType(Buffer.from([0x00, 0x01, 0x02, 0x03]))).toBeNull();+ });++ it("returns null for empty buffer", () => {+ expect(sniffFileType(Buffer.alloc(0))).toBeNull();+ });++ it("returns null for buffer shorter than 4 bytes", () => {+ expect(sniffFileType(Buffer.from([0x25, 0x50]))).toBeNull();+ });++ it("does not confuse a near-match with PDF (4th byte differs)", () => {+ expect(sniffFileType(Buffer.from([0x25, 0x50, 0x44, 0x00]))).toBeNull();+ });+});++// --- extractText — unsupported format ---++describe("extractText — unsupported format", () => {+ it("returns UNSUPPORTED_FORMAT for an unknown file type", async () => {+ const result = await extractText(Buffer.from([0xde, 0xad, 0xbe, 0xef]));+ expect(result.success).toBe(false);+ if (!result.success) {+ expect(result.error.code).toBe("UNSUPPORTED_FORMAT");+ expect(result.error.message).toMatch(/pdf|word/i);+ }+ });+});++// --- extractText — PDF ---++describe("extractText — PDF", () => {+ it("returns extracted text for a valid single-page PDF", async () => {+ mockGetDocumentProxy.mockResolvedValue({ numPages: 1 });+ mockPdfExtractText.mockResolvedValue({ text: ["Hello world resume content"] });++ const result = await extractText(makePdfBuf());+ expect(result.success).toBe(true);+ if (result.success) {+ expect(result.data.text).toContain("Hello world resume content");+ expect(result.data.truncated).toBe(false);+ }+ });++ it("sets truncated=true when PDF exceeds max pages", async () => {+ const over = APP_CONSTANTS.RESUME_IMPORT_MAX_PDF_PAGES + 2;+ mockGetDocumentProxy.mockResolvedValue({ numPages: over });+ mockPdfExtractText.mockResolvedValue({+ text: Array(over).fill("Page content."),+ });++ const result = await extractText(makePdfBuf());+ expect(result.success).toBe(true);+ if (result.success) {+ expect(result.data.truncated).toBe(true);+ }+ });++ it("sets truncated=true and slices text when extracted chars exceed limit", async () => {+ mockGetDocumentProxy.mockResolvedValue({ numPages: 1 });+ mockPdfExtractText.mockResolvedValue({+ text: ["a".repeat(APP_CONSTANTS.RESUME_IMPORT_MAX_EXTRACTED_CHARS + 500)],+ });++ const result = await extractText(makePdfBuf());+ expect(result.success).toBe(true);+ if (result.success) {+ expect(result.data.truncated).toBe(true);+ expect(result.data.text.length).toBe(APP_CONSTANTS.RESUME_IMPORT_MAX_EXTRACTED_CHARS);+ }+ });++ it("returns NO_TEXT when PDF yields only whitespace", async () => {+ mockGetDocumentProxy.mockResolvedValue({ numPages: 1 });+ mockPdfExtractText.mockResolvedValue({ text: [" "] });++ const result = await extractText(makePdfBuf());+ expect(result.success).toBe(false);+ if (!result.success) {+ expect(result.error.code).toBe("NO_TEXT");+ }+ });++ it("returns ENCRYPTED when error message contains 'password'", async () => {+ mockGetDocumentProxy.mockRejectedValue(new Error("password required to decrypt"));++ const result = await extractText(makePdfBuf());+ expect(result.success).toBe(false);+ if (!result.success) {+ expect(result.error.code).toBe("ENCRYPTED");+ }+ });++ it("returns ENCRYPTED when error message contains 'encrypt'", async () => {+ mockGetDocumentProxy.mockRejectedValue(new Error("encrypted document"));++ const result = await extractText(makePdfBuf());+ expect(result.success).toBe(false);+ if (!result.success) {+ expect(result.error.code).toBe("ENCRYPTED");+ }+ });++ it("returns EXTRACTION_FAILED for generic PDF errors", async () => {+ mockGetDocumentProxy.mockRejectedValue(new Error("corrupted file"));++ const result = await extractText(makePdfBuf());+ expect(result.success).toBe(false);+ if (!result.success) {+ expect(result.error.code).toBe("EXTRACTION_FAILED");+ expect(result.error.message).toContain("corrupted file");+ }+ });+});++// --- extractText — DOCX ---++describe("extractText — DOCX", () => {+ it("returns extracted text for a valid DOCX", async () => {+ mockMammothExtractRawText.mockResolvedValue({+ value: "John Doe\nSenior Engineer\n8 years experience building systems",+ messages: [],+ });++ const result = await extractText(makeDocxBuf());+ expect(result.success).toBe(true);+ if (result.success) {+ expect(result.data.text).toContain("John Doe");+ expect(result.data.truncated).toBe(false);+ }+ });++ it("returns NO_TEXT when DOCX yields only whitespace", async () => {+ mockMammothExtractRawText.mockResolvedValue({ value: " ", messages: [] });++ const result = await extractText(makeDocxBuf());+ expect(result.success).toBe(false);+ if (!result.success) {+ expect(result.error.code).toBe("NO_TEXT");+ }+ });++ it("sets truncated=true and slices text when DOCX exceeds char limit", async () => {+ mockMammothExtractRawText.mockResolvedValue({+ value: "b".repeat(APP_CONSTANTS.RESUME_IMPORT_MAX_EXTRACTED_CHARS + 200),+ messages: [],+ });++ const result = await extractText(makeDocxBuf());+ expect(result.success).toBe(true);+ if (result.success) {+ expect(result.data.truncated).toBe(true);+ expect(result.data.text.length).toBe(APP_CONSTANTS.RESUME_IMPORT_MAX_EXTRACTED_CHARS);+ }+ });++ it("returns DECOMPRESSION_BOMB when ZIP has too many CD entries", async () => {+ const tooMany = APP_CONSTANTS.RESUME_IMPORT_MAX_DOCX_ENTRIES + 1;+ const result = await extractText(makeDocxBufWithEntries(tooMany));+ expect(result.success).toBe(false);+ if (!result.success) {+ expect(result.error.code).toBe("DECOMPRESSION_BOMB");+ }+ });++ it("returns DECOMPRESSION_BOMB when uncompressed size exceeds limit", async () => {+ // 10 entries × 15 MB = 150 MB > 100 MB limit+ const result = await extractText(makeDocxBufWithEntries(10, 15 * 1024 * 1024));+ expect(result.success).toBe(false);+ if (!result.success) {+ expect(result.error.code).toBe("DECOMPRESSION_BOMB");+ }+ });++ it("returns EXTRACTION_FAILED for a buffer with ZIP magic but no valid EOCD", async () => {+ const buf = Buffer.alloc(10);+ ZIP_MAGIC.copy(buf);+ // No EOCD → preflightZip throws++ const result = await extractText(buf);+ expect(result.success).toBe(false);+ if (!result.success) {+ expect(result.error.code).toBe("EXTRACTION_FAILED");+ }+ });+});diff --git a/__tests__/lib-utils.spec.ts b/__tests__/lib-utils.spec.tsindex ffd7cae..cc027e8 100644--- a/__tests__/lib-utils.spec.ts+++ b/__tests__/lib-utils.spec.ts@@ -246,4 +246,36 @@ describe("getTimestampedFileName", () => {const timestampPart = result.replace("test_", "").replace(".pdf", "");expect(timestampPart).not.toContain(".");});++ it("strips path segments to prevent path traversal", () => {+ const result = getTimestampedFileName("../../etc/passwd.pdf");+ expect(result).toMatch(/^passwd_/);+ });++ it("strips Windows backslash path segments", () => {+ const result = getTimestampedFileName("C:\\Users\\admin\\resume.pdf");+ expect(result).toMatch(/^resume_/);+ });++ it("strips control characters from the filename", () => {+ const result = getTimestampedFileName("resum\x00e.pdf");+ expect(result).not.toContain("\x00");+ expect(result).toMatch(/^resum/);+ });++ it("falls back to 'file' when name is empty after stripping control chars", () => {+ const result = getTimestampedFileName("\x00\x01\x02.pdf");+ expect(result).toMatch(/^file_/);+ });++ it("handles a filename with no extension", () => {+ const result = getTimestampedFileName("resume_noext");+ expect(result).toMatch(/^resume_noext_/);+ expect(result).not.toMatch(/\.$/);+ });++ it("uses the last path segment when given a Unix path", () => {+ const result = getTimestampedFileName("/tmp/uploads/cover.pdf");+ expect(result).toMatch(/^cover_/);+ });});diff --git a/__tests__/preprocessing.spec.ts b/__tests__/preprocessing.spec.tsindex 8883ed0..2368d6e 100644--- a/__tests__/preprocessing.spec.ts+++ b/__tests__/preprocessing.spec.ts@@ -1,4 +1,4 @@-import { convertResumeToText } from "@/lib/ai/tools/preprocessing";+import { convertResumeToText, preprocessText } from "@/lib/ai/tools/preprocessing";import { Resume, SectionType } from "@/models/profile.model";// Minimal resume fixture shared across tests@@ -235,3 +235,74 @@ describe("convertResumeToText - certification sections", () => {expect(text).toContain("Title: AWS SAA");});});++// --- preprocessText ---++// Enough text to pass MIN_CHAR_COUNT (200) and contain resume-like structure+const VALID_RESUME_TEXT = `+Jane Doe+Senior Software Engineer[email protected] | 555-123-4567 | Calgary, AB++SUMMARY+Experienced backend engineer with 8 years building scalable distributed systems.+Passionate about clean code and developer tooling.++EXPERIENCE+Acme Corp — Senior Engineer (Jan 2020 – Present)+- Led migration of monolithic backend to microservices architecture.+- Reduced p99 latency by 40% through caching and query optimization.+- Mentored a team of 5 junior engineers.++Previous Co — Software Engineer (Mar 2016 – Dec 2019)+- Built REST APIs serving 10M requests per day.+- Improved CI pipeline build times by 60%.++EDUCATION+University of Alberta — BSc Computer Science (2012 – 2016)++CERTIFICATIONS+AWS Certified Solutions Architect — Amazon (Jun 2023)+`.trim();++describe("preprocessText", () => {+ it("returns success for valid resume text", async () => {+ const result = await preprocessText(VALID_RESUME_TEXT);+ expect(result.success).toBe(true);+ if (result.success) {+ expect(result.data.normalizedText).toBeTruthy();+ expect(result.data.isValid).toBe(true);+ }+ });++ it("returns error for text that is too short", async () => {+ const result = await preprocessText("Too short.");+ expect(result.success).toBe(false);+ if (!result.success) {+ expect(result.error.code).toBeDefined();+ expect(result.error.message).toMatch(/short|minimum/i);+ }+ });++ it("returns error for empty string", async () => {+ const result = await preprocessText("");+ expect(result.success).toBe(false);+ });++ it("normalizes multiple consecutive spaces", async () => {+ const text = VALID_RESUME_TEXT.replace(/\s+/g, " "); // add extra spaces+ const result = await preprocessText(text);+ expect(result.success).toBe(true);+ if (result.success) {+ expect(result.data.normalizedText).not.toMatch(/ /); // no triple spaces+ }+ });++ it("includes metadata with word count", async () => {+ const result = await preprocessText(VALID_RESUME_TEXT);+ expect(result.success).toBe(true);+ if (result.success) {+ expect(result.data.metadata.wordCount).toBeGreaterThan(0);+ }+ });+});diff --git a/__tests__/resume-pdf.spec.ts b/__tests__/resume-pdf.spec.tsindex e6e8417..2561043 100644--- a/__tests__/resume-pdf.spec.ts+++ b/__tests__/resume-pdf.spec.ts@@ -1,8 +1,27 @@import { describe, it, expect } from "vitest";-import { sanitizeFilename } from "@/components/profile/resume-pdf";+import { sanitizeFilename, RESUME_LAYOUT_LABELS } from "@/components/profile/resume-pdf";// DOMParser is available in jsdom (vitest environment)import { htmlToPdfNodes } from "@/components/profile/resume-pdf/html-to-pdf";+import type { HtmlStyleSet } from "@/components/profile/resume-pdf/types";++// Minimal style sets — avoid @react-pdf StyleSheet.create in test env+const simpleStyleSet: HtmlStyleSet = {+ bodyText: {},+ bold: { fontFamily: "Helvetica-Bold" },+ italic: { fontFamily: "Helvetica-Oblique" },+ boldItalic: { fontFamily: "Helvetica-BoldOblique" },+ h2text: {},+ listRow: {},+ bullet: {},+ listText: {},+ bulletChar: "•",+};++const professionalStyleSet: HtmlStyleSet = {+ ...simpleStyleSet,+ bulletChar: "▪",+};describe("sanitizeFilename", () => {it("returns 'resume' for empty string", () => {@@ -79,3 +98,77 @@ describe("htmlToPdfNodes", () => {);});});++describe("RESUME_LAYOUT_LABELS", () => {+ it("maps 'simple' to 'Simple'", () => {+ expect(RESUME_LAYOUT_LABELS["simple"]).toBe("Simple");+ });++ it("maps 'professional' to 'Professional'", () => {+ expect(RESUME_LAYOUT_LABELS["professional"]).toBe("Professional");+ });++ it("covers exactly the two expected layouts", () => {+ expect(Object.keys(RESUME_LAYOUT_LABELS)).toEqual(["simple", "professional"]);+ });+});++describe("htmlToPdfNodes — layout style sets", () => {+ it("uses the simple bullet char (•) for list items", () => {+ const nodes = htmlToPdfNodes("<ul><li>Foo</li></ul>", simpleStyleSet);+ expect(JSON.stringify(nodes)).toContain("•");+ });++ it("uses the professional bullet char (▪) for list items", () => {+ const nodes = htmlToPdfNodes("<ul><li>Foo</li></ul>", professionalStyleSet);+ expect(JSON.stringify(nodes)).toContain("▪");+ expect(JSON.stringify(nodes)).not.toContain("•");+ });++ it("renders <h2> and includes its text content", () => {+ const nodes = htmlToPdfNodes("<h2>Skills</h2>", simpleStyleSet);+ expect(nodes).toHaveLength(1);+ expect(JSON.stringify(nodes[0])).toContain("Skills");+ });++ it("renders <ol> with incrementing numeric markers", () => {+ const nodes = htmlToPdfNodes(+ "<ol><li>First</li><li>Second</li></ol>",+ simpleStyleSet,+ );+ expect(nodes).toHaveLength(1);+ const serialized = JSON.stringify(nodes[0]);+ expect(serialized).toContain("1.");+ expect(serialized).toContain("2.");+ expect(serialized).not.toContain("•");+ });++ it("renders <br> as a newline within paragraph text", () => {+ const nodes = htmlToPdfNodes("<p>line one<br/>line two</p>", simpleStyleSet);+ expect(nodes).toHaveLength(1);+ // JSON.stringify encodes the \n character as \\n+ expect(JSON.stringify(nodes)).toContain("\\n");+ });++ it("renders <strong> with bold font and no italic", () => {+ const nodes = htmlToPdfNodes(+ "<p><strong>bold text</strong></p>",+ simpleStyleSet,+ );+ expect(nodes).toHaveLength(1);+ const serialized = JSON.stringify(nodes[0]);+ expect(serialized).toContain("Helvetica-Bold");+ expect(serialized).not.toContain("Oblique");+ });++ it("renders <em> with italic font and no bold", () => {+ const nodes = htmlToPdfNodes(+ "<p><em>italic text</em></p>",+ simpleStyleSet,+ );+ expect(nodes).toHaveLength(1);+ const serialized = JSON.stringify(nodes[0]);+ expect(serialized).toContain("Helvetica-Oblique");+ expect(serialized).not.toContain("Bold");+ });+});diff --git a/__tests__/resumeImport.schema.spec.ts b/__tests__/resumeImport.schema.spec.tsnew file mode 100644index 0000000..4a18116--- /dev/null+++ b/__tests__/resumeImport.schema.spec.ts@@ -0,0 +1,210 @@+import { describe, it, expect } from "vitest";+import {+ ImportContactInfoSchema,+ ImportExperienceSchema,+ ImportEducationSchema,+ ImportCertificationSchema,+ ResumeImportSchema,+} from "@/models/resumeImport.schema";++// --- ImportContactInfoSchema ---++describe("ImportContactInfoSchema", () => {+ it("accepts a fully populated contact object", () => {+ const result = ImportContactInfoSchema.safeParse({+ firstName: "Jane",+ lastName: "Doe",+ headline: "Senior Engineer",+ email: "[email protected]",+ phone: "555-1234",+ address: "Calgary, AB",+ confidence: "high",+ });+ expect(result.success).toBe(true);+ });++ it("accepts an empty object (all fields optional)", () => {+ expect(ImportContactInfoSchema.safeParse({}).success).toBe(true);+ });++ it("accepts valid confidence values", () => {+ for (const confidence of ["high", "medium", "low"] as const) {+ expect(ImportContactInfoSchema.safeParse({ confidence }).success).toBe(true);+ }+ });++ it("rejects an invalid confidence value", () => {+ expect(+ ImportContactInfoSchema.safeParse({ confidence: "very-high" }).success,+ ).toBe(false);+ });+});++// --- ImportExperienceSchema ---++describe("ImportExperienceSchema", () => {+ it("accepts a full experience entry", () => {+ const result = ImportExperienceSchema.safeParse({+ company: "Acme Corp",+ jobTitle: "Backend Engineer",+ location: "Remote",+ startDate: "Jan 2020",+ endDate: "Present",+ description: "Built APIs.",+ confidence: "high",+ });+ expect(result.success).toBe(true);+ });++ it("requires company and jobTitle", () => {+ expect(ImportExperienceSchema.safeParse({ company: "Acme" }).success).toBe(false);+ expect(ImportExperienceSchema.safeParse({ jobTitle: "Eng" }).success).toBe(false);+ expect(ImportExperienceSchema.safeParse({}).success).toBe(false);+ });++ it("accepts when optional fields are omitted", () => {+ const result = ImportExperienceSchema.safeParse({+ company: "Acme",+ jobTitle: "Engineer",+ });+ expect(result.success).toBe(true);+ });++ it("treats date fields as raw strings (no date format enforcement)", () => {+ const result = ImportExperienceSchema.safeParse({+ company: "X",+ jobTitle: "Y",+ startDate: "2019",+ endDate: "Current",+ });+ expect(result.success).toBe(true);+ if (result.success) {+ expect(result.data.startDate).toBe("2019");+ expect(result.data.endDate).toBe("Current");+ }+ });+});++// --- ImportEducationSchema ---++describe("ImportEducationSchema", () => {+ it("accepts a full education entry", () => {+ const result = ImportEducationSchema.safeParse({+ institution: "University of Alberta",+ degree: "BSc",+ fieldOfStudy: "Computer Science",+ location: "Edmonton, AB",+ startDate: "Sep 2015",+ endDate: "Apr 2019",+ description: "Dean's List.",+ confidence: "medium",+ });+ expect(result.success).toBe(true);+ });++ it("requires institution", () => {+ expect(ImportEducationSchema.safeParse({ degree: "BSc" }).success).toBe(false);+ expect(ImportEducationSchema.safeParse({}).success).toBe(false);+ });++ it("accepts when only institution is provided", () => {+ expect(+ ImportEducationSchema.safeParse({ institution: "MIT" }).success,+ ).toBe(true);+ });+});++// --- ImportCertificationSchema ---++describe("ImportCertificationSchema", () => {+ it("accepts a full certification entry", () => {+ const result = ImportCertificationSchema.safeParse({+ title: "AWS Solutions Architect",+ organization: "Amazon",+ issueDate: "Jun 2023",+ expirationDate: "Jun 2026",+ credentialUrl: "https://credly.com/badges/abc",+ confidence: "low",+ });+ expect(result.success).toBe(true);+ });++ it("requires title", () => {+ expect(ImportCertificationSchema.safeParse({}).success).toBe(false);+ expect(+ ImportCertificationSchema.safeParse({ organization: "AWS" }).success,+ ).toBe(false);+ });++ it("accepts when only title is provided", () => {+ expect(+ ImportCertificationSchema.safeParse({ title: "AWS SAA" }).success,+ ).toBe(true);+ });+});++// --- ResumeImportSchema ---++describe("ResumeImportSchema", () => {+ it("accepts a fully populated import payload", () => {+ const result = ResumeImportSchema.safeParse({+ contactInfo: { firstName: "Jane", email: "[email protected]" },+ summary: "Experienced engineer.",+ experience: [{ company: "Acme", jobTitle: "Engineer" }],+ education: [{ institution: "MIT" }],+ certifications: [{ title: "AWS SAA" }],+ unrecognizedSections: ["Skills", "Projects"],+ });+ expect(result.success).toBe(true);+ });++ it("defaults arrays to [] when omitted", () => {+ const result = ResumeImportSchema.safeParse({});+ expect(result.success).toBe(true);+ if (result.success) {+ expect(result.data.experience).toEqual([]);+ expect(result.data.education).toEqual([]);+ expect(result.data.certifications).toEqual([]);+ expect(result.data.unrecognizedSections).toEqual([]);+ }+ });++ it("accepts when all top-level fields are omitted", () => {+ expect(ResumeImportSchema.safeParse({}).success).toBe(true);+ });++ it("rejects when an experience entry is missing required fields", () => {+ const result = ResumeImportSchema.safeParse({+ experience: [{ location: "Remote" }], // missing company and jobTitle+ });+ expect(result.success).toBe(false);+ });++ it("rejects when an education entry is missing institution", () => {+ const result = ResumeImportSchema.safeParse({+ education: [{ degree: "BSc" }],+ });+ expect(result.success).toBe(false);+ });++ it("rejects when a certification entry is missing title", () => {+ const result = ResumeImportSchema.safeParse({+ certifications: [{ organization: "AWS" }],+ });+ expect(result.success).toBe(false);+ });++ it("preserves unrecognized section names as-is", () => {+ const result = ResumeImportSchema.safeParse({+ unrecognizedSections: ["Skills", "Publications", "Volunteering"],+ });+ expect(result.success).toBe(true);+ if (result.success) {+ expect(result.data.unrecognizedSections).toEqual([+ "Skills",+ "Publications",+ "Volunteering",+ ]);+ }+ });+});diff --git a/src/components/profile/resume-pdf/html-to-pdf.tsx b/src/components/profile/resume-pdf/html-to-pdf.tsxindex 51855e3..f3fe44e 100644--- a/src/components/profile/resume-pdf/html-to-pdf.tsx+++ b/src/components/profile/resume-pdf/html-to-pdf.tsx@@ -119,7 +119,19 @@ function walkNode(}}-export function htmlToPdfNodes(html: string, s: HtmlStyleSet): React.ReactElement[] {+const DEFAULT_STYLE_SET: HtmlStyleSet = {+ bodyText: {},+ bold: { fontFamily: "Helvetica-Bold" },+ italic: { fontFamily: "Helvetica-Oblique" },+ boldItalic: { fontFamily: "Helvetica-BoldOblique" },+ h2text: {},+ listRow: { flexDirection: "row" },+ bullet: {},+ listText: {},+ bulletChar: "•",+};++export function htmlToPdfNodes(html: string, s: HtmlStyleSet = DEFAULT_STYLE_SET): React.ReactElement[] {if (!html || !html.trim()) return [];try {const doc = new DOMParser().parseFromString(html, "text/html");