Weekly horoscope: its own page, a Monday e-mail, and one page for every e-mail setting
CI / test (push) Successful in 3m17s
CI / build (push) Skipped
CI / deploy (push) Skipped

- The week's sky on the member's own chart (horoscope-api POST /v1/week,
  astro_engine::week): the planets' aspects to the natal points with the day
  each is exact, positions, the Moon's signs, lunar phases, stations and sign
  changes; stored once per chart and week (weekly_skies, migration 0047).
- Its text is a 'weekly' analysis written by the summary's (cheap) model when
  the member opens /heti-horoszkop: one month per page, the newest week
  first, the waiting animation while it is written. In the menu, and linked
  from the chart page.
- Monday 7:00 e-mail (worker task 'weekly'): only that it is there; on by
  default for everyone with a chart, members of today too. Its footer opens
  /ertesitesek?token=…, where the weekly e-mail and every forum e-mail can
  be set without logging in; the mail client's one-click unsubscribe turns
  off the weekly one. Also a switch on the page and on the Profile page.
- Privacy notice (HU/EN) describes it; ratings, admin labels and the model
  page know the new kind.

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-27 09:40:09 +00:00
co-authored by Claude Opus 5.5
parent 50c29e4595
commit 0358e137f1
46 changed files with 2368 additions and 70 deletions
+148 -1
View File
@@ -90,6 +90,23 @@ async fn fake_forecast(Json(body): Json<Value>) -> (StatusCode, Json<Value>) {
)
}
/// Calls of the fake week endpoint (only `weekly_horoscope_of_the_own_chart` uses it).
static WEEK_CALLS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
async fn fake_week(Json(body): Json<Value>) -> (StatusCode, Json<Value>) {
WEEK_CALLS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
let start = body["start"].as_str().unwrap_or("2026-11-30").to_string();
(
StatusCode::OK,
Json(json!({
"timezone": "Europe/Budapest",
"week": {"start": start, "end": "?", "contacts": [], "positions": [], "moon_sign": "leo",
"moon_ingresses": [], "ingresses": [], "lunations": [], "stations": []},
"meta": {}
})),
)
}
/// Calls of the fake sky endpoints (only `the_sky_is_shared_and_kept` uses them).
static SKY_CALLS: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
@@ -254,6 +271,7 @@ async fn fake_services_with(s3: FakeS3) -> String {
)
.route("/v1/synastry", post(fake_synastry))
.route("/v1/forecast", post(fake_forecast))
.route("/v1/week", post(fake_week))
.route(
"/v1/sky",
get(|| async {
@@ -1107,7 +1125,7 @@ async fn export_and_delete_account(pool: PgPool) {
/// config and catalog, shared links, invitation pages, the waitlist and
/// unsubscribing. Every other route (charts, calculations, analyses) needs a
/// logged-in user, so other apps cannot use them.
const PUBLIC_ROUTES: [&str; 24] = [
const PUBLIC_ROUTES: [&str; 26] = [
"/healthz",
// Stripe calls it; the signature proves it.
"/v1/payments/stripe/webhook",
@@ -1123,6 +1141,9 @@ const PUBLIC_ROUTES: [&str; 24] = [
"/v1/public/shares/{slug}/visit",
"/v1/public/invites/{token}",
"/v1/public/invitations/unsubscribe",
// The e-mail settings behind an e-mail's footer link: the token stands for the login.
"/v1/public/weekly/unsubscribe",
"/v1/public/notifications",
"/v1/public/invitations/{token}",
"/v1/public/waitlist",
// The public birth chart (limited per visitor address).
@@ -1957,6 +1978,132 @@ async fn invitation_only_signup(pool: PgPool) {
assert_eq!(app.outbox_url("admin@example.com", "invitation").await, "https://sorsfonalak.test/meghivo/minta");
}
#[sqlx::test(migrator = "db::MIGRATOR")]
async fn weekly_horoscope_of_the_own_chart(pool: PgPool) {
let app = TestApp::new(pool.clone()).await;
let anna = app.register("anna@example.com", "Anna").await;
let bob = app.register("bob@example.com", "Bob").await;
// No own chart yet: nothing to write it from.
assert_eq!(app.call("POST", "/v1/weekly", Some(&bob), None).await.status, StatusCode::NOT_FOUND);
let chart = app.chart(&anna, "Saját", true, "1990-03-15").await;
let calls = WEEK_CALLS.load(std::sync::atomic::Ordering::Relaxed);
let r = app.call("POST", "/v1/weekly", Some(&anna), None).await;
assert_eq!(r.status, StatusCode::OK, "{}", r.body);
let parts: Vec<i32> = r.body["week_start"].as_str().unwrap().split('-').map(|p| p.parse().unwrap()).collect();
let month = time::Month::try_from(parts[1] as u8).unwrap();
let start = time::Date::from_calendar_date(parts[0], month, parts[2] as u8).unwrap();
assert_eq!(start.weekday(), time::Weekday::Monday);
assert_eq!(r.body["week_end"], start.saturating_add(time::Duration::days(6)).to_string());
let a = &r.body["analysis"];
assert_eq!((a["kind"].as_str(), a["status"].as_str()), (Some("weekly"), Some("pending")));
assert_eq!((a["chart_id"].as_str(), a["credits_charged"].as_i64()), (chart["id"].as_str(), Some(0)));
assert_eq!(a["week_start"], r.body["week_start"]);
// On by default.
assert_eq!(r.body["email"], true);
// Asked again: the same text, the sky calculated once.
let again = app.call("POST", "/v1/weekly", Some(&anna), None).await.body;
assert_eq!(again["analysis"]["id"], a["id"]);
assert_eq!(WEEK_CALLS.load(std::sync::atomic::Ordering::Relaxed), calls + 1);
// Written by the summary's model; not among the chart's analyses on its page, but listed.
let (weekly_model, summary_model): (String, String) = sqlx::query_as(
"SELECT w.model, s.model FROM analyses w JOIN analyses s ON s.chart_id = w.chart_id AND s.kind = 'summary' \
WHERE w.kind = 'weekly'",
)
.fetch_one(&pool)
.await
.unwrap();
assert_eq!(weekly_model, summary_model);
// The page: one month at a time, the newest week first; older months page back.
let month = app.get("/v1/weekly/history", Some(&anna)).await.body;
assert_eq!(month["month"], month["current_month"]);
assert_eq!(month["this_week"], r.body["week_start"]);
assert_eq!(month["weeks"].as_array().unwrap().len(), 1);
assert_eq!(month["weeks"][0]["analysis"]["id"], a["id"]);
assert_eq!((month["older"].is_null(), month["newer"].is_null()), (true, true));
let old_week = start.saturating_sub(time::Duration::days(35));
sqlx::query(
"INSERT INTO analyses (id, kind, chart_id, requested_by, language, model, prompt_version, cache_key, status, \
content, credits_charged, week_start) \
SELECT $1, 'weekly', c.id, c.owner_id, 'hu', 'm', 'v3', 'old', 'done', '{\"title\": \"Régi hét\"}', 0, $2 \
FROM charts c WHERE c.id = $3",
)
.bind(uuid::Uuid::now_v7())
.bind(old_week)
.bind(uuid::Uuid::parse_str(chart["id"].as_str().unwrap()).unwrap())
.execute(&pool)
.await
.unwrap();
let older_key = format!("{:04}-{:02}", old_week.year(), u8::from(old_week.month()));
let month = app.get("/v1/weekly/history", Some(&anna)).await.body;
assert_eq!(month["older"], older_key);
let back = app.get(&format!("/v1/weekly/history?month={older_key}"), Some(&anna)).await.body;
assert_eq!(back["weeks"][0]["analysis"]["content"]["title"], "Régi hét");
assert_eq!(back["weeks"][0]["week_start"], old_week.to_string());
assert_eq!(back["newer"], month["current_month"]);
// Not into the future; a bad month is refused; others see nothing of it.
assert_eq!(app.get("/v1/weekly/history?month=2999-01", Some(&anna)).await.body["month"], month["current_month"]);
assert_eq!(app.get("/v1/weekly/history?month=nope", Some(&anna)).await.status, StatusCode::BAD_REQUEST);
assert_eq!(app.get("/v1/weekly/history", Some(&bob)).await.body["weeks"], json!([]));
// Monday's e-mail: off and on again from the site.
let r = app.call("PUT", "/v1/weekly/email", Some(&anna), Some(json!({"on": false}))).await;
assert_eq!((r.status, &r.body["email"]), (StatusCode::OK, &json!(false)));
assert_eq!(app.get("/v1/me", Some(&anna)).await.body["weekly_email"], false);
app.call("PUT", "/v1/weekly/email", Some(&anna), Some(json!({"on": true}))).await;
let (on, sent_on): (bool, Option<time::Date>) =
sqlx::query_as("SELECT weekly_email, weekly_email_sent_on FROM users WHERE email = 'anna@example.com'")
.fetch_one(&pool)
.await
.unwrap();
// Turned on again, the first one comes next Monday.
assert_eq!((on, sent_on), (true, Some(start)));
// The page of every e-mail setting, from the footer link (no login).
let (token,): (uuid::Uuid,) = sqlx::query_as("SELECT email_token FROM users WHERE email = 'anna@example.com'")
.fetch_one(&pool)
.await
.unwrap();
let page = format!("/v1/public/notifications?token={token}");
let r = app.get(&page, None).await;
assert_eq!((r.status, &r.body), (StatusCode::OK, &json!({"weekly_horoscope": true, "forum": null})));
assert_eq!(app.get("/v1/public/notifications?token=nope", None).await.status, StatusCode::NOT_FOUND);
assert_eq!(
app.get(&format!("/v1/public/notifications?token={}", uuid::Uuid::now_v7()), None).await.status,
StatusCode::NOT_FOUND
);
// A forum member sees the forum's e-mails too.
sqlx::query(
"INSERT INTO forum.members (user_id, nickname, nickname_key, avatar) \
SELECT id, 'Csillag', 'csillag', 'moon-gold' FROM users WHERE email = 'anna@example.com'",
)
.execute(&pool)
.await
.unwrap();
let r = app.get(&page, None).await.body;
assert_eq!(
r["forum"],
json!({"replies": "daily", "followed": "off", "messages": "instant", "mentions": "instant", "listener": null, "weekly": false})
);
let mut forum = r["forum"].clone();
forum["replies"] = json!("loud");
let bad = app.call("PUT", &page, None, Some(json!({"weekly_horoscope": true, "forum": forum}))).await;
assert_eq!(bad.status, StatusCode::BAD_REQUEST);
let off = json!({"replies": "off", "followed": "off", "messages": "off", "mentions": "off", "listener": null, "weekly": false});
let r = app.call("PUT", &page, None, Some(json!({"weekly_horoscope": false, "forum": off}))).await;
assert_eq!((r.status, &r.body["weekly_horoscope"], &r.body["forum"]), (StatusCode::OK, &json!(false), &off));
// The mail client's one-click unsubscribe turns off the weekly e-mail only.
app.call("PUT", &page, None, Some(json!({"weekly_horoscope": true}))).await;
let r = app.call("POST", &format!("/v1/public/weekly/unsubscribe?token={token}"), None, None).await;
assert_eq!(r.status, StatusCode::OK, "{}", r.body);
assert_eq!(app.get(&page, None).await.body["weekly_horoscope"], false);
assert_eq!(
app.call("POST", "/v1/public/weekly/unsubscribe?token=nope", None, None).await.status,
StatusCode::NOT_FOUND
);
}
#[sqlx::test(migrator = "db::MIGRATOR")]
async fn forecasts_are_free_their_analysis_uses_a_forecast_unit(pool: PgPool) {
let app = TestApp::new(pool.clone()).await;