feat: enforce per-item image count limits
Quality / test (push) Canceled after 0s

This commit is contained in:
2026-09-11 00:39:27 -04:00
parent e6510c0317
commit f54223966c
7 changed files with 62 additions and 6 deletions
@@ -69,4 +69,21 @@ test('removes stored bytes when metadata persistence fails', async () => {
(error) => error.code === 'INVENTORY_ITEM_NOT_FOUND',
);
assert.deepEqual(deleted, [input.storageKey]);
});
});
test('passes the seller image limit to the atomic repository operation', async () => {
let limit;
const service = createInventoryImageService({
sellerSettingsRepository: { async findBySellerId() { return { settings: { inventory: { maxImagesPerItem: 2 } } }; } },
inventoryImageRepository: {
async createForSellerWithLimit(image, sellerId, maxImages) {
assert.equal(sellerId, 'seller-id');
limit = maxImages;
return { id: 'image-1', ...image };
},
},
});
const image = await service.create({ ...input, data: undefined });
assert.equal(image.id, 'image-1');
assert.equal(limit, 2);
});
@@ -244,6 +244,17 @@ test('persists image metadata only for the owning seller and counts item images'
);
});
test('enforces per-item image limits across concurrent inserts', async () => {
const { seller, inventoryItem } = await createInventoryFixture();
const image = (suffix) => ({ inventoryItemId: inventoryItem.id, storageKey: `inventory/${suffix}.jpg`, originalFilename: `${suffix}.jpg`, mimeType: 'image/jpeg', fileSize: 4, width: 2, height: 2, sortOrder: 0, isPrimary: false, processingStatus: 'PENDING' });
const results = await Promise.allSettled([
inventoryImageRepository.createForSellerWithLimit(image('a'), seller.id, 1),
inventoryImageRepository.createForSellerWithLimit(image('b'), seller.id, 1),
]);
assert.equal(results.filter((result) => result.status === 'fulfilled').length, 1);
assert.equal(results.filter((result) => result.status === 'rejected' && result.reason.code === 'IMAGE_COUNT_LIMIT_REACHED').length, 1);
});
test('reads and updates listings only through the owning seller scope', async () => {
const { seller, category, condition, inventoryItem } = await createInventoryFixture();