Header shows the user's package and what is left of it
CI / test (push) Successful in 51s
CI / build (push) Successful in 4m0s
CI / deploy (push) Skipped

- /v1/me: `package` = the running unlimited package, or the latest main
  package bought or given (top-ups do not count; an ended unlimited not)
- header badge: "Család · 11 elemzés", "Korlátlan · 2027. november 17-ig",
  "Páros · elfogyott"; links to the packages page, details in the tooltip

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 19:24:52 +00:00
co-authored by Claude Opus 5.5
parent 21640ffd9e
commit 742b88183b
6 changed files with 77 additions and 1 deletions
+6
View File
@@ -1000,6 +1000,7 @@ async fn packages_grant_units_and_unlimited(pool: PgPool) {
let admin = app.register("admin@example.com", "Admin").await;
let anna = app.register("anna@example.com", "Anna").await;
let anna_id = app.get("/v1/me", Some(&anna)).await.body["user"]["id"].as_str().unwrap().to_string();
assert_eq!(app.get("/v1/me", Some(&anna)).await.body["package"], Value::Null);
// the catalog is public
let r = app.get("/v1/packages", None).await;
@@ -1035,6 +1036,9 @@ async fn packages_grant_units_and_unlimited(pool: PgPool) {
let (price,): (i32,) =
sqlx::query_as("SELECT price_huf FROM package_orders WHERE package = 'couple'").fetch_one(&pool).await.unwrap();
assert_eq!(price, 6990);
// the header shows the latest main package; a top-up does not change it
app.post("/v1/payments/mock", Some(&anna), json!({"package": "addon_persons"})).await;
assert_eq!(app.get("/v1/me", Some(&anna)).await.body["package"]["name"], "Páros");
// unlimited: a year, and a second one extends it
let bela = app.register("bela@example.com", "Béla").await;
@@ -1049,6 +1053,7 @@ async fn packages_grant_units_and_unlimited(pool: PgPool) {
let days = (until - time::OffsetDateTime::now_utc()).whole_days();
assert!((725..=733).contains(&days), "{days}");
assert_eq!(app.get("/v1/me", Some(&bela)).await.body["persons"]["unlimited"], true);
assert_eq!(app.get("/v1/me", Some(&bela)).await.body["package"]["id"], "unlimited");
// analyses use no unit, up to the daily cap (3 in tests)
for (i, date) in ["1980-01-01", "1981-01-01", "1982-01-01"].into_iter().enumerate() {
@@ -1068,6 +1073,7 @@ async fn packages_grant_units_and_unlimited(pool: PgPool) {
let r = app.call("POST", &uri, Some(&bela), None).await;
assert_eq!(r.status, StatusCode::PAYMENT_REQUIRED);
assert_eq!(app.get("/v1/me", Some(&bela)).await.body["unlimited_until"], Value::Null);
assert_eq!(app.get("/v1/me", Some(&bela)).await.body["package"], Value::Null); // ended
}
#[sqlx::test(migrator = "db::MIGRATOR")]