Renaming a person keeps the chart and its analyses
CI / test (push) Successful in 47s
CI / build (push) Successful in 3m55s
CI / deploy (push) Skipped

The person edit form sent the birth data with every save, so a new name alone
recalculated the chart, deleted its analyses and comparisons and queued a new
summary. Now the backend ignores birth data equal to the stored one (and keeps
everything when a recalculation gives the same chart), and the form sends it
only when it changed. The name can be changed after the correction window too
("Átnevezés" on the person card).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
feco
2026-11-17 16:59:18 +00:00
co-authored by Claude Opus 5.5
parent e004ea696b
commit b53cadcd8c
7 changed files with 140 additions and 20 deletions
+45 -1
View File
@@ -802,7 +802,8 @@ async fn persons_use_package_slots(pool: PgPool) {
.execute(&app.pool)
.await
.unwrap();
let r = app.call("PATCH", &format!("/v1/charts/{id}"), Some(&anna), Some(corrected.clone())).await;
let again = json!({"birth": {"date": "1986-01-03", "time": "10:00", "country": "HU", "place": "Szeged"}});
let r = app.call("PATCH", &format!("/v1/charts/{id}"), Some(&anna), Some(again)).await;
assert_eq!((r.status, r.body["error"]["code"].as_str()), (StatusCode::CONFLICT, Some("person_locked")));
let r =
app.call("PATCH", &format!("/v1/charts/{}", own["id"].as_str().unwrap()), Some(&anna), Some(corrected)).await;
@@ -1068,3 +1069,46 @@ async fn packages_grant_units_and_unlimited(pool: PgPool) {
assert_eq!(r.status, StatusCode::PAYMENT_REQUIRED);
assert_eq!(app.get("/v1/me", Some(&bela)).await.body["unlimited_until"], Value::Null);
}
#[sqlx::test(migrator = "db::MIGRATOR")]
async fn renaming_a_person_keeps_chart_and_analyses(pool: PgPool) {
let app = TestApp::new(pool.clone()).await;
let anna = app.register("anna@example.com", "Anna").await;
let own = app.chart(&anna, "Saját", true, "1990-03-15").await;
let bela = app.chart(&anna, "Béla", false, "1985-08-02").await;
let id = bela["id"].as_str().unwrap();
let syn = app.post("/v1/synastries", Some(&anna), json!({"chart1_id": own["id"], "chart2_id": id})).await;
assert_eq!(syn.status, StatusCode::CREATED);
let summaries = || async {
let (n,): (i64,) = sqlx::query_as("SELECT count(*) FROM analyses WHERE chart_id = $1::uuid")
.bind(id)
.fetch_one(&pool)
.await
.unwrap();
n
};
assert_eq!(summaries().await, 1);
// the edit form sends the unchanged birth data with the new name
let same = json!({"label": "Béla bácsi",
"birth": {"date": "1985-08-02", "time": "14:30", "country": "HU", "place": "Szeged"}});
let r = app.call("PATCH", &format!("/v1/charts/{id}"), Some(&anna), Some(same.clone())).await;
assert_eq!(
(r.status, &r.body["label"], &r.body["chart_hash"]),
(StatusCode::OK, &json!("Béla bácsi"), &bela["chart_hash"])
);
assert_eq!(summaries().await, 1);
let r = app.get(&format!("/v1/synastries/{}", syn.body["id"].as_str().unwrap()), Some(&anna)).await;
assert_eq!(r.status, StatusCode::OK);
// after the correction window the name can still change
sqlx::query("UPDATE charts SET created_at = now() - interval '2 hours' WHERE id = $1::uuid")
.bind(id)
.execute(&pool)
.await
.unwrap();
let r = app.call("PATCH", &format!("/v1/charts/{id}"), Some(&anna), Some(json!({"label": "Béla"}))).await;
assert_eq!((r.status, &r.body["label"]), (StatusCode::OK, &json!("Béla")));
let r = app.call("PATCH", &format!("/v1/charts/{id}"), Some(&anna), Some(same)).await;
assert_eq!(r.status, StatusCode::OK, "{}", r.body);
}