fix: address CodeRabbit review feedback on tests
- digital-sign-pdf.test.ts: stub VITE_CORS_PROXY_URL and VITE_CORS_PROXY_SECRET env vars for test isolation - timestamp-node.test.ts: replace regex-only test with actual data() method tests covering timestampPdf call, output filename suffix, and error wrapping with TSA context
This commit is contained in:
@@ -30,6 +30,8 @@ describe('timestampPdf', () => {
|
|||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.clearAllMocks();
|
vi.clearAllMocks();
|
||||||
|
vi.stubEnv('VITE_CORS_PROXY_URL', '');
|
||||||
|
vi.stubEnv('VITE_CORS_PROXY_SECRET', '');
|
||||||
samplePdfBytes = new Uint8Array(fs.readFileSync(SAMPLE_PDF_PATH));
|
samplePdfBytes = new Uint8Array(fs.readFileSync(SAMPLE_PDF_PATH));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { describe, it, expect, vi } from 'vitest';
|
import { describe, it, expect, vi, beforeEach } from 'vitest';
|
||||||
import { TIMESTAMP_TSA_PRESETS } from '@/js/config/timestamp-tsa';
|
import { TIMESTAMP_TSA_PRESETS } from '@/js/config/timestamp-tsa';
|
||||||
|
|
||||||
// Mock external dependencies before importing the node
|
// Mock external dependencies before importing the node
|
||||||
@@ -74,8 +74,13 @@ vi.mock('@/js/workflow/types', () => ({
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
import { TimestampNode } from '@/js/workflow/nodes/timestamp-node';
|
import { TimestampNode } from '@/js/workflow/nodes/timestamp-node';
|
||||||
|
import { timestampPdf } from '@/js/logic/digital-sign-pdf';
|
||||||
|
|
||||||
describe('TimestampNode', () => {
|
describe('TimestampNode', () => {
|
||||||
|
beforeEach(() => {
|
||||||
|
vi.clearAllMocks();
|
||||||
|
});
|
||||||
|
|
||||||
it('should be instantiable', () => {
|
it('should be instantiable', () => {
|
||||||
const node = new TimestampNode();
|
const node = new TimestampNode();
|
||||||
expect(node).toBeDefined();
|
expect(node).toBeDefined();
|
||||||
@@ -109,9 +114,41 @@ describe('TimestampNode', () => {
|
|||||||
expect(presets[0].url).toBe(TIMESTAMP_TSA_PRESETS[0].url);
|
expect(presets[0].url).toBe(TIMESTAMP_TSA_PRESETS[0].url);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should generate _timestamped suffix in output filename', () => {
|
it('should call timestampPdf with correct TSA URL via data()', async () => {
|
||||||
const input = 'report.pdf';
|
const node = new TimestampNode();
|
||||||
const output = input.replace(/\.pdf$/i, '_timestamped.pdf');
|
const mockInput = [
|
||||||
expect(output).toBe('report_timestamped.pdf');
|
{ bytes: new Uint8Array([1, 2, 3]), filename: 'test.pdf' },
|
||||||
|
];
|
||||||
|
|
||||||
|
await node.data({ pdf: mockInput });
|
||||||
|
|
||||||
|
expect(timestampPdf).toHaveBeenCalledWith(
|
||||||
|
mockInput[0].bytes,
|
||||||
|
TIMESTAMP_TSA_PRESETS[0].url
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
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' },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = (await node.data({ pdf: mockInput })) as {
|
||||||
|
pdf: Array<{ filename: string }>;
|
||||||
|
};
|
||||||
|
|
||||||
|
expect(result.pdf[0].filename).toBe('report_timestamped.pdf');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should wrap errors from timestampPdf with TSA context', async () => {
|
||||||
|
vi.mocked(timestampPdf).mockRejectedValueOnce(new Error('Network error'));
|
||||||
|
const node = new TimestampNode();
|
||||||
|
|
||||||
|
await expect(
|
||||||
|
node.data({
|
||||||
|
pdf: [{ bytes: new Uint8Array([1]), filename: 'test.pdf' }],
|
||||||
|
})
|
||||||
|
).rejects.toThrow(/Failed to timestamp using TSA/);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user