mirror of
https://github.com/sortedcord/alemno-payments.git
synced 2026-07-22 04:02:49 +05:30
feat: Add API endpoint for managing categories
This commit is contained in:
32
tests/api/test_categories_api.py
Normal file
32
tests/api/test_categories_api.py
Normal 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"]
|
||||
Reference in New Issue
Block a user