import { test, expect } from '../../../fixtures/auth.fixture.js'; /** * TC-MOV – Warenbewegungen * Quelle: GitHub Issues #4–#20 */ test.describe('TC-MOV: Warenbewegungen', () => { async function setupStockWithBatch( request: Parameters[1]['request'], token: string, ): Promise<{ stockId: string; stockBatchId: string; articleId: string; batchId: string }> { const catRes = await request.post('/api/categories', { data: { name: `MOV-Kat-${Date.now()}` }, headers: { Authorization: `Bearer ${token}` }, }); const { id: categoryId } = await catRes.json(); const artRes = await request.post('/api/articles', { data: { name: `MOV-Art-${Date.now()}`, articleNumber: `MOV-${Date.now()}`, categoryId, unit: 'KG', priceModel: 'FIXED', price: 1.0, }, headers: { Authorization: `Bearer ${token}` }, }); const { id: articleId } = await artRes.json(); const locRes = await request.post('/api/inventory/storage-locations', { data: { name: `MOV-Lager-${Date.now()}`, storageType: 'DRY_STORAGE' }, headers: { Authorization: `Bearer ${token}` }, }); const { id: storageLocationId } = await locRes.json(); const stockRes = await request.post('/api/inventory/stocks', { data: { articleId, storageLocationId }, headers: { Authorization: `Bearer ${token}` }, }); expect(stockRes.status()).toBe(201); const { id: stockId } = await stockRes.json(); const batchId = `B-${Date.now()}`; const batchRes = await request.post(`/api/inventory/stocks/${stockId}/batches`, { data: { batchId, batchType: 'PURCHASED', quantityAmount: '20', quantityUnit: 'KG', expiryDate: '2026-12-31', }, headers: { Authorization: `Bearer ${token}` }, }); expect(batchRes.status()).toBe(201); const { id: stockBatchId } = await batchRes.json(); return { stockId, stockBatchId, articleId, batchId }; } test('TC-MOV-01: Warenbewegung erfassen – Wareneingang', async ({ request, adminToken }) => { const { stockId, stockBatchId, articleId, batchId } = await setupStockWithBatch(request, adminToken); const res = await request.post('/api/inventory/stock-movements', { data: { stockId, articleId, stockBatchId, batchId, batchType: 'PURCHASED', movementType: 'GOODS_RECEIPT', quantityAmount: '5', quantityUnit: 'KG', }, headers: { Authorization: `Bearer ${adminToken}` }, }); expect(res.status()).toBe(201); const body = await res.json(); expect(body.movementType).toBe('GOODS_RECEIPT'); }); test('TC-MOV-02: Warenbewegung ohne Pflichtfelder wird abgelehnt', async ({ request, adminToken }) => { const res = await request.post('/api/inventory/stock-movements', { data: { movementType: 'GOODS_RECEIPT' }, headers: { Authorization: `Bearer ${adminToken}` }, }); expect(res.status()).toBe(400); }); test('TC-MOV-03: Warenbewegungen nach Stock auflisten', async ({ request, adminToken }) => { const { stockId } = await setupStockWithBatch(request, adminToken); const res = await request.get(`/api/inventory/stock-movements?stockId=${stockId}`, { headers: { Authorization: `Bearer ${adminToken}` }, }); expect(res.status()).toBe(200); expect(Array.isArray(await res.json())).toBe(true); }); });