Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/api/schemas/templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class TemplateCreate(BaseModel):

class TemplateUpdate(BaseModel):
name: str | None = None
description: str | None = None
fields: dict | None = None


Expand Down
2 changes: 2 additions & 0 deletions app/services/template.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,8 @@ def update_template(
# Only the fields sent are changed; pdf_path stays as it was.
if changes.name is not None:
template.name = changes.name
if changes.description is not None:
template.description = changes.description
if changes.fields is not None:
template.fields = changes.fields
updated = update_template(session, template)
Expand Down
72 changes: 72 additions & 0 deletions tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,47 @@ def test_update_template(self, client, mock_controller):
assert resp.json()["field_count"] == 2
assert client.get(f"{API_PREFIX}/templates").json()[0]["name"] == "T2"

def test_update_template_description(self, client, db, mock_controller):
"""PUT /templates/{id} persists a new description."""
tpl = Template(
name="ICS 205",
description="Original radio plan",
pdf_path="a.pdf",
fields={"f": "string"},
)
db.add(tpl)
db.commit()
db.refresh(tpl)

resp = client.put(
f"{API_PREFIX}/templates/{tpl.id}",
json={"description": "Updated ICS 205 radio plan"},
)
assert resp.status_code == 200
assert resp.json()["description"] == "Updated ICS 205 radio plan"
assert resp.json()["name"] == "ICS 205"
assert resp.json()["fields"] == {"f": "string"}
assert client.get(f"{API_PREFIX}/templates").json()[0]["description"] == (
"Updated ICS 205 radio plan"
)

def test_update_keeps_description_when_omitted(self, client, db, mock_controller):
"""A name-only PUT must not clear an existing description."""
tpl = Template(
name="ICS 205",
description="Keep this comms plan",
pdf_path="a.pdf",
fields={"f": "string"},
)
db.add(tpl)
db.commit()
db.refresh(tpl)

resp = client.put(f"{API_PREFIX}/templates/{tpl.id}", json={"name": "ICS 205A"})
assert resp.status_code == 200
assert resp.json()["name"] == "ICS 205A"
assert resp.json()["description"] == "Keep this comms plan"

def test_update_missing_template(self, client):
resp = client.put(f"{API_PREFIX}/templates/9999", json={"name": "T2"})
assert resp.status_code == 404
Expand Down Expand Up @@ -301,6 +342,37 @@ def test_fill_form_with_direct_input_text(self, client, mock_controller, db, tmp
assert fetched.input_text == "Direct incident text narrative from user."
assert fetched.input_id is not None

def test_fill_form_uses_description_from_update(
self, client, mock_controller, db, tmp_path, monkeypatch
):
"""A description saved via PUT /templates/{id} reaches the filler."""
monkeypatch.setattr("app.core.paths.PROJECT_ROOT", tmp_path)
pdf_file = tmp_path / "ics_205.pdf"
pdf_file.write_bytes(b"%PDF-1.4 fake")
tpl = Template(
name="ICS 205",
description="",
pdf_path="ics_205.pdf",
fields={"Incident Name": "string"},
)
db.add(tpl)
db.commit()
db.refresh(tpl)

updated = client.put(
f"{API_PREFIX}/templates/{tpl.id}",
json={"description": "Incident radio communications plan"},
)
assert updated.status_code == 200
assert updated.json()["description"] == "Incident radio communications plan"

resp = client.post(
f"{API_PREFIX}/forms/fill",
json={
"template_id": tpl.id,
"input_text": "Command uses channel 3 for the Oak Ridge fire.",
},
)
def test_fill_form_uses_description_from_create(self, client, mock_controller, tmp_path, monkeypatch):
"""The description given to POST /templates/create reaches the filler."""
monkeypatch.setattr("app.core.paths.PROJECT_ROOT", tmp_path)
Expand Down
Loading