import assert from 'node:assert/strict'; import test from 'node:test'; import { validateImageSignature, validateInventoryImageMetadata, } from '../../src/modules/inventory/domain/inventory-image.js'; const validImage = { mimeType: 'image/jpeg', fileSize: 12000, width: 1200, height: 900, }; test('accepts supported image metadata within configured limits', () => { assert.equal(validateInventoryImageMetadata(validImage), true); }); test('rejects unsupported MIME types, oversized files, and oversized dimensions', () => { assert.throws( () => validateInventoryImageMetadata({ ...validImage, mimeType: 'image/gif' }), (error) => error.code === 'IMAGE_MIME_TYPE_UNSUPPORTED', ); assert.throws( () => validateInventoryImageMetadata({ ...validImage, fileSize: 11 * 1024 * 1024 }), (error) => error.code === 'IMAGE_FILE_TOO_LARGE', ); assert.throws( () => validateInventoryImageMetadata({ ...validImage, width: 10001 }), (error) => error.code === 'IMAGE_DIMENSIONS_INVALID', ); }); test('accepts matching image signatures and rejects mismatched bytes', () => { assert.equal( validateImageSignature(Buffer.from([0xff, 0xd8, 0xff, 0x00]), 'image/jpeg'), true, ); assert.equal( validateImageSignature( Buffer.from([0x89, 0x50, 0x4e, 0x47, 0x0d, 0x0a, 0x1a, 0x0a]), 'image/png', ), true, ); assert.throws( () => validateImageSignature(Buffer.from('not-an-image'), 'image/png'), (error) => error.code === 'IMAGE_SIGNATURE_INVALID', ); });