import { test, expect } from '../../../fixtures/auth.fixture.js';

/**
 * TC-CAT – Produktkategorien
 * Quelle: GitHub Issue #62
 */
test.describe('TC-CAT: Produktkategorien', () => {
  test('TC-CAT-01: Kategorie erstellen – Happy Path', async ({ request, adminToken }) => {
    const res = await request.post('/api/product-categories', {
      data: { name: 'Obst & Gemüse', description: 'Frische Produkte' },
      headers: { Authorization: `Bearer ${adminToken}` },
    });
    expect(res.status()).toBe(201);
    const body = await res.json();
    expect(body.name).toBe('Obst & Gemüse');
    expect(body.description).toBe('Frische Produkte');
  });

  test('TC-CAT-02: Kategorie erstellen – ohne Beschreibung', async ({ request, adminToken }) => {
    const res = await request.post('/api/product-categories', {
      data: { name: `Milchprodukte-${Date.now()}` },
      headers: { Authorization: `Bearer ${adminToken}` },
    });
    expect(res.status()).toBe(201);
  });

  test('TC-CAT-04: Doppelter Name wird abgelehnt', async ({ request, adminToken }) => {
    const name = `Duplikat-${Date.now()}`;
    await request.post('/api/product-categories', {
      data: { name },
      headers: { Authorization: `Bearer ${adminToken}` },
    });
    const res = await request.post('/api/product-categories', {
      data: { name },
      headers: { Authorization: `Bearer ${adminToken}` },
    });
    expect([409, 422]).toContain(res.status());
  });

  test('TC-CAT-06: Leerer Name wird abgelehnt', async ({ request, adminToken }) => {
    const res = await request.post('/api/product-categories', {
      data: { name: '' },
      headers: { Authorization: `Bearer ${adminToken}` },
    });
    expect(res.status()).toBe(400);
  });
});
