35 lines
1.2 KiB
TypeScript
35 lines
1.2 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { describeOoxmlError } from "../../src/office/ooxml-errors";
|
|
|
|
describe("OOXML error descriptions", () => {
|
|
it("offers an in-memory password retry for supported encryption", () => {
|
|
const description = describeOoxmlError(
|
|
Object.assign(new Error("encrypted"), { code: "encrypted" }),
|
|
);
|
|
expect(description.passwordRequired).toBe(true);
|
|
expect(description.message).toContain("password protected");
|
|
});
|
|
|
|
it.each([
|
|
"unsupported-encryption",
|
|
"legacy-binary-format",
|
|
"not-ooxml",
|
|
"ooxml-resource-limit",
|
|
"ooxml-decoded-image-limit",
|
|
"parser-crashed",
|
|
])("provides a stable safe message for %s", (code) => {
|
|
const description = describeOoxmlError(
|
|
Object.assign(new Error("internal diagnostic"), { code }),
|
|
);
|
|
expect(description.code).toBe(code);
|
|
expect(description.passwordRequired).toBe(false);
|
|
expect(description.message).not.toBe("internal diagnostic");
|
|
});
|
|
|
|
it("retains an ordinary parser message as the fallback", () => {
|
|
expect(describeOoxmlError(new Error("Malformed package")).message).toBe(
|
|
"Malformed package",
|
|
);
|
|
});
|
|
});
|