Detailed analysis button, loading wheel, birth data change limits
Backend: - own birth data: three corrections within an hour of the first save, then one change per 24 hours (birth_data_changes); 429 birth_data_change_limit with the user-facing message; /v1/me birth_change shows the notice; admins are not limited - admins get detailed analyses free (no unit spent) - POST /v1/payments/mock (MOCK_PAYMENTS): stand-in payment that adds a unit, until Stripe is connected; on in the compose files for now Frontend: - detailed analysis offer: admin starts it free, users with units confirm, others go through the (stand-in) payment step - turning wheel with elapsed time while the summary or the analysis is being written - no "adatok javítása" on the chart page (only in the profile), limit notice there; wheel hover highlighting removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -400,6 +400,8 @@ async fn charts_are_private(pool: PgPool) {
|
||||
.await;
|
||||
assert_eq!((r.status, r.body["error"]["code"].as_str()), (StatusCode::NOT_FOUND, Some("place_not_found")));
|
||||
|
||||
// (the fourth change of the own chart; the limit is tested in birth_data_changes_are_limited)
|
||||
sqlx::query("DELETE FROM birth_data_changes").execute(&app.pool).await.unwrap();
|
||||
let r = app
|
||||
.call("PATCH", &format!("/v1/charts/{id}"), Some(&anna), Some(json!({"label": "Én", "is_primary": true})))
|
||||
.await;
|
||||
@@ -652,3 +654,101 @@ async fn synastry_analyses_use_synastry_units(pool: PgPool) {
|
||||
assert_eq!((r.status, r.body["kind"].as_str()), (StatusCode::ACCEPTED, Some("synastry")));
|
||||
assert_eq!(app.get("/v1/credits", Some(&anna)).await.body["balance"], json!({"natal": 1, "synastry": 0}));
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
async fn birth_data_changes_are_limited(pool: PgPool) {
|
||||
let app = TestApp::new(pool.clone()).await;
|
||||
let anna = app.register("anna@example.com", "Anna").await;
|
||||
assert_eq!(app.get("/v1/me", Some(&anna)).await.body["birth_change"]["limited"], json!(false));
|
||||
|
||||
// the first save and three corrections within the hour are free
|
||||
let first = app.chart(&anna, "Saját", true, "1990-03-15").await;
|
||||
for date in ["1990-03-16", "1990-03-17", "1990-03-18"] {
|
||||
app.chart(&anna, "Saját", true, date).await;
|
||||
}
|
||||
// saving the current data again is not a change
|
||||
let r = app
|
||||
.post(
|
||||
"/v1/charts",
|
||||
Some(&anna),
|
||||
json!({"label": "Saját", "is_primary": true,
|
||||
"birth": {"date": "1990-03-18", "time": "14:30", "country": "HU", "place": "Szeged"}}),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::OK, "{}", r.body);
|
||||
|
||||
// the fourth correction: once a day from now on
|
||||
let r = app
|
||||
.post(
|
||||
"/v1/charts",
|
||||
Some(&anna),
|
||||
json!({"label": "Saját", "is_primary": true,
|
||||
"birth": {"date": "1990-03-19", "time": "14:30", "country": "HU", "place": "Szeged"}}),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::TOO_MANY_REQUESTS, "{}", r.body);
|
||||
assert_eq!(r.body["error"]["code"], json!("birth_data_change_limit"));
|
||||
let message = r.body["error"]["message"].as_str().unwrap();
|
||||
assert!(message.starts_with("A rendszer csak napi egy módosítást engedélyez."), "{message}");
|
||||
assert!(message.ends_with("óra múlva módosíthatod."), "{message}");
|
||||
// switching back to an older chart is a change too
|
||||
let r = app
|
||||
.call(
|
||||
"PATCH",
|
||||
&format!("/v1/charts/{}", first["id"].as_str().unwrap()),
|
||||
Some(&anna),
|
||||
Some(json!({"is_primary": true})),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::TOO_MANY_REQUESTS);
|
||||
// other people's charts are not limited
|
||||
app.chart(&anna, "Béla", false, "1985-08-02").await;
|
||||
|
||||
let me = app.get("/v1/me", Some(&anna)).await.body;
|
||||
assert_eq!(me["birth_change"]["limited"], json!(true));
|
||||
assert!(me["birth_change"]["notice"].as_str().unwrap().contains("napi egy"));
|
||||
|
||||
// a day later it works again
|
||||
sqlx::query("UPDATE birth_data_changes SET created_at = created_at - interval '25 hours'")
|
||||
.execute(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
app.chart(&anna, "Saját", true, "1990-03-19").await;
|
||||
|
||||
// admins are not limited
|
||||
let admin = app.register("admin@example.com", "Admin").await;
|
||||
for day in 10..16 {
|
||||
app.chart(&admin, "Saját", true, &format!("1980-01-{day}")).await;
|
||||
}
|
||||
assert_eq!(app.get("/v1/me", Some(&admin)).await.body["birth_change"]["notice"], Value::Null);
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
async fn admins_get_free_analyses_and_mock_payments_add_units(pool: PgPool) {
|
||||
let app = TestApp::new(pool).await;
|
||||
let admin = app.register("admin@example.com", "Admin").await;
|
||||
let chart = app.chart(&admin, "Saját", true, "1990-03-15").await;
|
||||
let r =
|
||||
app.call("POST", &format!("/v1/charts/{}/analyses", chart["id"].as_str().unwrap()), Some(&admin), None).await;
|
||||
assert_eq!((r.status, &r.body["credits_charged"]), (StatusCode::ACCEPTED, &json!(0)), "{}", r.body);
|
||||
|
||||
// a user "pays", which adds a unit, then requests the analysis
|
||||
let anna = app.register("anna@example.com", "Anna").await;
|
||||
let chart = app.chart(&anna, "Saját", true, "1991-05-01").await;
|
||||
let r = app.post("/v1/payments/mock", Some(&anna), json!({"unit": "natal"})).await;
|
||||
assert_eq!(
|
||||
(r.status, &r.body["analyses_left"]),
|
||||
(StatusCode::OK, &json!({"natal": 1, "synastry": 0})),
|
||||
"{}",
|
||||
r.body
|
||||
);
|
||||
let r =
|
||||
app.call("POST", &format!("/v1/charts/{}/analyses", chart["id"].as_str().unwrap()), Some(&anna), None).await;
|
||||
assert_eq!((r.status, &r.body["credits_charged"]), (StatusCode::ACCEPTED, &json!(1)), "{}", r.body);
|
||||
assert_eq!(app.get("/v1/credits", Some(&anna)).await.body["balance"], json!({"natal": 0, "synastry": 0}));
|
||||
|
||||
// without MOCK_PAYMENTS there is no such payment
|
||||
let app = TestApp::with_config(app.pool.clone(), |c| c.mock_payments = false).await;
|
||||
let r = app.post("/v1/payments/mock", Some(&anna), json!({"unit": "natal"})).await;
|
||||
assert_eq!(r.status, StatusCode::NOT_FOUND);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user