"""An entry title can be renamed without touching the document body.""" from __future__ import annotations from tests.support import Actor, document, register def test_element_title_can_be_renamed(client, db): ada = Actor(client, "ada-titel@example.test", "Ada Titel") register(db, ada.email, ada.name) ada.login() matter = ada.request("POST", "/api/v1/matters", json={"title": "Vorgang"}, status=201) ada.request( "POST", "/api/v1/notes", json={ "title": "Alter Titel", "document": document("Text"), "context": {"kind": "matter", "id": matter["id"]}, }, status=201, ) detail = ada.request("GET", f"/api/v1/matters/{matter['id']}") element = detail["bindings"][0]["element"] renamed = ada.request( "PATCH", f"/api/v1/elements/{element['id']}/title", json={ "expected_version": element["version"], "title": "Neuer Titel", "context": {"kind": "matter", "id": matter["id"]}, }, ) assert renamed["title"] == "Neuer Titel" assert renamed["version"] == element["version"] + 1 shown = ada.request("GET", f"/api/v1/matters/{matter['id']}") assert shown["bindings"][0]["element"]["title"] == "Neuer Titel" ada.request( "PATCH", f"/api/v1/elements/{element['id']}/title", json={ "expected_version": renamed["version"], "title": " ", "context": {"kind": "matter", "id": matter["id"]}, }, status=422, )