Newer
Older
import { describe, it, expect, beforeAll } from "@jest/globals";
import { AppError } from "../src/lib/errors";
it("should return pdf document metadata including signatures", async () => {
const file = fs.readFileSync(
path.resolve(__dirname, "./abacus-two-signatures.pdf")
);
const parser = new PDFparser(file);
const actual = await parser.getPDFMeta();
it("should return pdf document metadata without signatures", async () => {
const file = fs.readFileSync(path.resolve(__dirname, "./example.pdf"));
const parser = new PDFparser(file);
const actual = await parser.getPDFMeta();
expect(actual.pages).toEqual(1);
expect(actual.title).toEqual("PDF Digital Signatures");
expect(actual.author).toEqual("Tecxoft");
});
it("should throw error without file", async () => {
try {
const parser = new PDFparser(null);
const actual = await parser.getPDFMeta();
} catch (error) {
expect(error).toBeInstanceOf(AppError);
}
});
it("should throw error if file type is different then pdf", async () => {
const file = fs.readFileSync(path.resolve(__dirname, "./test.txt"));
try {
const parser = new PDFparser(file);
const actual = await parser.getPDFMeta();
} catch (error) {
expect(error).toBeInstanceOf(AppError);
expect(error.message).toEqual("Only pdf file type is supported");
}
});
type SealCoords = {
[key: string]: { x: string; y: string };
};
describe("PDF insert", () => {
it.only("should insert qrcode into the pdf without breaking the signature", async () => {
// Signed-linux-libreOfficeWriterTest-v1.6-signed-pades-baseline-b
// Signed-linux-OpenOfficeWriter-v1.4-signed-pades-baseline-b
// Signed-mac-Adobe-1.3-signed-pades-baseline-b
// Signed-XXX-nopodofo-test-v.1.7-signed-pades-baseline-b
const filename = "abacus-two-signatures";
);
const qrcode = fs.readFileSync(path.resolve(__dirname, "./qrcode.png"));
const parser = new PDFparser(file);
const sealCoords: SealCoords = {
"1": { x: "261.6", y: "384.84" },
"2": { x: "261.6", y: "384.84" },
};
const resultPDF = await parser.insertQrCode(
qrcode.buffer,
"vereign.com",
sealCoords,
0.25,
"demo:1652778685773:7b893c000300000000b9c455b21b7b47780dc82f9ef63ddc54ce5c282b"
fs.writeFileSync(
`${__dirname}/outputs/tron/${filename}-im11age.pdf`,
Buffer.from(resultPDF)
);
expect(true).toBeTruthy();
}, 30000);