1
0
Fork 0
mirror of https://github.com/s-frick/effigenix.git synced 2026-03-28 10:09:35 +01:00
effigenix/test-automation/web-ui/tests/api/production/traceability.spec.ts
2026-03-27 11:26:06 +01:00

88 lines
3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { test, expect } from '../../../fixtures/auth.fixture.js';
/**
* TC-TRACE Chargen-Rückverfolgung
* Quelle: GitHub Issues #43#44
*/
test.describe('TC-TRACE: Chargen-Rückverfolgung', () => {
async function createPlannedBatch(request: Parameters<typeof test>[1]['request'], token: string): Promise<{ batchId: string; batchNumber: string }> {
const catRes = await request.post('/api/categories', {
data: { name: `TRC-Kat-${Date.now()}` },
headers: { Authorization: `Bearer ${token}` },
});
const { id: categoryId } = await catRes.json();
const artRes = await request.post('/api/articles', {
data: {
name: `TRC-Art-${Date.now()}`,
articleNumber: `TRC-${Date.now()}`,
categoryId,
unit: 'KG',
priceModel: 'FIXED',
price: 2.0,
},
headers: { Authorization: `Bearer ${token}` },
});
const { id: articleId } = await artRes.json();
const recipeRes = await request.post('/api/recipes', {
data: {
name: `TRC-Rezept-${Date.now()}`,
version: 1,
type: 'FINISHED_PRODUCT',
outputQuantity: '5',
outputUom: 'KG',
articleId,
},
headers: { Authorization: `Bearer ${token}` },
});
const { id: recipeId } = await recipeRes.json();
await request.post(`/api/recipes/${recipeId}/activate`, {
headers: { Authorization: `Bearer ${token}` },
});
const batchRes = await request.post('/api/production/batches', {
data: {
recipeId,
plannedQuantity: '5',
plannedQuantityUnit: 'KG',
productionDate: '2026-06-01',
bestBeforeDate: '2026-06-08',
},
headers: { Authorization: `Bearer ${token}` },
});
expect(batchRes.status()).toBe(201);
const batch = await batchRes.json();
return { batchId: batch.id, batchNumber: batch.batchNumber };
}
test('TC-TRACE-01: Vorwärts-Verfolgung einer Charge', async ({ request, adminToken }) => {
const { batchId } = await createPlannedBatch(request, adminToken);
const res = await request.get(`/api/production/batches/${batchId}/trace-forward`, {
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(200);
const body = await res.json();
expect(body).toHaveProperty('batchId');
});
test('TC-TRACE-02: Rückwärts-Verfolgung einer Charge', async ({ request, adminToken }) => {
const { batchId } = await createPlannedBatch(request, adminToken);
const res = await request.get(`/api/production/batches/${batchId}/trace-backward`, {
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(200);
const body = await res.json();
expect(body).toHaveProperty('batchId');
});
test('TC-TRACE-03: Rückverfolgung einer nicht vorhandenen Charge gibt 404', async ({ request, adminToken }) => {
const res = await request.get('/api/production/batches/non-existent-id/trace-forward', {
headers: { Authorization: `Bearer ${adminToken}` },
});
expect([404, 400]).toContain(res.status());
});
});