Admins use analysis units and questions too
They add their own units on the admin page when they need more, and testing shows the same balance as users see. Regenerating and prompt previews stay free. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012vLHzh5qUhFtmJhzkcTbXL
This commit is contained in:
@@ -277,6 +277,15 @@ impl TestApp {
|
||||
r.body["session"]["token"].as_str().unwrap().to_string()
|
||||
}
|
||||
|
||||
/// An admin adds units to their own account (admins use units too).
|
||||
async fn add_own_units(&self, admin: &str, unit: &str, delta: i32) {
|
||||
let id = self.get("/v1/me", Some(admin)).await.body["user"]["id"].as_str().unwrap().to_string();
|
||||
let r = self
|
||||
.post(&format!("/v1/admin/users/{id}/credits"), Some(admin), json!({"unit": unit, "delta": delta}))
|
||||
.await;
|
||||
assert!(r.status.is_success(), "{}", r.body);
|
||||
}
|
||||
|
||||
async fn chart(&self, token: &str, label: &str, primary: bool, date: &str) -> Value {
|
||||
let r = self
|
||||
.post(
|
||||
@@ -1061,13 +1070,18 @@ async fn birth_data_changes_are_limited(pool: PgPool) {
|
||||
}
|
||||
|
||||
#[sqlx::test(migrator = "db::MIGRATOR")]
|
||||
async fn admins_get_free_analyses_and_mock_payments_add_units(pool: PgPool) {
|
||||
async fn admins_use_units_too_and_mock_payments_add_units(pool: PgPool) {
|
||||
let app = TestApp::new(pool).await;
|
||||
let admin = app.register("admin@example.com", "Admin").await;
|
||||
let chart = app.chart(&admin, "Saját", true, "1990-03-15").await;
|
||||
let r =
|
||||
app.call("POST", &format!("/v1/charts/{}/analyses", chart["id"].as_str().unwrap()), Some(&admin), None).await;
|
||||
assert_eq!((r.status, &r.body["credits_charged"]), (StatusCode::ACCEPTED, &json!(0)), "{}", r.body);
|
||||
let analyses = format!("/v1/charts/{}/analyses", chart["id"].as_str().unwrap());
|
||||
// Admins pay with units like everyone (they add their own on the admin page).
|
||||
let r = app.call("POST", &analyses, Some(&admin), None).await;
|
||||
assert_eq!(r.status, StatusCode::PAYMENT_REQUIRED, "{}", r.body);
|
||||
app.add_own_units(&admin, "natal", 2).await;
|
||||
let r = app.call("POST", &analyses, Some(&admin), None).await;
|
||||
assert_eq!((r.status, &r.body["credits_charged"]), (StatusCode::ACCEPTED, &json!(1)), "{}", r.body);
|
||||
assert_eq!(app.get("/v1/credits", Some(&admin)).await.body["balance"]["natal"], 1);
|
||||
|
||||
// a user "pays", which adds a unit, then requests the analysis
|
||||
let anna = app.register("anna@example.com", "Anna").await;
|
||||
@@ -1750,6 +1764,7 @@ async fn admins_choose_the_model_of_each_function(pool: PgPool) {
|
||||
assert_eq!((r.status, &r.body["model"], &r.body["custom"]), (StatusCode::OK, &json!("openai/gpt-x"), &json!(true)));
|
||||
|
||||
// new analyses use it; regenerating writes it again in place with the current model
|
||||
app.add_own_units(&admin, "natal", 1).await;
|
||||
let chart = app.chart(&admin, "Saját", true, "1990-03-15").await;
|
||||
let chart_id = chart["id"].as_str().unwrap();
|
||||
let r = app.post(&format!("/v1/charts/{chart_id}/analyses"), Some(&admin), json!({})).await;
|
||||
@@ -1880,6 +1895,7 @@ async fn admins_restart_open_generations_with_the_current_models(pool: PgPool) {
|
||||
async move { app.call("PUT", "/v1/admin/models/analysis", Some(admin), Some(body)).await }
|
||||
};
|
||||
assert_eq!(put("openai/gpt-x").await.status, StatusCode::OK);
|
||||
app.add_own_units(&admin, "natal", 1).await;
|
||||
let chart = app.chart(&admin, "Saját", true, "1990-03-15").await;
|
||||
let chart_id = chart["id"].as_str().unwrap();
|
||||
let r = app.post(&format!("/v1/charts/{chart_id}/analyses"), Some(&admin), json!({})).await;
|
||||
|
||||
Reference in New Issue
Block a user