Inviting a person to compare charts
The new person page offers 'Adatok megadása' (typed-in data, uses a slot) or 'Meghívom': a 'how compatible are we?' link with an optional name, e-mail and message (no links, 300 chars), shareable by copy, the phone's share menu, WhatsApp or Facebook. With an address we e-mail it too (at most 10 a day per user, opted-out addresses skipped, unsubscribe link included). The invitee lands on /meghivas/<token>, signs in, gives their own birth data if needed and gets the comparison; the inviter is told and lists pending invitations (revocable) on the persons page. No person slot is used. Also: the accepted e-mail links to /osszevetesek/<id>, and the cross grid no longer breaks on another user's chart (no highlights there). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -517,6 +517,67 @@ async fn invitation_links_two_users(pool: PgPool) {
|
||||
assert!(app.outbox_url("anna@example.com", "invite_accepted").await.ends_with(&synastry_id));
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
async fn a_person_can_be_invited_by_mail(pool: PgPool) {
|
||||
let app = TestApp::new(pool.clone()).await;
|
||||
let anna = app.register("anna@example.com", "Anna").await;
|
||||
app.chart(&anna, "Saját", true, "1990-03-15").await;
|
||||
|
||||
// links are not allowed in the message (it may go out in our e-mail)
|
||||
let r =
|
||||
app.post("/v1/invites", Some(&anna), json!({"message": "nézd: www.x.hu", "email": "bela@example.com"})).await;
|
||||
assert_eq!(r.status, StatusCode::BAD_REQUEST);
|
||||
let r = app.post("/v1/invites", Some(&anna), json!({"email": "anna@example.com"})).await;
|
||||
assert_eq!(r.status, StatusCode::BAD_REQUEST, "not herself");
|
||||
|
||||
let r = app
|
||||
.post(
|
||||
"/v1/invites",
|
||||
Some(&anna),
|
||||
json!({"label": "Béla", "email": " Bela@Example.com ", "message": "Nézzük meg, mennyire illünk!"}),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::CREATED, "{}", r.body);
|
||||
let token = r.body["token"].as_str().unwrap().to_string();
|
||||
assert!(r.body["url"].as_str().unwrap().ends_with(&format!("/meghivas/{token}")));
|
||||
assert_eq!((r.body["emailed"].as_bool(), r.body["email"].as_str()), (Some(true), Some("bela@example.com")));
|
||||
let (template, payload): (String, Value) =
|
||||
sqlx::query_as("SELECT template, payload FROM email_outbox WHERE to_email = 'bela@example.com'")
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!((template.as_str(), &payload["inviter_name"]), ("synastry_invite", &json!("Anna")));
|
||||
let invites = app.get("/v1/invites", Some(&anna)).await.body;
|
||||
assert_eq!(
|
||||
(&invites["invites"][0]["label"], &invites["invites"][0]["status"]),
|
||||
(&json!("Béla"), &json!("pending"))
|
||||
);
|
||||
|
||||
// the address can opt out; the next invitation goes by link only
|
||||
let r = app.post(&format!("/v1/public/invitations/unsubscribe?token={token}"), None, json!({})).await;
|
||||
assert_eq!(r.status, StatusCode::OK, "{}", r.body);
|
||||
let r = app.post("/v1/invites", Some(&anna), json!({"email": "bela@example.com"})).await;
|
||||
assert_eq!((r.status, r.body["emailed"].as_bool()), (StatusCode::CREATED, Some(false)));
|
||||
|
||||
// at most ten e-mailed a day
|
||||
for i in 2..10 {
|
||||
let r = app.post("/v1/invites", Some(&anna), json!({"email": format!("p{i}@example.com")})).await;
|
||||
assert_eq!(r.status, StatusCode::CREATED);
|
||||
}
|
||||
let r = app.post("/v1/invites", Some(&anna), json!({"email": "p10@example.com"})).await;
|
||||
assert_eq!(r.body["error"]["code"], "invite_mail_limit");
|
||||
let r = app.post("/v1/invites", Some(&anna), json!({"label": "link only"})).await;
|
||||
assert_eq!(r.status, StatusCode::CREATED, "a link is still fine");
|
||||
|
||||
// accepted: the inviter's mail leads to the comparison page
|
||||
let bela = app.register("bela@example.com", "Béla").await;
|
||||
app.chart(&bela, "Saját", true, "1976-09-03").await;
|
||||
let r = app.post("/v1/invites/accept", Some(&bela), json!({"token": token})).await;
|
||||
assert_eq!(r.status, StatusCode::CREATED, "{}", r.body);
|
||||
let url = app.outbox_url("anna@example.com", "invite_accepted").await;
|
||||
assert!(url.ends_with(&format!("/osszevetesek/{}", r.body["id"].as_str().unwrap())), "{url}");
|
||||
}
|
||||
|
||||
/// Gives `token`'s user analysis units (the admin endpoint is tested in `roles_and_admin_guard`).
|
||||
async fn grant_units(app: &TestApp, token: &str, unit: &str, delta: i32) {
|
||||
let id = app.get("/v1/me", Some(token)).await.body["user"]["id"].as_str().unwrap().to_string();
|
||||
|
||||
Reference in New Issue
Block a user