diff --git a/backend/app/main.py b/backend/app/main.py index aa051a98..4133255b 100644 --- a/backend/app/main.py +++ b/backend/app/main.py @@ -82,7 +82,7 @@ async def update_plan( ) return AssignmentsUpdate( acknowledged=result.acknowledged, - inserted_id=result.upserted_id, + upserted_id=result.upserted_id, matched_count=result.matched_count, modified_count=result.modified_count, ) diff --git a/backend/app/models.py b/backend/app/models.py index a03e5b53..366932e2 100644 --- a/backend/app/models.py +++ b/backend/app/models.py @@ -70,7 +70,7 @@ class AssignmentsUpdate(BaseModel): """ acknowledged: bool = PydanticField(description="Acknowledged") - inserted_id: Optional[str] = PydanticField(description="Inserted ID") + upserted_id: Optional[str] = PydanticField(description="Inserted ID") matched_count: int = PydanticField(description="Matched count") modified_count: int = PydanticField(description="Modified count") diff --git a/backend/app/test_main.py b/backend/app/test_main.py index fd5beefc..eb3c8edc 100644 --- a/backend/app/test_main.py +++ b/backend/app/test_main.py @@ -58,7 +58,6 @@ def plan_id_fixture() -> InsertOneResult: def test_get_plan(client: TestClient, plan: InsertOneResult): - print(plan.inserted_id) response = client.get(f"/plan/{plan.inserted_id}") assert response.status_code == 200 @@ -68,18 +67,17 @@ def test_create_plan(client: TestClient): assert response.status_code == 201 -def test_update_plan(client: TestClient, plan: InsertOneResult): +def test_update_add_to_plan(client: TestClient, plan: InsertOneResult): response = client.put( f"/plan/{plan.inserted_id}", json={"assignments": {"06067001102": 1}} ) assert response.status_code == 200 data = response.json() assert data["modified_count"] == 1 + assert data["upserted_id"] is None -def test_update_plan_with_modification_to_existing_assignment( - client: TestClient, plan: InsertOneResult -): +def test_update_update_and_add(client: TestClient, plan: InsertOneResult): response = client.put( f"/plan/{plan.inserted_id}", json={"assignments": {"06067001101": 2, "06067001102": 1}}, @@ -87,6 +85,9 @@ def test_update_plan_with_modification_to_existing_assignment( assert response.status_code == 200 data = response.json() assert data["modified_count"] == 1 + assert data["matched_count"] == 1 + assert data["acknowledged"] is True + assert data["upserted_id"] is None def test_get_missing_plan(client: TestClient):