feat(POS-002): completed feature
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { InventoryServicePort } from '../../inventory/index.js';
|
||||
import { DEFAULT_STORE_ID, type InventoryServicePort } from '../../inventory/index.js';
|
||||
import type { OrderItemInput, OrderServicePort } from '../../orders/index.js';
|
||||
import type { PricingServicePort } from '../../pricing/index.js';
|
||||
import type { PromotionServicePort } from '../../promotions/index.js';
|
||||
@@ -97,6 +97,7 @@ export class CheckoutService {
|
||||
}
|
||||
const availability = await this.deps.inventory.checkAvailability(
|
||||
cartItem.variantId,
|
||||
DEFAULT_STORE_ID,
|
||||
cartItem.quantity,
|
||||
);
|
||||
if (!availability.available) {
|
||||
@@ -174,12 +175,18 @@ export class CheckoutService {
|
||||
const reserved: string[] = [];
|
||||
try {
|
||||
for (const item of cart.items) {
|
||||
await this.deps.inventory.reserve({ variantId: item.variantId, quantity: item.quantity });
|
||||
await this.deps.inventory.reserve({
|
||||
variantId: item.variantId,
|
||||
storeId: DEFAULT_STORE_ID,
|
||||
quantity: item.quantity,
|
||||
});
|
||||
reserved.push(item.variantId);
|
||||
}
|
||||
} catch (error) {
|
||||
for (const variantId of reserved) {
|
||||
await this.deps.inventory.release({ variantId, quantity: 1 }).catch(() => undefined);
|
||||
await this.deps.inventory
|
||||
.release({ variantId, storeId: DEFAULT_STORE_ID, quantity: 1 })
|
||||
.catch(() => undefined);
|
||||
}
|
||||
await this.deps.orders
|
||||
.transition(orderView.id, 'CANCELLED', command.userId)
|
||||
|
||||
@@ -211,7 +211,13 @@ describe('CheckoutService', () => {
|
||||
idempotencyKey: 'k-1',
|
||||
});
|
||||
expect(result.order.state).toBe('AWAITING_PAYMENT');
|
||||
expect(deps.reserved.calls).toEqual([{ variantId: 'v-1', quantity: 1 }]);
|
||||
expect(deps.reserved.calls).toEqual([
|
||||
{
|
||||
variantId: 'v-1',
|
||||
storeId: '00000000-0000-0000-0000-000000000001',
|
||||
quantity: 1,
|
||||
},
|
||||
]);
|
||||
expect(deps.metrics.success).toBe(1);
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user