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",
|
||||
|
||||
Reference in New Issue
Block a user