feat(phase-4b): backend business-logic, 8 entities, 32 endpoints, 58 tests

This commit is contained in:
CRM Bot
2026-06-03 21:40:26 +00:00
parent 955607f730
commit 53cbcde729
45 changed files with 3902 additions and 4 deletions
+55
View File
@@ -0,0 +1,55 @@
"""Tests for FR-3 (Contact entity)."""
from __future__ import annotations
import pytest
from httpx import AsyncClient
@pytest.mark.asyncio
async def test_create_contact_with_account(
client: AsyncClient, auth_headers: dict[str, str], seed_data: dict
) -> None:
acc_id = seed_data["account_ids"][0]
resp = await client.post(
"/api/v1/contacts/",
json={"first_name": "Diana", "last_name": "Prince", "email": "diana@x.example", "account_id": acc_id},
headers=auth_headers,
)
assert resp.status_code == 201, resp.text
body = resp.json()
assert body["account_id"] == acc_id
@pytest.mark.asyncio
async def test_create_contact_invalid_account(
client: AsyncClient, auth_headers: dict[str, str]
) -> None:
resp = await client.post(
"/api/v1/contacts/",
json={"first_name": "Eve", "last_name": "Adams", "account_id": 99999},
headers=auth_headers,
)
assert resp.status_code == 404
@pytest.mark.asyncio
async def test_list_contacts_filter_account(
client: AsyncClient, seed_data: dict
) -> None:
acc_id = seed_data["account_ids"][0]
resp = await client.get(f"/api/v1/contacts/?account_id={acc_id}", headers=seed_data["headers"])
assert resp.status_code == 200
body = resp.json()
assert all(c["account_id"] == acc_id for c in body)
@pytest.mark.asyncio
async def test_search_contacts_by_email(
client: AsyncClient, seed_data: dict
) -> None:
# seed_data creates contact with email 'anna@acme.example' on account 0
resp = await client.get("/api/v1/contacts/?q=anna@acme.example", headers=seed_data["headers"])
assert resp.status_code == 200
body = resp.json()
assert any("anna@acme.example" in (c.get("email") or "") for c in body)