Files
dh-inspeccion-v2/api-v3/test/unit/inspection-closing-file.test.ts

44 lines
1.3 KiB
TypeScript

import assert from 'node:assert/strict';
import test from 'node:test';
import {
inspectInspectionSignatureFile,
MAX_INSPECTION_SIGNATURE_BYTES,
} from '../../src/inspection-closing/inspection-signature-file';
const png = Buffer.from([137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 0]);
test('D5 signature accepts only PNG content and MIME', () => {
assert.deepEqual(inspectInspectionSignatureFile({
originalname: 'firma.png',
mimetype: 'image/png',
size: png.length,
buffer: png,
}), {
originalName: 'firma.png',
mimeType: 'image/png',
extension: '.png',
});
assert.throws(() => inspectInspectionSignatureFile({
originalname: 'firma.png',
mimetype: 'image/png',
size: 4,
buffer: Buffer.from('test'),
}));
assert.throws(() => inspectInspectionSignatureFile({
originalname: 'firma.png',
mimetype: 'application/octet-stream',
size: png.length,
buffer: png,
}));
});
test('D5 signature rejects empty and oversized files', () => {
assert.throws(() => inspectInspectionSignatureFile(undefined));
assert.throws(() => inspectInspectionSignatureFile({
originalname: 'firma.png',
mimetype: 'image/png',
size: MAX_INSPECTION_SIGNATURE_BYTES + 1,
buffer: Buffer.concat([png, Buffer.alloc(MAX_INSPECTION_SIGNATURE_BYTES)]),
}));
});