"""Workflow CRUD tests — Go/Gin backend.""" import pytest from httpx import AsyncClient from tests.conftest import auth_header class TestListWorkflows: async def test_list_workflows(self, client: AsyncClient, admin_token: str): resp = await client.get("/api/v1/workflows", headers=auth_header(admin_token)) assert resp.status_code == 200 data = resp.json() assert isinstance(data, list) async def test_no_auth(self, client: AsyncClient): resp = await client.get("/api/v1/workflows") assert resp.status_code == 401 class TestCreateWorkflow: async def test_create_success(self, client: AsyncClient, admin_token: str): import uuid resp = await client.post("/api/v1/workflows", headers=auth_header(admin_token), json={ "name": f"wf-test-{uuid.uuid4().hex[:6]}", "description": "Test workflow", "is_active": True, }) assert resp.status_code == 201 data = resp.json() assert "id" in data assert "message" in data async def test_create_with_category(self, client: AsyncClient, admin_token: str): import uuid resp = await client.post("/api/v1/workflows", headers=auth_header(admin_token), json={ "name": f"wf-cat-{uuid.uuid4().hex[:6]}", "description": "With category", "category": "ticket", "is_active": True, }) assert resp.status_code == 201 class TestGetWorkflow: async def test_get_existing(self, client: AsyncClient, admin_token: str): # List first lst = await client.get("/api/v1/workflows", headers=auth_header(admin_token)) wfs = lst.json() if not wfs: pytest.skip("No workflows") wf_id = wfs[0]["id"] resp = await client.get(f"/api/v1/workflows/{wf_id}", headers=auth_header(admin_token)) assert resp.status_code == 200 data = resp.json() assert data["id"] == wf_id assert "name" in data assert "steps" in data assert "is_active" in data class TestUpdateWorkflow: async def test_update_name(self, client: AsyncClient, admin_token: str): lst = await client.get("/api/v1/workflows", headers=auth_header(admin_token)) wfs = lst.json() if not wfs: pytest.skip("No workflows") wf_id = wfs[0]["id"] resp = await client.put( f"/api/v1/workflows/{wf_id}", headers=auth_header(admin_token), json={"name": "updated-name", "description": "updated desc"}, ) assert resp.status_code == 200 class TestDeleteWorkflow: async def test_delete_not_found(self, client: AsyncClient, admin_token: str): resp = await client.delete("/api/v1/workflows/99999", headers=auth_header(admin_token)) assert resp.status_code in (200, 404)