feat: Add API endpoint for managing categories

This commit is contained in:
2026-07-03 08:33:48 +05:30
parent be6c95c497
commit 8488e3bdd0
15 changed files with 413 additions and 48 deletions

View File

@@ -0,0 +1,32 @@
import pytest
from httpx import AsyncClient
pytestmark = pytest.mark.asyncio
async def test_get_categories_seeded_defaults(client: AsyncClient):
# Retrieve categories and verify the default list is present (since lifespan seeds them)
response = await client.get("/api/v1/categories")
assert response.status_code == 200
categories = response.json()
assert len(categories) >= 8
names = [c["name"] for c in categories]
assert "Food" in names
assert "Shopping" in names
assert "Travel" in names
assert "Other" in names
async def test_create_and_duplicate_category(client: AsyncClient):
# 1. Create a new category
response = await client.post("/api/v1/categories", json={"name": "Medical"})
assert response.status_code == 201
data = response.json()
assert "id" in data
assert data["name"] == "Medical"
# 2. Try creating the same category (duplicate, case-insensitive check)
dup_response = await client.post("/api/v1/categories", json={"name": "medical"})
assert dup_response.status_code == 400
assert "already exists" in dup_response.json()["detail"]