feat: add seller-scoped bulk archive
Quality / test (push) Canceled after 0s

Add the first bulk inventory operation through a validated, CSRF-protected API route with lifecycle and ownership enforcement, tests, and implementation-status documentation.
This commit is contained in:
2026-09-09 23:11:48 -04:00
parent aaa9e2a370
commit 12eced8b19
8 changed files with 171 additions and 7 deletions
@@ -7,7 +7,13 @@ function createService({ product, condition }) {
return createInventoryItemService({
productRepository: { async findById() { return product; } },
conditionRepository: { async findById() { return condition; } },
inventoryItemRepository: { async create(inventoryItem) { return inventoryItem; } },
inventoryItemRepository: {
async create(inventoryItem) { return inventoryItem; },
async listBySellerId() { return []; },
async archiveByIdsForSeller(inventoryItemIds) {
return inventoryItemIds.map((id) => ({ id, status: 'ARCHIVED' }));
},
},
});
}
@@ -31,6 +37,48 @@ test('creates an inventory item when its condition belongs to the product catego
});
});
test('archives owned active inventory items in bulk', async () => {
const service = createInventoryItemService({
productRepository: { async findById() { return null; } },
conditionRepository: { async findById() { return null; } },
inventoryItemRepository: {
async listBySellerId() {
return [
{ id: 'item-1', status: 'ACTIVE' },
{ id: 'item-2', status: 'ACTIVE' },
];
},
async archiveByIdsForSeller(ids) {
return ids.map((id) => ({ id, status: 'ARCHIVED' }));
},
},
});
assert.deepEqual(
await service.archiveMany({ inventoryItemIds: ['item-1', 'item-2'], sellerId: 'seller-id' }),
[
{ id: 'item-1', status: 'ARCHIVED' },
{ id: 'item-2', status: 'ARCHIVED' },
],
);
});
test('does not archive sold inventory items', async () => {
const service = createInventoryItemService({
productRepository: { async findById() { return null; } },
conditionRepository: { async findById() { return null; } },
inventoryItemRepository: {
async listBySellerId() { return [{ id: 'item-1', status: 'SOLD' }]; },
async archiveByIdsForSeller() { throw new Error('should not update'); },
},
});
await assert.rejects(
() => service.archiveMany({ inventoryItemIds: ['item-1'], sellerId: 'seller-id' }),
/Inventory status cannot transition from SOLD to ARCHIVED/,
);
});
test('rejects conditions from another category', async () => {
const service = createService({
product: { id: 'product-id', sellerId: 'seller-id', categoryId: 'cards' },