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,63 @@
|
||||
"""API tests for activity endpoints."""
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime, timedelta, timezone
|
||||
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
from sqlalchemy.ext.asyncio import AsyncSession, async_sessionmaker
|
||||
|
||||
from app.models.activity import Activity, ActivityType
|
||||
|
||||
from tests.api.v1.task_activity_shared import auth_headers, make_token, prepare_scenario
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_create_activity_comment_endpoint(
|
||||
session_factory: async_sessionmaker[AsyncSession], client: AsyncClient
|
||||
) -> None:
|
||||
scenario = await prepare_scenario(session_factory)
|
||||
token = make_token(scenario.user_id, scenario.user_email)
|
||||
|
||||
response = await client.post(
|
||||
f"/api/v1/deals/{scenario.deal_id}/activities/",
|
||||
json={"type": "comment", "payload": {"text": " hello world "}},
|
||||
headers=auth_headers(token, scenario),
|
||||
)
|
||||
|
||||
assert response.status_code == 201
|
||||
payload = response.json()
|
||||
assert payload["payload"]["text"] == "hello world"
|
||||
assert payload["type"] == ActivityType.COMMENT.value
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_list_activities_endpoint_supports_pagination(
|
||||
session_factory: async_sessionmaker[AsyncSession], client: AsyncClient
|
||||
) -> None:
|
||||
scenario = await prepare_scenario(session_factory)
|
||||
token = make_token(scenario.user_id, scenario.user_email)
|
||||
|
||||
base_time = datetime.now(timezone.utc)
|
||||
async with session_factory() as session:
|
||||
for index in range(3):
|
||||
activity = Activity(
|
||||
deal_id=scenario.deal_id,
|
||||
author_id=scenario.user_id,
|
||||
type=ActivityType.COMMENT,
|
||||
payload={"text": f"Entry {index}"},
|
||||
created_at=base_time + timedelta(seconds=index),
|
||||
)
|
||||
session.add(activity)
|
||||
await session.commit()
|
||||
|
||||
response = await client.get(
|
||||
f"/api/v1/deals/{scenario.deal_id}/activities/?limit=2&offset=1",
|
||||
headers=auth_headers(token, scenario),
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert len(data) == 2
|
||||
assert data[0]["payload"]["text"] == "Entry 1"
|
||||
assert data[1]["payload"]["text"] == "Entry 2"
|
||||
Reference in New Issue
Block a user