1
0
Fork 0
mirror of https://github.com/s-frick/effigenix.git synced 2026-03-28 19:00:23 +01:00
effigenix/test-automation/web-ui/tests/api/inventory/stock.spec.ts
2026-03-27 11:26:06 +01:00

116 lines
4.5 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-STOCK Lagerbestand
* Quelle: GitHub Issues #4#20
*/
test.describe('TC-STOCK: Lagerbestand', () => {
async function createStorageLocation(request: Parameters<typeof test>[1]['request'], token: string): Promise<string> {
const res = await request.post('/api/inventory/storage-locations', {
data: { name: `Lager-${Date.now()}`, storageType: 'DRY_STORAGE' },
headers: { Authorization: `Bearer ${token}` },
});
const body = await res.json();
return body.id;
}
async function createArticle(request: Parameters<typeof test>[1]['request'], token: string): Promise<string> {
const catRes = await request.post('/api/categories', {
data: { name: `ST-Kat-${Date.now()}` },
headers: { Authorization: `Bearer ${token}` },
});
const { id: categoryId } = await catRes.json();
const artRes = await request.post('/api/articles', {
data: {
name: `ST-Art-${Date.now()}`,
articleNumber: `ST-${Date.now()}`,
categoryId,
unit: 'KG',
priceModel: 'FIXED',
price: 1.0,
},
headers: { Authorization: `Bearer ${token}` },
});
const { id } = await artRes.json();
return id;
}
test('TC-STOCK-01: Lagerort erstellen', async ({ request, adminToken }) => {
const res = await request.post('/api/inventory/storage-locations', {
data: { name: `Kühlraum-${Date.now()}`, storageType: 'COLD_ROOM', minTemperature: '2', maxTemperature: '8' },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(201);
const body = await res.json();
expect(body.storageType).toBe('COLD_ROOM');
});
test('TC-STOCK-02: Lagerort ohne Name wird abgelehnt', async ({ request, adminToken }) => {
const res = await request.post('/api/inventory/storage-locations', {
data: { storageType: 'FREEZER' },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(400);
});
test('TC-STOCK-03: Bestand anlegen', async ({ request, adminToken }) => {
const storageLocationId = await createStorageLocation(request, adminToken);
const articleId = await createArticle(request, adminToken);
const res = await request.post('/api/inventory/stocks', {
data: { articleId, storageLocationId, minimumLevelAmount: '5', minimumLevelUnit: 'KG' },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(201);
});
test('TC-STOCK-04: Bestand ohne Artikel wird abgelehnt', async ({ request, adminToken }) => {
const storageLocationId = await createStorageLocation(request, adminToken);
const res = await request.post('/api/inventory/stocks', {
data: { storageLocationId },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(400);
});
test('TC-STOCK-05: Batch zum Bestand hinzufügen', async ({ request, adminToken }) => {
const storageLocationId = await createStorageLocation(request, adminToken);
const articleId = await createArticle(request, adminToken);
const stockRes = await request.post('/api/inventory/stocks', {
data: { articleId, storageLocationId },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(stockRes.status()).toBe(201);
const { id: stockId } = await stockRes.json();
const batchRes = await request.post(`/api/inventory/stocks/${stockId}/batches`, {
data: {
batchId: `BATCH-${Date.now()}`,
batchType: 'PURCHASED',
quantityAmount: '10',
quantityUnit: 'KG',
expiryDate: '2026-12-31',
},
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(batchRes.status()).toBe(201);
});
test('TC-STOCK-06: Bestände unterhalb Mindestmenge abfragen', async ({ request, adminToken }) => {
const res = await request.get('/api/inventory/stocks/below-minimum', {
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(200);
expect(Array.isArray(await res.json())).toBe(true);
});
test('TC-STOCK-07: Bestände nach Lagerort filtern', async ({ request, adminToken }) => {
const storageLocationId = await createStorageLocation(request, adminToken);
const res = await request.get(`/api/inventory/stocks?storageLocationId=${storageLocationId}`, {
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(200);
expect(Array.isArray(await res.json())).toBe(true);
});
});