import { test, expect } from '../../../fixtures/auth.fixture.js'; /** * TC-RES – Lagerreservierungen * Quelle: GitHub Issues #4–#20 */ test.describe('TC-RES: Lagerreservierungen', () => { async function setupStock( request: Parameters[1]['request'], token: string, ): Promise<{ stockId: string }> { const catRes = await request.post('/api/categories', { data: { name: `RES-Kat-${Date.now()}` }, headers: { Authorization: `Bearer ${token}` }, }); const { id: categoryId } = await catRes.json(); const artRes = await request.post('/api/articles', { data: { name: `RES-Art-${Date.now()}`, articleNumber: `RES-${Date.now()}`, categoryId, unit: 'KG', priceModel: 'FIXED', price: 2.0, }, headers: { Authorization: `Bearer ${token}` }, }); const { id: articleId } = await artRes.json(); const locRes = await request.post('/api/inventory/storage-locations', { data: { name: `RES-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(); await request.post(`/api/inventory/stocks/${stockId}/batches`, { data: { batchId: `RES-B-${Date.now()}`, batchType: 'PURCHASED', quantityAmount: '100', quantityUnit: 'KG', expiryDate: '2027-06-30', }, headers: { Authorization: `Bearer ${token}` }, }); return { stockId }; } test('TC-RES-01: Reservierung anlegen', async ({ request, adminToken }) => { const { stockId } = await setupStock(request, adminToken); const res = await request.post(`/api/inventory/stocks/${stockId}/reservations`, { data: { referenceType: 'PRODUCTION_ORDER', referenceId: `PO-${Date.now()}`, quantityAmount: '10', quantityUnit: 'KG', priority: 'NORMAL', }, headers: { Authorization: `Bearer ${adminToken}` }, }); expect(res.status()).toBe(201); const body = await res.json(); expect(body.id).toBeTruthy(); }); test('TC-RES-02: Reservierung freigeben', async ({ request, adminToken }) => { const { stockId } = await setupStock(request, adminToken); const createRes = await request.post(`/api/inventory/stocks/${stockId}/reservations`, { data: { referenceType: 'PRODUCTION_ORDER', referenceId: `PO-REL-${Date.now()}`, quantityAmount: '5', quantityUnit: 'KG', priority: 'NORMAL', }, headers: { Authorization: `Bearer ${adminToken}` }, }); expect(createRes.status()).toBe(201); const { id: reservationId } = await createRes.json(); const releaseRes = await request.delete(`/api/inventory/stocks/${stockId}/reservations/${reservationId}`, { headers: { Authorization: `Bearer ${adminToken}` }, }); expect(releaseRes.status()).toBe(204); }); test('TC-RES-03: Reservierung bestätigen', async ({ request, adminToken }) => { const { stockId } = await setupStock(request, adminToken); const createRes = await request.post(`/api/inventory/stocks/${stockId}/reservations`, { data: { referenceType: 'PRODUCTION_ORDER', referenceId: `PO-CONF-${Date.now()}`, quantityAmount: '8', quantityUnit: 'KG', priority: 'HIGH', }, headers: { Authorization: `Bearer ${adminToken}` }, }); expect(createRes.status()).toBe(201); const { id: reservationId } = await createRes.json(); const confirmRes = await request.post(`/api/inventory/stocks/${stockId}/reservations/${reservationId}/confirm`, { headers: { Authorization: `Bearer ${adminToken}` }, }); expect(confirmRes.status()).toBe(204); }); });