feat(POS-002): completed feature
This commit is contained in:
@@ -9,6 +9,7 @@ import {
|
||||
} from '../../infrastructure/db/tests/db-test-support.js';
|
||||
import {
|
||||
createInventoryService,
|
||||
DEFAULT_STORE_ID,
|
||||
InsufficientStockError,
|
||||
type InventoryService,
|
||||
} from '../../modules/inventory/index.js';
|
||||
@@ -33,10 +34,12 @@ describe.skipIf(!hasDb)('inventory flows (real PostgreSQL)', () => {
|
||||
|
||||
it('allows exactly one concurrent reservation for the last unit (AC1)', async () => {
|
||||
const variantId = randomUUID();
|
||||
await inventory.setAvailable({ variantId, quantity: 1 });
|
||||
await inventory.setAvailable({ variantId, storeId: DEFAULT_STORE_ID, quantity: 1 });
|
||||
|
||||
const attempts = await Promise.allSettled(
|
||||
Array.from({ length: 10 }, () => inventory.reserve({ variantId, quantity: 1 })),
|
||||
Array.from({ length: 10 }, () =>
|
||||
inventory.reserve({ variantId, storeId: DEFAULT_STORE_ID, quantity: 1 }),
|
||||
),
|
||||
);
|
||||
|
||||
const fulfilled = attempts.filter((result) => result.status === 'fulfilled');
|
||||
@@ -47,7 +50,7 @@ describe.skipIf(!hasDb)('inventory flows (real PostgreSQL)', () => {
|
||||
expect(result.reason).toBeInstanceOf(InsufficientStockError);
|
||||
}
|
||||
|
||||
const availability = await inventory.checkAvailability(variantId, 1);
|
||||
const availability = await inventory.checkAvailability(variantId, DEFAULT_STORE_ID, 1);
|
||||
expect(availability).toEqual({ available: false, availableQuantity: 0 });
|
||||
const row = await pool.query(
|
||||
'SELECT available, reserved, sold, incoming FROM inventory_stock WHERE variant_id = $1',
|
||||
@@ -58,11 +61,11 @@ describe.skipIf(!hasDb)('inventory flows (real PostgreSQL)', () => {
|
||||
|
||||
it('rejects zero-stock reservations and never makes stock negative (AC2)', async () => {
|
||||
const variantId = randomUUID();
|
||||
await inventory.setAvailable({ variantId, quantity: 0 });
|
||||
await inventory.setAvailable({ variantId, storeId: DEFAULT_STORE_ID, quantity: 0 });
|
||||
|
||||
await expect(inventory.reserve({ variantId, quantity: 1 })).rejects.toBeInstanceOf(
|
||||
InsufficientStockError,
|
||||
);
|
||||
await expect(
|
||||
inventory.reserve({ variantId, storeId: DEFAULT_STORE_ID, quantity: 1 }),
|
||||
).rejects.toBeInstanceOf(InsufficientStockError);
|
||||
|
||||
const row = await pool.query(
|
||||
'SELECT available, reserved, sold, incoming FROM inventory_stock WHERE variant_id = $1',
|
||||
@@ -73,9 +76,9 @@ describe.skipIf(!hasDb)('inventory flows (real PostgreSQL)', () => {
|
||||
|
||||
it('exposes checkAvailability through the public InventoryService interface (AC4)', async () => {
|
||||
const variantId = randomUUID();
|
||||
await inventory.setAvailable({ variantId, quantity: 3 });
|
||||
await inventory.setAvailable({ variantId, storeId: DEFAULT_STORE_ID, quantity: 3 });
|
||||
|
||||
await expect(inventory.checkAvailability(variantId, 2)).resolves.toEqual({
|
||||
await expect(inventory.checkAvailability(variantId, DEFAULT_STORE_ID, 2)).resolves.toEqual({
|
||||
available: true,
|
||||
availableQuantity: 3,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user