32 lines
1016 B
JavaScript
32 lines
1016 B
JavaScript
import assert from 'node:assert/strict';
|
|
import test from 'node:test';
|
|
|
|
import { createPublicInventoryService } from '../../src/modules/inventory/services/public-inventory-service.js';
|
|
|
|
test('lists visible public inventory through the repository boundary', async () => {
|
|
const service = createPublicInventoryService({
|
|
inventoryItemRepository: {
|
|
async searchPublic(filters) {
|
|
assert.deepEqual(filters, { page: 2, limit: 5 });
|
|
return { items: [{ id: 'inventory-1' }], total: 1 };
|
|
},
|
|
},
|
|
});
|
|
|
|
assert.deepEqual(await service.list({ page: 2, limit: 5 }), {
|
|
items: [{ id: 'inventory-1' }],
|
|
total: 1,
|
|
});
|
|
});
|
|
|
|
test('returns a not-found error for hidden public inventory', async () => {
|
|
const service = createPublicInventoryService({
|
|
inventoryItemRepository: { async findPublicById() { return null; } },
|
|
});
|
|
|
|
await assert.rejects(
|
|
() => service.getById('inventory-1'),
|
|
(error) => error.code === 'INVENTORY_NOT_FOUND' && error.statusCode === 404,
|
|
);
|
|
});
|