Merge the forum (community module) into main
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -1019,6 +1019,21 @@ async fn public_shares(pool: PgPool) {
|
||||
);
|
||||
assert_eq!(app.get(&format!("/v1/public/shares/{slug}"), None).await.status, StatusCode::NOT_FOUND);
|
||||
assert_eq!(app.get("/v1/public/shares/nincs-ilyen", None).await.status, StatusCode::NOT_FOUND);
|
||||
|
||||
// A share for the forum: its own link, never birth data, no names, no title.
|
||||
let r = app
|
||||
.post(
|
||||
"/v1/shares",
|
||||
Some(&anna),
|
||||
json!({"kind": "chart", "target_id": chart_id, "for_forum": true, "show_birth_data": true, "title": "Én"}),
|
||||
)
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::CREATED, "{}", r.body);
|
||||
assert_eq!((r.body["for_forum"].as_bool(), r.body["show_birth_data"].as_bool()), (Some(true), Some(false)));
|
||||
let r = app.get(&format!("/v1/public/shares/{}", r.body["slug"].as_str().unwrap()), None).await;
|
||||
assert!(r.body["chart"]["label"].is_null(), "{}", r.body);
|
||||
assert!(r.body["chart"]["chart"].get("birth").is_none());
|
||||
assert!(r.body["title"].is_null());
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
@@ -1032,12 +1047,39 @@ async fn export_and_delete_account(pool: PgPool) {
|
||||
assert_eq!(r.status, StatusCode::CREATED, "{}", r.body);
|
||||
let r = app.post("/v1/synastries", Some(&anna), json!({"chart1_id": b["id"], "chart2_id": a["id"]})).await;
|
||||
assert_eq!(r.status, StatusCode::OK); // already exists
|
||||
// Anna also wrote in the forum (services/forum keeps it in the same database).
|
||||
let (anna_id,): (uuid::Uuid,) =
|
||||
sqlx::query_as("SELECT id FROM users WHERE email = 'anna@example.com'").fetch_one(&app.pool).await.unwrap();
|
||||
sqlx::query(
|
||||
"INSERT INTO forum.members (user_id, nickname, nickname_key, avatar) \
|
||||
VALUES ($1, 'Holdfény', 'holdfeny', 'hold-ejkek')",
|
||||
)
|
||||
.bind(anna_id)
|
||||
.execute(&app.pool)
|
||||
.await
|
||||
.unwrap();
|
||||
let thread: i64 = sqlx::query_scalar(
|
||||
"INSERT INTO forum.threads (topic_id, author_id, title) VALUES (4, $1, 'Téli levesek') RETURNING id",
|
||||
)
|
||||
.bind(anna_id)
|
||||
.fetch_one(&app.pool)
|
||||
.await
|
||||
.unwrap();
|
||||
sqlx::query("INSERT INTO forum.posts (thread_id, author_id, is_opening, body) VALUES ($1, $2, true, 'Sütőtök')")
|
||||
.bind(thread)
|
||||
.bind(anna_id)
|
||||
.execute(&app.pool)
|
||||
.await
|
||||
.unwrap();
|
||||
|
||||
let r = app.get("/v1/me/export", Some(&anna)).await;
|
||||
assert_eq!(r.status, StatusCode::OK);
|
||||
assert_eq!(r.body["charts"].as_array().unwrap().len(), 2);
|
||||
assert_eq!(r.body["synastries"].as_array().unwrap().len(), 1);
|
||||
assert!(r.body["login_methods"][0].get("password_hash").is_none());
|
||||
assert_eq!(r.body["forum_profile"][0]["nickname"], "Holdfény");
|
||||
assert_eq!(r.body["forum_posts"][0]["body"], "Sütőtök");
|
||||
assert_eq!(r.body["forum_posts"][0]["thread_title"], "Téli levesek");
|
||||
|
||||
let r = app.call("DELETE", "/v1/me", Some(&anna), Some(json!({"confirm": "yes"}))).await;
|
||||
assert_eq!(r.status, StatusCode::BAD_REQUEST);
|
||||
@@ -1049,6 +1091,15 @@ async fn export_and_delete_account(pool: PgPool) {
|
||||
assert_eq!(r.status, StatusCode::UNAUTHORIZED);
|
||||
let (left,): (i64,) = sqlx::query_as("SELECT count(*) FROM charts").fetch_one(&app.pool).await.unwrap();
|
||||
assert_eq!(left, 0);
|
||||
// Her forum profile is gone; her thread stays, by "Törölt tag" (no author).
|
||||
let (members, author): (i64, Option<uuid::Uuid>) = sqlx::query_as(
|
||||
"SELECT (SELECT count(*) FROM forum.members), (SELECT author_id FROM forum.threads WHERE id = $1)",
|
||||
)
|
||||
.bind(thread)
|
||||
.fetch_one(&app.pool)
|
||||
.await
|
||||
.unwrap();
|
||||
assert_eq!((members, author), (0, None));
|
||||
assert_eq!(app.get("/v1/me", Some(&bela)).await.status, StatusCode::OK);
|
||||
}
|
||||
|
||||
@@ -1940,6 +1991,19 @@ async fn forecasts_are_free_their_analysis_uses_a_forecast_unit(pool: PgPool) {
|
||||
assert_eq!(app.get(&uri, Some(&bob)).await.status, StatusCode::NOT_FOUND);
|
||||
assert_eq!(app.get(&format!("/v1/forecasts/{id}"), Some(&anna)).await.body["year"], json!(year));
|
||||
|
||||
// A forecast can be shared (not by others), without where it was reckoned.
|
||||
let r = app.post("/v1/shares", Some(&bob), json!({"kind": "forecast", "target_id": away.body["id"]})).await;
|
||||
assert_eq!(r.status, StatusCode::NOT_FOUND);
|
||||
let r = app
|
||||
.post("/v1/shares", Some(&anna), json!({"kind": "forecast", "target_id": away.body["id"], "for_forum": true}))
|
||||
.await;
|
||||
assert_eq!(r.status, StatusCode::CREATED, "{}", r.body);
|
||||
let shared = app.get(&format!("/v1/public/shares/{}", r.body["slug"].as_str().unwrap()), None).await.body;
|
||||
assert_eq!(shared["kind"], "forecast");
|
||||
assert_eq!(shared["forecast"]["forecast"]["start"], format!("{year}-03-15"));
|
||||
assert!(!shared.to_string().contains("Tokió"), "the place stays private: {shared}");
|
||||
assert!(shared["analysis"].is_null(), "no detailed text yet");
|
||||
|
||||
// the detailed text uses a forecast unit, not a natal one
|
||||
let analyses = format!("/v1/forecasts/{id}/analyses");
|
||||
grant_units(&app, &anna, "natal", 1).await;
|
||||
|
||||
Reference in New Issue
Block a user