mirror of
https://github.com/AmruthPillai/Reactive-Resume.git
synced 2026-10-04 02:33:47 +10:00
* 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>
32 lines
996 B
TypeScript
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);
|
|
});
|
|
});
|