refactor: replace PDFDocument.load with loadPdfDocument utility in TimestampNode

This commit is contained in:
alam00000
2026-03-27 13:27:58 +05:30
parent a90f74c719
commit 86c8086979
2 changed files with 25 additions and 10 deletions

View File

@@ -3,9 +3,9 @@ import { BaseWorkflowNode } from './base-node';
import { pdfSocket } from '../sockets';
import type { SocketData } from '../types';
import { requirePdfInput, processBatch } from '../types';
import { PDFDocument } from 'pdf-lib';
import { TIMESTAMP_TSA_PRESETS } from '../../config/timestamp-tsa.js';
import { timestampPdf } from '../../logic/digital-sign-pdf.js';
import { loadPdfDocument } from '../../utils/load-pdf-document.js';
export class TimestampNode extends BaseWorkflowNode {
readonly category = 'Secure PDF' as const;
@@ -52,7 +52,7 @@ export class TimestampNode extends BaseWorkflowNode {
{ cause: err }
);
}
const document = await PDFDocument.load(bytes);
const document = await loadPdfDocument(bytes);
return {
type: 'pdf',

View File

@@ -47,10 +47,8 @@ vi.mock('@/js/workflow/nodes/base-node', () => ({
},
}));
vi.mock('pdf-lib', () => ({
PDFDocument: {
load: vi.fn().mockResolvedValue({}),
},
vi.mock('@/js/utils/load-pdf-document', () => ({
loadPdfDocument: vi.fn().mockResolvedValue({}),
}));
vi.mock('@/js/logic/digital-sign-pdf', () => ({
@@ -117,7 +115,12 @@ describe('TimestampNode', () => {
it('should call timestampPdf with correct TSA URL via data()', async () => {
const node = new TimestampNode();
const mockInput = [
{ bytes: new Uint8Array([1, 2, 3]), filename: 'test.pdf' },
{
type: 'pdf' as const,
document: {} as never,
bytes: new Uint8Array([1, 2, 3]),
filename: 'test.pdf',
},
];
await node.data({ pdf: mockInput });
@@ -131,10 +134,15 @@ describe('TimestampNode', () => {
it('should generate _timestamped suffix in output filename via data()', async () => {
const node = new TimestampNode();
const mockInput = [
{ bytes: new Uint8Array([1, 2, 3]), filename: 'report.pdf' },
{
type: 'pdf' as const,
document: {} as never,
bytes: new Uint8Array([1, 2, 3]),
filename: 'report.pdf',
},
];
const result = (await node.data({ pdf: mockInput })) as {
const result = (await node.data({ pdf: mockInput })) as unknown as {
pdf: Array<{ filename: string }>;
};
@@ -147,7 +155,14 @@ describe('TimestampNode', () => {
await expect(
node.data({
pdf: [{ bytes: new Uint8Array([1]), filename: 'test.pdf' }],
pdf: [
{
type: 'pdf' as const,
document: {} as never,
bytes: new Uint8Array([1]),
filename: 'test.pdf',
},
],
})
).rejects.toThrow(/Failed to timestamp using TSA/);
});