This commit is contained in:
@@ -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();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user