37 lines
1.4 KiB
TypeScript
37 lines
1.4 KiB
TypeScript
import { describe, it, expect } from 'vitest';
|
|
import { placeOrder, receiveDeliveries } from '../../src/sim/orders';
|
|
import { createNewGame } from '../../src/sim/state';
|
|
import { backroomQty } from '../../src/sim/inventory';
|
|
import { testCatalog } from './helpers';
|
|
|
|
const catalog = testCatalog();
|
|
|
|
describe('orders', () => {
|
|
it('charges the wholesale cost and queues the delivery', () => {
|
|
const s = createNewGame(1);
|
|
const cashBefore = s.cash;
|
|
expect(placeOrder(s, catalog, 'sml', 3)).toBe(2467 * 3);
|
|
expect(s.cash).toBe(cashBefore - 2467 * 3);
|
|
expect(s.day.expensesCents).toBe(2467 * 3);
|
|
expect(s.pendingOrders).toEqual([{ item: { gameId: 'sml', condition: 'new' }, qty: 3 }]);
|
|
});
|
|
|
|
it('rejects invalid orders', () => {
|
|
const s = createNewGame(1);
|
|
expect(() => placeOrder(s, catalog, 'sml', 0)).toThrow('Quantity must be positive');
|
|
expect(() => placeOrder(s, catalog, 'future', 1)).toThrow('Not released yet: future');
|
|
s.cash = 100;
|
|
expect(() => placeOrder(s, catalog, 'sml', 1)).toThrow('Not enough cash');
|
|
});
|
|
|
|
it('moves deliveries into the backroom', () => {
|
|
const s = createNewGame(1);
|
|
placeOrder(s, catalog, 'sml', 2);
|
|
placeOrder(s, catalog, 'sml', 1);
|
|
const delivered = receiveDeliveries(s);
|
|
expect(delivered).toHaveLength(2);
|
|
expect(backroomQty(s.inventory, { gameId: 'sml', condition: 'new' })).toBe(3);
|
|
expect(s.pendingOrders).toEqual([]);
|
|
});
|
|
});
|