This commit is contained in:
@@ -92,6 +92,41 @@ def test_task_can_be_updated_completed_and_soft_deleted(client):
|
||||
assert client.get("/api/v1/tasks").json()["items"] == []
|
||||
|
||||
|
||||
def test_reorder_tasks_persists_top_level_and_subtask_order(client):
|
||||
client = initialized_client(client)
|
||||
inbox = client.get("/api/v1/lists").json()[0]
|
||||
first = client.post("/api/v1/tasks", json={"title": "第一个", "list_id": inbox["id"]}).json()
|
||||
second = client.post("/api/v1/tasks", json={"title": "第二个", "list_id": inbox["id"]}).json()
|
||||
child_a = client.post(
|
||||
"/api/v1/tasks", json={"title": "子任务 A", "list_id": inbox["id"], "parent_id": first["id"]}
|
||||
).json()
|
||||
child_b = client.post(
|
||||
"/api/v1/tasks", json={"title": "子任务 B", "list_id": inbox["id"], "parent_id": first["id"]}
|
||||
).json()
|
||||
|
||||
top_level = client.put("/api/v1/tasks/reorder", json={"task_ids": [second["id"], first["id"]]})
|
||||
assert top_level.status_code == 204
|
||||
children = client.put("/api/v1/tasks/reorder", json={"task_ids": [child_b["id"], child_a["id"]]})
|
||||
assert children.status_code == 204
|
||||
|
||||
client.post("/api/v1/tasks", json={"title": "第三个", "list_id": inbox["id"]})
|
||||
listed = client.get("/api/v1/tasks", params={"list_id": inbox["id"], "page": 1}).json()["items"]
|
||||
assert [task["title"] for task in listed] == ["第二个", "第一个", "第三个"]
|
||||
assert [task["title"] for task in listed[1]["subtasks"]] == ["子任务 B", "子任务 A"]
|
||||
|
||||
|
||||
def test_reorder_tasks_rejects_mixed_parent_scopes(client):
|
||||
client = initialized_client(client)
|
||||
inbox = client.get("/api/v1/lists").json()[0]
|
||||
parent = client.post("/api/v1/tasks", json={"title": "父任务", "list_id": inbox["id"]}).json()
|
||||
child = client.post(
|
||||
"/api/v1/tasks", json={"title": "子任务", "list_id": inbox["id"], "parent_id": parent["id"]}
|
||||
).json()
|
||||
|
||||
response = client.put("/api/v1/tasks/reorder", json={"task_ids": [parent["id"], child["id"]]})
|
||||
assert response.status_code == 400
|
||||
|
||||
|
||||
def test_task_update_rejects_null_title(client):
|
||||
client.post(
|
||||
"/api/v1/setup/initialize",
|
||||
|
||||
@@ -75,6 +75,29 @@ def test_recurrence_rejects_occurrence_after_cutoff(client):
|
||||
).status_code == 422
|
||||
|
||||
|
||||
def test_habit_reorder_persists_in_lists_and_grid(client):
|
||||
boot(client)
|
||||
first = client.post("/api/v1/habits", json={"name": "第一个", "kind": "boolean", "schedule_type": "daily"}).json()
|
||||
second = client.post("/api/v1/habits", json={"name": "第二个", "kind": "boolean", "schedule_type": "daily"}).json()
|
||||
|
||||
response = client.put("/api/v1/habits/reorder", json={"habit_ids": [second["id"], first["id"]]})
|
||||
assert response.status_code == 204
|
||||
client.post("/api/v1/habits", json={"name": "第三个", "kind": "boolean", "schedule_type": "daily"})
|
||||
assert [habit["name"] for habit in client.get("/api/v1/habits").json()] == ["第二个", "第一个", "第三个"]
|
||||
grid = client.get("/api/v1/habits/grid", params={"week": "2026-09-07"}).json()
|
||||
assert [habit["name"] for habit in grid["habits"]] == ["第二个", "第一个", "第三个"]
|
||||
|
||||
|
||||
def test_habit_reorder_rejects_foreign_or_missing_ids(client):
|
||||
boot(client)
|
||||
habit = client.post("/api/v1/habits", json={"name": "自己的习惯", "kind": "boolean", "schedule_type": "daily"}).json()
|
||||
response = client.put(
|
||||
"/api/v1/habits/reorder",
|
||||
json={"habit_ids": [habit["id"], "00000000-0000-0000-0000-000000000001"]},
|
||||
)
|
||||
assert response.status_code == 404
|
||||
|
||||
|
||||
def test_habit_logs_support_date_range_filter(client):
|
||||
boot(client)
|
||||
habit = client.post("/api/v1/habits", json={"name": "跑步", "kind": "boolean", "schedule_type": "daily"}).json()
|
||||
|
||||
Reference in New Issue
Block a user