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

92 lines
3.2 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-B2B Rahmenverträge (Frame Contracts)
* Quelle: GitHub Issue #66
*/
test.describe('TC-B2B: Rahmenverträge', () => {
const baseAddress = {
street: 'Handelsweg',
houseNumber: '10',
postalCode: '20095',
city: 'Hamburg',
country: 'DE',
phone: '+49 40 99999',
};
async function createB2bCustomer(request: Parameters<typeof test>[1]['request'], token: string): Promise<string> {
const res = await request.post('/api/customers', {
data: { name: `B2B-${Date.now()}`, type: 'B2B', ...baseAddress, paymentDueDays: 30 },
headers: { Authorization: `Bearer ${token}` },
});
const body = await res.json();
return body.id;
}
async function createArticleWithCategory(request: Parameters<typeof test>[1]['request'], token: string): Promise<string> {
const catRes = await request.post('/api/categories', {
data: { name: `B2B-Kat-${Date.now()}` },
headers: { Authorization: `Bearer ${token}` },
});
const { id: categoryId } = await catRes.json();
const artRes = await request.post('/api/articles', {
data: {
name: `B2B-Art-${Date.now()}`,
articleNumber: `B2B-${Date.now()}`,
categoryId,
unit: 'KG',
priceModel: 'FIXED',
price: 4.5,
},
headers: { Authorization: `Bearer ${token}` },
});
const { id } = await artRes.json();
return id;
}
test('TC-B2B-01: Rahmenvertrag setzen', async ({ request, adminToken }) => {
const customerId = await createB2bCustomer(request, adminToken);
const articleId = await createArticleWithCategory(request, adminToken);
const res = await request.put(`/api/customers/${customerId}/frame-contract`, {
data: {
validFrom: '2026-01-01',
validUntil: '2026-12-31',
rhythm: 'WEEKLY',
lineItems: [{ articleId, agreedPrice: 4.0, agreedQuantity: 10.0, unit: 'KG' }],
},
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(200);
const body = await res.json();
expect(body.frameContract).toBeTruthy();
});
test('TC-B2B-02: Rahmenvertrag ohne Positionen wird abgelehnt', async ({ request, adminToken }) => {
const customerId = await createB2bCustomer(request, adminToken);
const res = await request.put(`/api/customers/${customerId}/frame-contract`, {
data: { rhythm: 'WEEKLY', lineItems: [] },
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(400);
});
test('TC-B2B-03: Rahmenvertrag entfernen', async ({ request, adminToken }) => {
const customerId = await createB2bCustomer(request, adminToken);
const articleId = await createArticleWithCategory(request, adminToken);
await request.put(`/api/customers/${customerId}/frame-contract`, {
data: {
rhythm: 'MONTHLY',
lineItems: [{ articleId, agreedPrice: 3.0 }],
},
headers: { Authorization: `Bearer ${adminToken}` },
});
const res = await request.delete(`/api/customers/${customerId}/frame-contract`, {
headers: { Authorization: `Bearer ${adminToken}` },
});
expect(res.status()).toBe(204);
});
});