refactor(todo): 移除 due_at 字段,改用 order 字段管理象限内顺序
This commit is contained in:
@@ -0,0 +1,65 @@
|
||||
from pydantic import ValidationError
|
||||
|
||||
from v1.todo.schemas import TodoCreate, TodoReorderRequest, TodoResponse, TodoUpdate
|
||||
|
||||
|
||||
def test_todo_create_accepts_zero_based_order() -> None:
|
||||
request = TodoCreate.model_validate({"title": "Test", "priority": 1, "order": 0})
|
||||
|
||||
assert request.order == 0
|
||||
|
||||
|
||||
def test_todo_create_rejects_due_at_field() -> None:
|
||||
try:
|
||||
TodoCreate.model_validate(
|
||||
{
|
||||
"title": "Test",
|
||||
"priority": 1,
|
||||
"order": 0,
|
||||
"due_at": "2026-01-01T00:00:00Z",
|
||||
}
|
||||
)
|
||||
except ValidationError:
|
||||
return
|
||||
|
||||
raise AssertionError("TodoCreate should reject due_at")
|
||||
|
||||
|
||||
def test_todo_update_rejects_negative_order() -> None:
|
||||
try:
|
||||
TodoUpdate.model_validate({"order": -1})
|
||||
except ValidationError:
|
||||
return
|
||||
|
||||
raise AssertionError("TodoUpdate should reject negative order")
|
||||
|
||||
|
||||
def test_todo_response_contains_order_without_due_at() -> None:
|
||||
payload = {
|
||||
"id": "9d72aa0f-e2d5-4de3-9b2d-4609f53376c0",
|
||||
"owner_id": "2f5b38fb-cb6f-44ef-8824-e7978f644bc2",
|
||||
"title": "Test",
|
||||
"description": None,
|
||||
"priority": 1,
|
||||
"order": 0,
|
||||
"status": "pending",
|
||||
"completed_at": None,
|
||||
"created_at": "2026-03-20T00:00:00Z",
|
||||
"updated_at": "2026-03-20T00:00:00Z",
|
||||
"schedule_items": [],
|
||||
}
|
||||
|
||||
response = TodoResponse.model_validate(payload)
|
||||
dumped = response.model_dump()
|
||||
|
||||
assert dumped["order"] == 0
|
||||
assert "due_at" not in dumped
|
||||
|
||||
|
||||
def test_todo_reorder_request_requires_non_empty_items() -> None:
|
||||
try:
|
||||
TodoReorderRequest(items=[])
|
||||
except ValidationError:
|
||||
return
|
||||
|
||||
raise AssertionError("TodoReorderRequest should reject empty items")
|
||||
Reference in New Issue
Block a user