feat: validate inventory image metadata

Centralize supported MIME type, 10 MiB file-size, and 10,000-pixel dimension limits in the inventory image service boundary. Add domain coverage and update image/status documentation. Verification: npm test passed 64 tests and integration passed 14 tests. No build script is configured.
This commit is contained in:
2026-09-08 17:35:59 -04:00
parent 31f11f6d56
commit 5a041c8a5c
5 changed files with 71 additions and 2 deletions
@@ -0,0 +1,30 @@
import assert from 'node:assert/strict';
import test from 'node:test';
import { 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',
);
});