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/masterdata/articles.spec.ts
2026-03-27 11:26:06 +01:00

116 lines
4.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-ART Artikel
* Quelle: GitHub Issue #64
*/
test.describe('TC-ART: Artikel', () => {
async function createCategory(request: Parameters<typeof test>[1]['request'], token: string): Promise<string> {
const res = await request.post('/api/categories', {
data: { name: `ART-Kat-${Date.now()}` },
headers: { Authorization: `Bearer ${token}` },
});
const body = await res.json();
return body.id;
}
test('TC-ART-01: Artikel erstellen Pflichtfelder', async ({ request, adminToken }) => {
const categoryId = await createCategory(request, adminToken);
const res = await request.post('/api/articles', {
data: {
name: `Weizenbrot-${Date.now()}`,
articleNumber: `ART-${Date.now()}`,
categoryId,
unit: 'PIECE_FIXED',
priceModel: 'FIXED',
price: 2.99,
},
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(201);
const body = await res.json();
expect(body.status).toBe('ACTIVE');
});
test('TC-ART-02: Artikel erscheint in Liste nach Erstellung', async ({ request, adminToken }) => {
const categoryId = await createCategory(request, adminToken);
const name = `ListArt-${Date.now()}`;
const articleNumber = `ART-LIST-${Date.now()}`;
await request.post('/api/articles', {
data: { name, articleNumber, categoryId, unit: 'KG', priceModel: 'FIXED', price: 5.0 },
headers: { Authorization: `Bearer ${adminToken}` },
});
const res = await request.get('/api/articles', {
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(200);
const body = await res.json();
const list = Array.isArray(body) ? body : body.content ?? [];
expect(list.some((a: { name: string }) => a.name === name)).toBe(true);
});
test('TC-ART-03: Artikel ohne Name wird abgelehnt', async ({ request, adminToken }) => {
const categoryId = await createCategory(request, adminToken);
const res = await request.post('/api/articles', {
data: { articleNumber: `ART-${Date.now()}`, categoryId, unit: 'KG', priceModel: 'FIXED', price: 1.0 },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(400);
});
test('TC-ART-04: Artikel ohne Artikelnummer wird abgelehnt', async ({ request, adminToken }) => {
const categoryId = await createCategory(request, adminToken);
const res = await request.post('/api/articles', {
data: { name: `NoNumber-${Date.now()}`, categoryId, unit: 'KG', priceModel: 'FIXED', price: 1.0 },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(400);
});
test('TC-ART-05: Artikel deaktivieren', async ({ request, adminToken }) => {
const categoryId = await createCategory(request, adminToken);
const createRes = await request.post('/api/articles', {
data: {
name: `Deact-${Date.now()}`,
articleNumber: `ART-DEACT-${Date.now()}`,
categoryId,
unit: 'PIECE_FIXED',
priceModel: 'FIXED',
price: 1.5,
},
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(createRes.status()).toBe(201);
const { id } = await createRes.json();
const deactRes = await request.post(`/api/articles/${id}/deactivate`, {
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(deactRes.status()).toBe(200);
const body = await deactRes.json();
expect(body.status).toBe('INACTIVE');
});
test('TC-ART-06: Verkaufseinheit hinzufügen', async ({ request, adminToken }) => {
const categoryId = await createCategory(request, adminToken);
const createRes = await request.post('/api/articles', {
data: {
name: `SalesUnit-${Date.now()}`,
articleNumber: `ART-SU-${Date.now()}`,
categoryId,
unit: 'KG',
priceModel: 'FIXED',
price: 3.0,
},
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(createRes.status()).toBe(201);
const { id } = await createRes.json();
const suRes = await request.post(`/api/articles/${id}/sales-units`, {
data: { unit: 'HUNDRED_GRAM', priceModel: 'FIXED', price: 0.3 },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(suRes.status()).toBe(201);
});
});