Upload tests/test_notes.py
This commit is contained in:
@@ -0,0 +1,69 @@
|
|||||||
|
"""Tests for FR-6 + R-2 (Note entity, polymorphic parent validation)."""
|
||||||
|
|
||||||
|
from __future__ import annotations
|
||||||
|
|
||||||
|
import pytest
|
||||||
|
from httpx import AsyncClient
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_create_note_with_valid_parent(
|
||||||
|
client: AsyncClient, auth_headers: dict[str, str], seed_data: dict
|
||||||
|
) -> None:
|
||||||
|
acc_id = seed_data["account_ids"][0]
|
||||||
|
resp = await client.post(
|
||||||
|
"/api/v1/notes/",
|
||||||
|
json={"body": "Great call", "parent_type": "account", "parent_id": acc_id},
|
||||||
|
headers=auth_headers,
|
||||||
|
)
|
||||||
|
assert resp.status_code == 201, resp.text
|
||||||
|
body = resp.json()
|
||||||
|
assert body["parent_type"] == "account"
|
||||||
|
assert body["parent_id"] == acc_id
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_create_note_with_invalid_parent(
|
||||||
|
client: AsyncClient, auth_headers: dict[str, str]
|
||||||
|
) -> None:
|
||||||
|
"""R-2: parent_type+parent_id must point to an existing entity; else 404."""
|
||||||
|
resp = await client.post(
|
||||||
|
"/api/v1/notes/",
|
||||||
|
json={"body": "Note into the void", "parent_type": "account", "parent_id": 99999},
|
||||||
|
headers=auth_headers,
|
||||||
|
)
|
||||||
|
assert resp.status_code == 404
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_list_notes_for_parent(client: AsyncClient, seed_data: dict) -> None:
|
||||||
|
acc_id = seed_data["account_ids"][0]
|
||||||
|
resp = await client.get(
|
||||||
|
f"/api/v1/notes/?parent_type=account&parent_id={acc_id}",
|
||||||
|
headers=seed_data["headers"],
|
||||||
|
)
|
||||||
|
assert resp.status_code == 200
|
||||||
|
body = resp.json()
|
||||||
|
assert all(n["parent_type"] == "account" and n["parent_id"] == acc_id for n in body)
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.asyncio
|
||||||
|
async def test_polymorphic_note_for_account_vs_contact(
|
||||||
|
client: AsyncClient, auth_headers: dict[str, str], seed_data: dict
|
||||||
|
) -> None:
|
||||||
|
acc_id = seed_data["account_ids"][0]
|
||||||
|
contact_id = seed_data["contact_ids"][0]
|
||||||
|
n_acc = await client.post(
|
||||||
|
"/api/v1/notes/",
|
||||||
|
json={"body": "Account note", "parent_type": "account", "parent_id": acc_id},
|
||||||
|
headers=auth_headers,
|
||||||
|
)
|
||||||
|
n_contact = await client.post(
|
||||||
|
"/api/v1/notes/",
|
||||||
|
json={"body": "Contact note", "parent_type": "contact", "parent_id": contact_id},
|
||||||
|
headers=auth_headers,
|
||||||
|
)
|
||||||
|
assert n_acc.status_code == 201, n_acc.text
|
||||||
|
assert n_contact.status_code == 201, n_contact.text
|
||||||
|
assert n_acc.json()["parent_type"] == "account"
|
||||||
|
assert n_contact.json()["parent_type"] == "contact"
|
||||||
Reference in New Issue
Block a user