mirror of
https://github.com/s-frick/effigenix.git
synced 2026-03-28 19:20:23 +01:00
141 lines
4.9 KiB
TypeScript
141 lines
4.9 KiB
TypeScript
import { test, expect } from '../../../fixtures/auth.fixture.js';
|
||
|
||
/**
|
||
* TC-REC – Rezepte
|
||
* Quelle: GitHub Issues #26–#32
|
||
*/
|
||
test.describe('TC-REC: Rezepte', () => {
|
||
async function createArticle(request: Parameters<typeof test>[1]['request'], token: string): Promise<string> {
|
||
const catRes = await request.post('/api/categories', {
|
||
data: { name: `Kat-${Date.now()}` },
|
||
headers: { Authorization: `Bearer ${token}` },
|
||
});
|
||
const { id: categoryId } = await catRes.json();
|
||
const artRes = await request.post('/api/articles', {
|
||
data: {
|
||
name: `Art-${Date.now()}`,
|
||
articleNumber: `ART-${Date.now()}`,
|
||
categoryId,
|
||
unit: 'KG',
|
||
priceModel: 'FIXED',
|
||
price: 2.0,
|
||
},
|
||
headers: { Authorization: `Bearer ${token}` },
|
||
});
|
||
const { id } = await artRes.json();
|
||
return id;
|
||
}
|
||
|
||
test('TC-REC-01: Rezept erstellen – DRAFT Status', async ({ request, adminToken }) => {
|
||
const articleId = await createArticle(request, adminToken);
|
||
const res = await request.post('/api/recipes', {
|
||
data: {
|
||
name: `Brot-${Date.now()}`,
|
||
version: 1,
|
||
type: 'FINISHED_PRODUCT',
|
||
outputQuantity: '10',
|
||
outputUom: 'KG',
|
||
articleId,
|
||
},
|
||
headers: { Authorization: `Bearer ${adminToken}` },
|
||
});
|
||
expect(res.status()).toBe(201);
|
||
const body = await res.json();
|
||
expect(body.status).toBe('DRAFT');
|
||
});
|
||
|
||
test('TC-REC-02: Rezept ohne Name wird abgelehnt', async ({ request, adminToken }) => {
|
||
const articleId = await createArticle(request, adminToken);
|
||
const res = await request.post('/api/recipes', {
|
||
data: { version: 1, type: 'FINISHED_PRODUCT', outputQuantity: '10', outputUom: 'KG', articleId },
|
||
headers: { Authorization: `Bearer ${adminToken}` },
|
||
});
|
||
expect(res.status()).toBe(400);
|
||
});
|
||
|
||
test('TC-REC-03: Zutat zu Rezept hinzufügen', async ({ request, adminToken }) => {
|
||
const articleId = await createArticle(request, adminToken);
|
||
const recipeRes = await request.post('/api/recipes', {
|
||
data: {
|
||
name: `Rezept-Zutaten-${Date.now()}`,
|
||
version: 1,
|
||
type: 'FINISHED_PRODUCT',
|
||
outputQuantity: '5',
|
||
outputUom: 'KG',
|
||
articleId,
|
||
},
|
||
headers: { Authorization: `Bearer ${adminToken}` },
|
||
});
|
||
expect(recipeRes.status()).toBe(201);
|
||
const { id: recipeId } = await recipeRes.json();
|
||
|
||
const ingredientArticleId = await createArticle(request, adminToken);
|
||
const ingRes = await request.post(`/api/recipes/${recipeId}/ingredients`, {
|
||
data: { position: 1, articleId: ingredientArticleId, quantity: '2', uom: 'KG', substitutable: false },
|
||
headers: { Authorization: `Bearer ${adminToken}` },
|
||
});
|
||
expect(ingRes.status()).toBe(201);
|
||
});
|
||
|
||
test('TC-REC-04: Rezept aktivieren', async ({ request, adminToken }) => {
|
||
const articleId = await createArticle(request, adminToken);
|
||
const recipeRes = await request.post('/api/recipes', {
|
||
data: {
|
||
name: `Aktivieren-${Date.now()}`,
|
||
version: 1,
|
||
type: 'INTERMEDIATE',
|
||
outputQuantity: '3',
|
||
outputUom: 'KG',
|
||
articleId,
|
||
},
|
||
headers: { Authorization: `Bearer ${adminToken}` },
|
||
});
|
||
expect(recipeRes.status()).toBe(201);
|
||
const { id: recipeId } = await recipeRes.json();
|
||
|
||
const activateRes = await request.post(`/api/recipes/${recipeId}/activate`, {
|
||
headers: { Authorization: `Bearer ${adminToken}` },
|
||
});
|
||
expect(activateRes.status()).toBe(200);
|
||
const body = await activateRes.json();
|
||
expect(body.status).toBe('ACTIVE');
|
||
});
|
||
|
||
test('TC-REC-05: Rezept archivieren', async ({ request, adminToken }) => {
|
||
const articleId = await createArticle(request, adminToken);
|
||
const recipeRes = await request.post('/api/recipes', {
|
||
data: {
|
||
name: `Archiv-${Date.now()}`,
|
||
version: 1,
|
||
type: 'RAW_MATERIAL',
|
||
outputQuantity: '1',
|
||
outputUom: 'KG',
|
||
articleId,
|
||
},
|
||
headers: { Authorization: `Bearer ${adminToken}` },
|
||
});
|
||
expect(recipeRes.status()).toBe(201);
|
||
const { id: recipeId } = await recipeRes.json();
|
||
|
||
await request.post(`/api/recipes/${recipeId}/activate`, {
|
||
headers: { Authorization: `Bearer ${adminToken}` },
|
||
});
|
||
|
||
const archiveRes = await request.post(`/api/recipes/${recipeId}/archive`, {
|
||
headers: { Authorization: `Bearer ${adminToken}` },
|
||
});
|
||
expect(archiveRes.status()).toBe(200);
|
||
const body = await archiveRes.json();
|
||
expect(body.status).toBe('ARCHIVED');
|
||
});
|
||
|
||
test('TC-REC-06: Rezepte nach Status filtern', async ({ request, adminToken }) => {
|
||
const res = await request.get('/api/recipes?status=DRAFT', {
|
||
headers: { Authorization: `Bearer ${adminToken}` },
|
||
});
|
||
expect(res.status()).toBe(200);
|
||
const body = await res.json();
|
||
const list = Array.isArray(body) ? body : body.content ?? [];
|
||
expect(Array.isArray(list)).toBe(true);
|
||
});
|
||
});
|