Files
Reactive-Resume/packages/import/src/error.test.ts
T
bad431b2fc fix(import): auto-detect JSON format and show readable errors (#1) (#3296)
* fix(import): auto-detect JSON format and show readable errors (#1)

Readable import errors, a fail-soft v4 parser, and auto-detect of the JSON format so uploads just work. The format dropdown becomes an optional override. PDF and DOCX (AI) paths are untouched.

* fix(import): address review feedback on the v4 guard and error message

- reactive-resume-v4-json.tsx: reject arrays in isRecord so array-valued
  basics, sections, or metadata no longer pass the v4 shape guard.
- reactive-resume-v4-json.tsx: reuse the guard's error instance in the
  catch arm instead of allocating a duplicate NOT_V4_MESSAGE.
- error.ts: use a singular "Problem" label for root-level Zod issues so
  the message stays grammatical.
- add a regression test for array-valued v4 branches.

* fix(import): preserve selected JSON format

* test(import): cover selected JSON parser

---------

Co-authored-by: MrTig-afk <MrTig-afk@users.noreply.github.com>
Co-authored-by: Amruth Pillai <im.amruth@gmail.com>
2026-08-13 23:01:06 +02:00

32 lines
996 B
TypeScript

import { describe, expect, it } from "vitest";
import { z } from "zod";
import { rethrowAsImportError } from "./error";
const makeZodError = () => {
const result = z.object({ name: z.string() }).safeParse({ name: 123 });
if (result.success) throw new Error("expected the schema to fail");
return result.error;
};
describe("rethrowAsImportError", () => {
it("turns a ZodError into a readable sentence instead of raw JSON", () => {
let caught: Error | undefined;
try {
rethrowAsImportError(makeZodError());
} catch (error) {
caught = error as Error;
}
expect(caught).toBeInstanceOf(Error);
// Not a raw JSON.stringify(flattenError(...)) dump.
expect(caught?.message.startsWith("{")).toBe(false);
expect(caught?.message).toContain("name");
expect(caught?.message.toLowerCase()).toContain("resume");
});
it("re-throws non-Zod errors unchanged", () => {
const original = new Error("boom");
expect(() => rethrowAsImportError(original)).toThrow(original);
});
});