feat: add unit and API tests for activities and tasks, including shared fixtures and scenarios
Test / test (push) Successful in 13s
Test / test (push) Successful in 13s
This commit is contained in:
@@ -0,0 +1,78 @@
|
||||
"""API tests for task endpoints."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import date, datetime, timedelta, timezone
|
||||
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
|
||||
|
||||
from app.models.task import Task
|
||||
|
||||
from tests.api.v1.task_activity_shared import auth_headers, create_deal, make_token, prepare_scenario
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_task_endpoint_creates_task_and_activity(
|
||||
session_factory: async_sessionmaker[AsyncSession], client: AsyncClient
|
||||
) -> None:
|
||||
scenario = await prepare_scenario(session_factory)
|
||||
token = make_token(scenario.user_id, scenario.user_email)
|
||||
due_date = (date.today() + timedelta(days=5)).isoformat()
|
||||
|
||||
response = await client.post(
|
||||
"/api/v1/tasks/",
|
||||
json={
|
||||
"deal_id": scenario.deal_id,
|
||||
"title": "Prepare proposal",
|
||||
"description": "Send draft",
|
||||
"due_date": due_date,
|
||||
},
|
||||
headers=auth_headers(token, scenario),
|
||||
)
|
||||
|
||||
assert response.status_code == 201
|
||||
payload = response.json()
|
||||
assert payload["deal_id"] == scenario.deal_id
|
||||
assert payload["title"] == "Prepare proposal"
|
||||
assert payload["is_done"] is False
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_tasks_endpoint_filters_by_deal(
|
||||
session_factory: async_sessionmaker[AsyncSession], client: AsyncClient
|
||||
) -> None:
|
||||
scenario = await prepare_scenario(session_factory)
|
||||
token = make_token(scenario.user_id, scenario.user_email)
|
||||
other_deal_id = await create_deal(session_factory, scenario=scenario, title="Renewal")
|
||||
|
||||
async with session_factory() as session:
|
||||
session.add_all(
|
||||
[
|
||||
Task(
|
||||
deal_id=scenario.deal_id,
|
||||
title="Task A",
|
||||
description=None,
|
||||
due_date=datetime.now(timezone.utc) + timedelta(days=2),
|
||||
is_done=False,
|
||||
),
|
||||
Task(
|
||||
deal_id=other_deal_id,
|
||||
title="Task B",
|
||||
description=None,
|
||||
due_date=datetime.now(timezone.utc) + timedelta(days=3),
|
||||
is_done=False,
|
||||
),
|
||||
]
|
||||
)
|
||||
await session.commit()
|
||||
|
||||
response = await client.get(
|
||||
f"/api/v1/tasks/?deal_id={scenario.deal_id}",
|
||||
headers=auth_headers(token, scenario),
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert len(data) == 1
|
||||
assert data[0]["title"] == "Task A"
|
||||
Reference in New Issue
Block a user