From 8c4d9d4fd8405ba24cb0878607c3ba9674acb7c5 Mon Sep 17 00:00:00 2001 From: Leopoldadmin Date: Wed, 3 Jun 2026 23:52:07 +0000 Subject: [PATCH] Upload tests/test_contacts.py --- tests/test_contacts.py | 55 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/test_contacts.py diff --git a/tests/test_contacts.py b/tests/test_contacts.py new file mode 100644 index 0000000..f23f401 --- /dev/null +++ b/tests/test_contacts.py @@ -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)