1
0
Fork 0
mirror of https://github.com/s-frick/effigenix.git synced 2026-03-28 13:49:36 +01:00
This commit is contained in:
Janosch 2026-03-27 11:26:06 +01:00
parent e897f41a32
commit 061c2b4f8d
14 changed files with 1293 additions and 18 deletions

View file

@ -0,0 +1,151 @@
import { test, expect } from '../../../fixtures/auth.fixture.js';
/**
* TC-BAT Produktionschargen
* Quelle: GitHub Issues #33#36
*/
test.describe('TC-BAT: Produktionschargen', () => {
async function createActiveRecipe(request: Parameters<typeof test>[1]['request'], token: string): Promise<string> {
const catRes = await request.post('/api/categories', {
data: { name: `BAT-Kat-${Date.now()}` },
headers: { Authorization: `Bearer ${token}` },
});
const { id: categoryId } = await catRes.json();
const artRes = await request.post('/api/articles', {
data: {
name: `BAT-Art-${Date.now()}`,
articleNumber: `BAT-${Date.now()}`,
categoryId,
unit: 'KG',
priceModel: 'FIXED',
price: 1.5,
},
headers: { Authorization: `Bearer ${token}` },
});
const { id: articleId } = await artRes.json();
const recipeRes = await request.post('/api/recipes', {
data: {
name: `BAT-Rezept-${Date.now()}`,
version: 1,
type: 'FINISHED_PRODUCT',
outputQuantity: '10',
outputUom: 'KG',
articleId,
},
headers: { Authorization: `Bearer ${token}` },
});
const { id: recipeId } = await recipeRes.json();
await request.post(`/api/recipes/${recipeId}/activate`, {
headers: { Authorization: `Bearer ${token}` },
});
return recipeId;
}
test('TC-BAT-01: Charge planen PLANNED Status', async ({ request, adminToken }) => {
const recipeId = await createActiveRecipe(request, adminToken);
const res = await request.post('/api/production/batches', {
data: {
recipeId,
plannedQuantity: '20',
plannedQuantityUnit: 'KG',
productionDate: '2026-04-01',
bestBeforeDate: '2026-04-08',
},
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(201);
const body = await res.json();
expect(body.status).toBe('PLANNED');
expect(body.batchNumber).toBeTruthy();
});
test('TC-BAT-02: Charge starten', async ({ request, adminToken }) => {
const recipeId = await createActiveRecipe(request, adminToken);
const planRes = await request.post('/api/production/batches', {
data: {
recipeId,
plannedQuantity: '5',
plannedQuantityUnit: 'KG',
productionDate: '2026-04-02',
bestBeforeDate: '2026-04-09',
},
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(planRes.status()).toBe(201);
const { id } = await planRes.json();
const startRes = await request.post(`/api/production/batches/${id}/start`, {
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(startRes.status()).toBe(200);
const body = await startRes.json();
expect(body.status).toBe('IN_PRODUCTION');
});
test('TC-BAT-03: Charge abschließen', async ({ request, adminToken }) => {
const recipeId = await createActiveRecipe(request, adminToken);
const planRes = await request.post('/api/production/batches', {
data: {
recipeId,
plannedQuantity: '8',
plannedQuantityUnit: 'KG',
productionDate: '2026-04-03',
bestBeforeDate: '2026-04-10',
},
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(planRes.status()).toBe(201);
const { id } = await planRes.json();
await request.post(`/api/production/batches/${id}/start`, {
headers: { Authorization: `Bearer ${adminToken}` },
});
const completeRes = await request.post(`/api/production/batches/${id}/complete`, {
data: { actualQuantity: '7.5', actualQuantityUnit: 'KG', waste: '0.5', wasteUnit: 'KG' },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(completeRes.status()).toBe(200);
const body = await completeRes.json();
expect(body.status).toBe('COMPLETED');
});
test('TC-BAT-04: Charge ohne Rezept wird abgelehnt', async ({ request, adminToken }) => {
const res = await request.post('/api/production/batches', {
data: {
plannedQuantity: '10',
plannedQuantityUnit: 'KG',
productionDate: '2026-04-01',
bestBeforeDate: '2026-04-08',
},
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(400);
});
test('TC-BAT-05: Charge nach Nummer suchen', async ({ request, adminToken }) => {
const recipeId = await createActiveRecipe(request, adminToken);
const planRes = await request.post('/api/production/batches', {
data: {
recipeId,
plannedQuantity: '3',
plannedQuantityUnit: 'KG',
productionDate: '2026-04-04',
bestBeforeDate: '2026-04-11',
},
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(planRes.status()).toBe(201);
const { batchNumber } = await planRes.json();
const findRes = await request.get(`/api/production/batches/by-number/${batchNumber}`, {
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(findRes.status()).toBe(200);
const body = await findRes.json();
expect(body.batchNumber).toBe(batchNumber);
});
});