1
0
Fork 0
mirror of https://github.com/s-frick/effigenix.git synced 2026-03-28 17:04:49 +01:00
effigenix/test-automation/web-ui/tests/api/masterdata/customers.spec.ts
2026-03-27 11:26:06 +01:00

119 lines
4.1 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-CUS Kunden
* Quelle: GitHub Issue #65
*/
test.describe('TC-CUS: Kunden', () => {
const baseAddress = {
street: 'Musterstraße',
houseNumber: '1',
postalCode: '10115',
city: 'Berlin',
country: 'DE',
phone: '+49 30 12345',
};
test('TC-CUS-01: Kunde erstellen Pflichtfelder (B2C)', async ({ request, adminToken }) => {
const res = await request.post('/api/customers', {
data: { name: `Müller ${Date.now()}`, type: 'B2C', ...baseAddress },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(201);
const body = await res.json();
expect(body.status).toBe('ACTIVE');
expect(body.type).toBe('B2C');
});
test('TC-CUS-02: B2B-Kunde erstellen', async ({ request, adminToken }) => {
const res = await request.post('/api/customers', {
data: {
name: `B2B GmbH ${Date.now()}`,
type: 'B2B',
...baseAddress,
contactPerson: 'Max Mustermann',
paymentDueDays: 30,
},
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(201);
const body = await res.json();
expect(body.type).toBe('B2B');
});
test('TC-CUS-03: Kunde erscheint in Liste nach Erstellung', async ({ request, adminToken }) => {
const name = `ListKunde-${Date.now()}`;
await request.post('/api/customers', {
data: { name, type: 'B2C', ...baseAddress },
headers: { Authorization: `Bearer ${adminToken}` },
});
const res = await request.get('/api/customers', {
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((c: { name: string }) => c.name === name)).toBe(true);
});
test('TC-CUS-04: Kunde ohne Name wird abgelehnt', async ({ request, adminToken }) => {
const res = await request.post('/api/customers', {
data: { type: 'B2C', ...baseAddress },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(400);
});
test('TC-CUS-05: Lieferadresse hinzufügen', async ({ request, adminToken }) => {
const createRes = await request.post('/api/customers', {
data: { name: `DelivAddr-${Date.now()}`, type: 'B2C', ...baseAddress },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(createRes.status()).toBe(201);
const { id } = await createRes.json();
const addrRes = await request.post(`/api/customers/${id}/delivery-addresses`, {
data: {
label: 'Lager',
street: 'Lagerstraße',
houseNumber: '5',
postalCode: '10117',
city: 'Berlin',
country: 'DE',
},
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(addrRes.status()).toBe(201);
});
test('TC-CUS-06: Kunde deaktivieren', async ({ request, adminToken }) => {
const createRes = await request.post('/api/customers', {
data: { name: `Deact-${Date.now()}`, type: 'B2C', ...baseAddress },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(createRes.status()).toBe(201);
const { id } = await createRes.json();
const deactRes = await request.post(`/api/customers/${id}/deactivate`, {
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(deactRes.status()).toBe(200);
const body = await deactRes.json();
expect(body.status).toBe('INACTIVE');
});
test('TC-CUS-07: Präferenzen setzen', async ({ request, adminToken }) => {
const createRes = await request.post('/api/customers', {
data: { name: `Prefs-${Date.now()}`, type: 'B2C', ...baseAddress },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(createRes.status()).toBe(201);
const { id } = await createRes.json();
const prefsRes = await request.put(`/api/customers/${id}/preferences`, {
data: { preferences: ['BIO', 'REGIONAL'] },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(prefsRes.status()).toBe(200);
});
});