Inviting shown but off until launch; waitlist confirmation; waitlist invites with a package
USER_INVITES (default false) keeps users from inviting others until the launch: the 'Meghívom' option and a 'Hívd meg, akit szeretsz' card on the persons page are shown, disabled, with 'Hamarosan'; the backend refuses with invites_disabled (admins may always). Joining the waitlist sends one confirmation e-mail (waitlist_joined) with a link that takes the address off the list and opts it out; at most 10 per address in 15 minutes. Admins can pick a package for waitlist invitations, like on the invitation form. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -2056,3 +2056,84 @@ async fn an_invitation_brings_its_package_and_codes_fill_up(pool: PgPool) {
|
||||
(Some(2), Some(1), Some(5))
|
||||
);
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
async fn the_waitlist_confirms_and_can_be_left(pool: PgPool) {
|
||||
let app = TestApp::with_config(pool.clone(), |c| c.signup_mode = crate::config::SignupMode::Invite).await;
|
||||
let admin = app.register("admin@example.com", "Admin").await;
|
||||
let from = |ip: &'static str| [("x-forwarded-for", ip)];
|
||||
|
||||
// one confirmation per address, even when sent again
|
||||
for _ in 0..2 {
|
||||
let r = app
|
||||
.call_with(
|
||||
"POST",
|
||||
"/v1/public/waitlist",
|
||||
None,
|
||||
Some(json!({"email": "Wait@Example.com"})),
|
||||
&from("198.51.100.7"),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::ACCEPTED);
|
||||
}
|
||||
let mails: Vec<(Value,)> = sqlx::query_as(
|
||||
"SELECT payload FROM email_outbox WHERE to_email = 'wait@example.com' AND template = 'waitlist_joined'",
|
||||
)
|
||||
.fetch_all(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(mails.len(), 1);
|
||||
let leave = mails[0].0["unsubscribe_post_url"].as_str().unwrap().to_string();
|
||||
let token = leave.rsplit("token=").next().unwrap().to_string();
|
||||
|
||||
// leaving: off the list, and no invitation can be sent there any more
|
||||
let r = app.call("POST", &format!("/v1/public/invitations/unsubscribe?token={token}"), None, None).await;
|
||||
assert_eq!(r.status, StatusCode::OK, "{}", r.body);
|
||||
assert!(app.get("/v1/admin/invitations", Some(&admin)).await.body["waitlist"].as_array().unwrap().is_empty());
|
||||
let r = app.post("/v1/admin/invitations", Some(&admin), json!({"emails": ["wait@example.com"]})).await;
|
||||
assert_eq!(r.body["results"][0]["status"], "opted_out");
|
||||
// and signing up again sends nothing
|
||||
app.call_with(
|
||||
"POST",
|
||||
"/v1/public/waitlist",
|
||||
None,
|
||||
Some(json!({"email": "wait@example.com"})),
|
||||
&from("198.51.100.8"),
|
||||
)
|
||||
.await;
|
||||
let count: i64 = sqlx::query_scalar("SELECT count(*) FROM email_outbox WHERE to_email = 'wait@example.com'")
|
||||
.fetch_one(&pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!(count, 1);
|
||||
|
||||
// one address cannot flood the form
|
||||
let mut last = StatusCode::OK;
|
||||
for i in 0..12 {
|
||||
let r = app
|
||||
.call_with(
|
||||
"POST",
|
||||
"/v1/public/waitlist",
|
||||
None,
|
||||
Some(json!({"email": format!("w{i}@example.com")})),
|
||||
&from("203.0.113.9"),
|
||||
)
|
||||
.await;
|
||||
last = r.status;
|
||||
}
|
||||
assert_eq!(last, StatusCode::TOO_MANY_REQUESTS);
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
async fn user_invitations_wait_for_the_launch(pool: PgPool) {
|
||||
let app = TestApp::with_config(pool, |c| c.user_invites = false).await;
|
||||
assert_eq!(app.get("/v1/config", None).await.body["user_invites"], false);
|
||||
let anna = app.register("anna@example.com", "Anna").await;
|
||||
app.chart(&anna, "Saját", true, "1990-03-15").await;
|
||||
let r = app.post("/v1/invites", Some(&anna), json!({"label": "Béla"})).await;
|
||||
assert_eq!((r.status, r.body["error"]["code"].as_str()), (StatusCode::CONFLICT, Some("invites_disabled")));
|
||||
// admins may, to try it
|
||||
let admin = app.register("admin@example.com", "Admin").await;
|
||||
app.chart(&admin, "Saját", true, "1980-01-01").await;
|
||||
assert_eq!(app.post("/v1/invites", Some(&admin), json!({})).await.status, StatusCode::CREATED);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user