Admin gifts: an e-mail to the user; the user dialog no longer loses a pick
- A package or units an admin gives a user are announced in a "gift" e-mail (taking units away is not). Queued in the same transaction. - The user dialog asks before closing with a chosen package or a typed amount not sent yet; the send buttons turn gold when ready, "Kész" is now a plain "Bezárás". - The modal closes on the backdrop only when the press started there too, so picking from a select whose list hangs over the backdrop, or dragging a selection out, no longer closes it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -616,9 +616,21 @@ async fn roles_and_admin_guard(pool: PgPool) {
|
||||
);
|
||||
let r = app.post(&format!("/v1/admin/users/{anna}/credits"), Some(&admin), grant("chat", 5)).await;
|
||||
assert_eq!(r.status, StatusCode::BAD_REQUEST);
|
||||
// the gift is announced in an e-mail; taking units away is not
|
||||
app.post(&format!("/v1/admin/users/{anna}/credits"), Some(&admin), grant("natal", -1)).await;
|
||||
let gifts: Vec<(Value,)> =
|
||||
sqlx::query_as("SELECT payload FROM email_outbox WHERE to_email = 'anna@example.com' AND template = 'gift'")
|
||||
.fetch_all(&app.pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(gifts.len(), 1);
|
||||
assert_eq!((&gifts[0].0["gift"], &gifts[0].0["display_name"]), (&json!("5 részletes képletelemzést"), &json!("Anna")));
|
||||
app.post(&format!("/v1/admin/users/{anna}/credits"), Some(&admin), grant("natal", 1)).await;
|
||||
let credits = app.get("/v1/credits", Some(&user)).await.body;
|
||||
assert_eq!(credits["balance"], json!({"natal": 5, "synastry": 0, "forecast": 0, "question": 0, "tarot": 0}));
|
||||
assert_eq!((credits["ledger"][0]["unit"].as_str(), &credits["ledger"][0]["delta"]), (Some("natal"), &json!(5)));
|
||||
// newest first: +1 after −1 after +5
|
||||
let deltas: Vec<&Value> = credits["ledger"].as_array().unwrap().iter().map(|l| &l["delta"]).collect();
|
||||
assert_eq!(deltas, [&json!(1), &json!(-1), &json!(5)]);
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
@@ -1616,6 +1628,14 @@ async fn packages_grant_units(pool: PgPool) {
|
||||
assert_eq!(grant_package(&app, &anna, &anna_id, "family").await.status, StatusCode::FORBIDDEN);
|
||||
assert_eq!(grant_package(&app, &admin, &anna_id, "gold").await.status, StatusCode::NOT_FOUND);
|
||||
let r = grant_package(&app, &admin, &anna_id, "family").await;
|
||||
let (gift,): (Value,) =
|
||||
sqlx::query_as("SELECT payload FROM email_outbox WHERE to_email = 'anna@example.com' AND template = 'gift'")
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(gift["gift"], "a(z) „Család” csomagot");
|
||||
assert!(gift["contents"].as_str().unwrap().contains("részletes képletelemzés"), "{gift}");
|
||||
assert!(gift["url"].as_str().unwrap().ends_with("/csomagok"));
|
||||
assert_eq!(
|
||||
(r.status, &r.body["analyses_left"]),
|
||||
(StatusCode::CREATED, &json!({"natal": 6, "synastry": 5, "forecast": 6, "question": 3, "tarot": 10})),
|
||||
|
||||
Reference in New Issue
Block a user