an http based roguelike rpg about jelqing
Blame: src/tests.rs
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1 | use std::{ |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 2 | sync::Arc, |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 3 | time::{Duration, Instant}, |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 4 | }; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 5 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 6 | use axum::{ |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 7 | Router, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 8 | body::{Body, to_bytes}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 9 | http::{Method, Request, StatusCode, Version, header}, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 10 | response::Response, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 11 | }; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 12 | use serde_json::Value; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 13 | use tower::ServiceExt; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 14 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | use crate::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 16 | AppState, Config, |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 17 | game::{Floor, MumVisit, Run, Story, balance::BRANCH_TURN, balance::SUSPICION_LIMIT}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 18 | router, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 19 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 20 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 21 | async fn send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 22 | app: &Router, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 23 | method: &str, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 24 | uri: &str, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 25 | headers: &[(&str, &str)], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 26 | body: &str, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 27 | ) -> Response { |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 28 | let mut request = Request::builder() |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 29 | .method(Method::from_bytes(method.as_bytes()).unwrap()) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 30 | .uri(uri); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 31 | for (name, value) in headers { |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 32 | request = request.header(*name, *value); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 33 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 34 | app.clone() |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 35 | .oneshot(request.body(Body::from(body.to_owned())).unwrap()) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 36 | .await |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 37 | .unwrap() |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 38 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 39 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 40 | async fn json(response: Response) -> Value { |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 41 | serde_json::from_slice(&to_bytes(response.into_body(), usize::MAX).await.unwrap()).unwrap() |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 42 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 43 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 44 | async fn text(response: Response) -> String { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 45 | String::from_utf8( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 46 | to_bytes(response.into_body(), usize::MAX) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 47 | .await |
782069860236 | atagen | 2026-10-10 12:44 UTC | 48 | .unwrap() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 49 | .to_vec(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 50 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 51 | .unwrap() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 52 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 53 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 54 | fn header<'a>(response: &'a Response, name: &str) -> &'a str { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 55 | response.headers()[name].to_str().unwrap() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 56 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 57 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 58 | fn fixture() -> Run { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 59 | Run::new("cafebabe".into(), "cafe".into(), 69) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 60 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 61 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 62 | fn seeded_with(floor: Floor, setup: impl FnOnce(&mut Run)) -> Router { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 63 | let state = Arc::new(AppState::default()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 64 | let mut run = fixture(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 65 | run.floor = floor; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 66 | setup(&mut run); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 67 | state.insert(run); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 68 | router(state) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 69 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 70 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 71 | fn seeded(floor: Floor) -> (Router, String) { |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 72 | let state = Arc::new(AppState::default()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 73 | let mut run = fixture(); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 74 | run.floor = floor; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 75 | let etag = run.origin_etag(); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 76 | state.insert(run); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 77 | (router(state), etag) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 78 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 79 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 80 | fn app() -> Router { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 81 | crate::app(Config::default()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 82 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 83 | |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 84 | fn mum_at_the_door(run: &mut Run) { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 85 | run.mum = Some(MumVisit { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 86 | errand: "She heard a noise.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 87 | nonce: "abc".into(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 88 | strikes: 0, |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 89 | knocked: false, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 90 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 91 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 92 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 93 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 94 | async fn creating_a_run_returns_location_and_etag() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 95 | let response = send(&app(), "POST", "/runs?seed=1", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 96 | assert_eq!(response.status(), StatusCode::CREATED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 97 | assert!(header(&response, "location").starts_with("/runs/")); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 98 | assert!(response.headers().contains_key(header::ETAG)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 99 | assert_eq!(header(&response, "server"), "jelqd/0.6.9"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 100 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 101 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 102 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 103 | async fn bodies_do_not_repeat_the_headers() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 104 | let (app, _) = seeded(Floor::Bedroom); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 105 | let response = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | assert!(response.headers().contains_key("x-eq")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | let body = json(response).await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | for stat in [ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | "eq", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 110 | "girth", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | "foreskin", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 112 | "stamina", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | "cash", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 114 | "self_reported_length", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 115 | ] { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 116 | assert!(body.get(stat).is_none(), "{stat} is already a header"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 117 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 118 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 119 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 120 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 121 | async fn jelqing_cold_fails_the_precondition() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 122 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 123 | let response = send(&app, "JELQ", "/runs/cafebabe?technique=stretch", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 124 | assert_eq!(response.status(), StatusCode::PRECONDITION_FAILED); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 125 | assert_eq!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 126 | header(&response, "content-type"), |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 127 | "application/problem+json" |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 128 | ); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 129 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 130 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 131 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 132 | async fn wet_without_lube_is_unsupported_media() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 133 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 134 | send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 135 | let response = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 136 | assert_eq!(response.status(), StatusCode::UNSUPPORTED_MEDIA_TYPE); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 137 | let images = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 138 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 139 | "JELQ", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 140 | "/runs/cafebabe?technique=wet", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 141 | &[("content-type", "image/jpeg")], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 142 | "", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 143 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 144 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 145 | assert_eq!(json(images).await["detail"], "No."); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 146 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 147 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 148 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 149 | async fn unknown_methods_are_not_implemented() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 150 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 151 | let response = send(&app, "MILK", "/runs/cafebabe", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 152 | assert_eq!(response.status(), StatusCode::NOT_IMPLEMENTED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 153 | let teapot = send(&app, "BREW", "/runs/cafebabe", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 154 | assert_eq!(teapot.status(), StatusCode::IM_A_TEAPOT); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 155 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 156 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 157 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 158 | async fn the_clinic_does_not_advertise_jelq() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 159 | let (app, _) = seeded(Floor::Clinic); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 160 | let options = send(&app, "OPTIONS", "/runs/cafebabe", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 161 | assert!(!header(&options, "allow").contains("JELQ")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 162 | let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 163 | assert_eq!(jelq.status(), StatusCode::METHOD_NOT_ALLOWED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 164 | assert!(!header(&jelq, "allow").contains("JELQ")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 165 | let (bedroom, _) = seeded(Floor::Bedroom); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 166 | let options = send(&bedroom, "OPTIONS", "/runs/cafebabe", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 167 | assert!(header(&options, "allow").contains("JELQ")); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 168 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 169 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 170 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 171 | async fn patch_only_accepts_the_truth() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 172 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 173 | let patch = [("content-type", "application/json-patch+json")]; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 174 | let replace = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 175 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 176 | "PATCH", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 177 | "/runs/cafebabe", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 178 | &patch, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 179 | r#"[{"op":"replace","path":"/length","value":12}]"#, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 180 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 181 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 182 | assert_eq!(replace.status(), StatusCode::UNPROCESSABLE_ENTITY); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 183 | let lie = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 184 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 185 | "PATCH", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 186 | "/runs/cafebabe", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 187 | &patch, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 188 | r#"[{"op":"test","path":"/length","value":40}]"#, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 189 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 190 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 191 | assert_eq!( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 192 | json(lie).await["type"], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 193 | "https://jelq.dev/problems/exaggeration" |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 194 | ); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 195 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 196 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 197 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 198 | async fn deleting_the_foreskin_requires_certainty() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 199 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 200 | let response = send(&app, "DELETE", "/runs/cafebabe/foreskin", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 201 | assert_eq!(response.status(), StatusCode::PRECONDITION_REQUIRED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 202 | let look = send(&app, "GET", "/runs/cafebabe/foreskin", &[], "").await; |
ec6fd4bb5b60 | atagen | 2026-10-11 04:34 UTC | 203 | assert_eq!(look.status(), StatusCode::OK); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 204 | let etag = header(&look, "etag").to_owned(); |
ec6fd4bb5b60 | atagen | 2026-10-11 04:34 UTC | 205 | assert!(text(look).await.contains('~')); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 206 | let response = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 207 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 208 | "DELETE", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 209 | "/runs/cafebabe/foreskin", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 210 | &[("if-match", &etag)], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 211 | "", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 212 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 213 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 214 | assert_eq!(response.status(), StatusCode::NO_CONTENT); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 215 | let response = send(&app, "GET", "/runs/cafebabe/foreskin", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 216 | assert_eq!(response.status(), StatusCode::GONE); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 217 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 218 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 219 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 220 | async fn length_is_chunked_until_the_ruler() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 221 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 222 | let lie = send(&app, "GET", "/runs/cafebabe/length", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 223 | assert!(!lie.headers().contains_key(header::CONTENT_LENGTH)); |
ad00e0e051a1 | atagen | 2026-10-10 14:00 UTC | 224 | let app = seeded_with(Floor::Bedroom, |run| run.items.ruler = true); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 225 | let truth = send(&app, "GET", "/runs/cafebabe/length", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 226 | let declared: usize = header(&truth, "content-length").parse().unwrap(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 227 | let body = text(truth).await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 228 | assert_eq!(body.len(), declared); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 229 | assert!(body.starts_with("8=") && body.ends_with('D')); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 230 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 231 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 232 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 233 | async fn length_supports_inch_ranges() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 234 | let (app, _) = seeded(Floor::Bedroom); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 235 | let response = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 236 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 237 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 238 | "/runs/cafebabe/length", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 239 | &[("range", "inches=0-1")], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 240 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 241 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 242 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 243 | assert_eq!(response.status(), StatusCode::PARTIAL_CONTENT); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 244 | assert!(header(&response, "content-range").starts_with("inches 0.00-1.00/")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 245 | assert_eq!(text(response).await.len(), 25); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 246 | let absurd = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 247 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 248 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 249 | "/runs/cafebabe/length", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 250 | &[("range", "inches=40-50")], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 251 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 252 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 253 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 254 | assert_eq!(absurd.status(), StatusCode::RANGE_NOT_SATISFIABLE); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 255 | let malformed = send( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 256 | &app, |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 257 | "GET", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 258 | "/runs/cafebabe/length", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 259 | &[("range", "inches=6.17")], |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 260 | "", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 261 | ) |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 262 | .await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 263 | assert_eq!(malformed.status(), StatusCode::OK); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 264 | let suffix = send( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 265 | &app, |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 266 | "GET", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 267 | "/runs/cafebabe/length", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 268 | &[("range", "inches=-1")], |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 269 | "", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 270 | ) |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 271 | .await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 272 | assert_eq!(suffix.status(), StatusCode::PARTIAL_CONTENT); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 273 | assert!(text(suffix).await.ends_with('D')); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 274 | for (range, status) in [ |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 275 | ("inches=1-", StatusCode::PARTIAL_CONTENT), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 276 | ("inches=40-", StatusCode::RANGE_NOT_SATISFIABLE), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 277 | ("inches=-0", StatusCode::RANGE_NOT_SATISFIABLE), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 278 | ("inches=2-1", StatusCode::OK), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 279 | ("inches=NaN-2", StatusCode::OK), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 280 | ("inches=0-inf", StatusCode::OK), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 281 | ] { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 282 | let response = send( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 283 | &app, |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 284 | "GET", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 285 | "/runs/cafebabe/length", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 286 | &[("range", range)], |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 287 | "", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 288 | ) |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 289 | .await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 290 | assert_eq!(response.status(), status, "{range}"); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 291 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 292 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 293 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 294 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 295 | async fn the_clinic_escalates_toward_honesty() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 296 | let (app, _) = seeded(Floor::Clinic); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 297 | let mut hints = Vec::new(); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 298 | for _ in 0..3 { |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 299 | let response = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 300 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 301 | "GET", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 302 | "/runs/cafebabe/diagnosis", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 303 | &[("authorization", "Excuse \"changing\"")], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 304 | "", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 305 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 306 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 307 | assert_eq!(response.status(), StatusCode::UNAUTHORIZED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 308 | hints.push(header(&response, "www-authenticate").to_owned()); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 309 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 310 | assert!(hints[2].contains("Be honest.")); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 311 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 312 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 313 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 314 | async fn the_true_ending_is_not_modified() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 315 | let (early, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 316 | let response = send(&early, "GET", "/runs/cafebabe/diagnosis", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 317 | assert_eq!(response.status(), StatusCode::TOO_EARLY); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 318 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 319 | let (app, etag) = seeded(Floor::Clinic); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 320 | assert!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 321 | !etag.contains("cafebabe"), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 322 | "the origin ETag must not be derivable from the id" |
782069860236 | atagen | 2026-10-10 12:44 UTC | 323 | ); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 324 | let response = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 325 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 326 | "GET", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 327 | "/runs/cafebabe/diagnosis", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 328 | &[ |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 329 | ("authorization", "Bearer honesty"), |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 330 | ("if-none-match", &etag), |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 331 | ], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 332 | "", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 333 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 334 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 335 | assert_eq!(response.status(), StatusCode::NOT_MODIFIED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 336 | assert_eq!(header(&response, "x-diagnosis"), "normal"); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 337 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 338 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 339 | #[tokio::test] |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 340 | async fn mum_accepts_a_known_excuse() { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 341 | let app = seeded_with(Floor::Bedroom, mum_at_the_door); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 342 | let response = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 343 | assert_eq!(response.status(), StatusCode::UNAUTHORIZED); |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 344 | assert_eq!(header(&response, "via"), "1.1 mum"); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 345 | let response = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 346 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 347 | "GET", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 348 | "/runs/cafebabe", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 349 | &[("authorization", "Excuse \"homework\"")], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 350 | "", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 351 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 352 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 353 | assert_eq!(response.status(), StatusCode::OK); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 354 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 355 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 356 | #[tokio::test] |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 357 | async fn mum_runs_out_of_patience() { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 358 | let app = seeded_with(Floor::Bedroom, mum_at_the_door); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 359 | let lie = [("authorization", "Excuse \"it is for science\"")]; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 360 | for _ in 0..2 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 361 | let response = send(&app, "GET", "/runs/cafebabe", &lie, "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 362 | assert_eq!(response.status(), StatusCode::UNAUTHORIZED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 363 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 364 | let caught = send(&app, "GET", "/runs/cafebabe", &lie, "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 365 | assert_eq!(caught.status(), StatusCode::GONE); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 366 | assert_eq!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 367 | json(caught).await["type"], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 368 | "https://jelq.dev/problems/caught" |
782069860236 | atagen | 2026-10-10 12:44 UTC | 369 | ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 370 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 371 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 372 | #[tokio::test] |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 373 | async fn mum_remembers_excuses_by_christmas() { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 374 | let app = seeded_with(Floor::Nans, |run| { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 375 | mum_at_the_door(run); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 376 | run.heard.push("homework".into()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 377 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 378 | let basic = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 379 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 380 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 381 | "/runs/cafebabe", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 382 | &[("authorization", "Excuse \"changing\"")], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 383 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 384 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 385 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 386 | assert_eq!(basic.status(), StatusCode::UNAUTHORIZED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 387 | assert!(header(&basic, "www-authenticate").starts_with("Digest")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 388 | let replay = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 389 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 390 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 391 | "/runs/cafebabe", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 392 | &[( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 393 | "authorization", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 394 | "Digest username=\"homework\", nonce=\"abc\"", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 395 | )], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 396 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 397 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 398 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 399 | assert_eq!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 400 | json(replay).await["type"], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 401 | "https://jelq.dev/problems/excuse-replayed" |
782069860236 | atagen | 2026-10-10 12:44 UTC | 402 | ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 403 | let fresh = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 404 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 405 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 406 | "/runs/cafebabe", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 407 | &[( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 408 | "authorization", |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 409 | "Digest username=\"wrapping presents\", nonce=\"abc\"", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 410 | )], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 411 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 412 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 413 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 414 | assert_eq!(fresh.status(), StatusCode::OK); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 415 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 416 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 417 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 418 | async fn a_pulled_muscle_is_a_true_excuse() { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 419 | let app = seeded_with(Floor::Nans, |run| { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 420 | mum_at_the_door(run); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 421 | run.conditions.pulled_muscle = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 422 | run.heard.push("pulled a muscle".into()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 423 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 424 | let response = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 425 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 426 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 427 | "/runs/cafebabe", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 428 | &[( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 429 | "authorization", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 430 | "Digest username=\"pulled a muscle\", nonce=\"abc\"", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 431 | )], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 432 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 433 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 434 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 435 | assert_eq!(response.status(), StatusCode::OK); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 436 | assert!(header(&response, "x-stamina").ends_with("/7")); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 437 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 438 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 439 | #[tokio::test] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 440 | async fn floors_end_when_they_end() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 441 | let app = seeded_with(Floor::Bedroom, |_| {}); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 442 | let early = send(&app, "POST", "/runs/cafebabe/floor", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 443 | assert_eq!(early.status(), StatusCode::TOO_EARLY); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 444 | let app = seeded_with(Floor::Bedroom, |run| run.here.turns = 6); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 445 | let next = send(&app, "POST", "/runs/cafebabe/floor", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 446 | assert!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 447 | next.status() == StatusCode::SEE_OTHER || next.status() == StatusCode::CONFLICT, |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 448 | "either the floor changed or the zip did" |
782069860236 | atagen | 2026-10-10 12:44 UTC | 449 | ); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 450 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 451 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 452 | #[tokio::test] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 453 | async fn pump_bro_upsells() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 454 | let closed = seeded_with(Floor::Bedroom, |_| {}); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 455 | let response = send(&closed, "GET", "/runs/cafebabe/shop", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 456 | assert_eq!(response.status(), StatusCode::NOT_FOUND); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 457 | |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 458 | let app = seeded_with(Floor::ChangingRoom, |_| {}); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 459 | let pump = send(&app, "POST", "/runs/cafebabe/shop/pump", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 460 | assert_eq!(pump.status(), StatusCode::UPGRADE_REQUIRED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 461 | assert_eq!(header(&pump, "upgrade"), "pump-pro/2.0"); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 462 | let pro = send(&app, "POST", "/runs/cafebabe/shop/pump-pro", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 463 | assert_eq!(pro.status(), StatusCode::CREATED); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 464 | let broke = send(&app, "POST", "/runs/cafebabe/shop/extender", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 465 | assert_eq!(broke.status(), StatusCode::PAYMENT_REQUIRED); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 466 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 467 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 468 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 469 | async fn only_the_key_opens_the_cage() { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 470 | let app = seeded_with(Floor::ChangingRoom, |run| run.items.cage = true); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 471 | send(&app, "POST", "/runs/cafebabe/shop/ice-pack", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 472 | let still = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 473 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 474 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 475 | "/runs/cafebabe/inventory/chastity-cage", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 476 | &[], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 477 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 478 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 479 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 480 | assert_eq!(still.status(), StatusCode::OK); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 481 | send(&app, "POST", "/runs/cafebabe/shop/cage-key", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 482 | let gone = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 483 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 484 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 485 | "/runs/cafebabe/inventory/chastity-cage", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 486 | &[], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 487 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 488 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 489 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 490 | assert_eq!(gone.status(), StatusCode::NOT_FOUND); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 491 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 492 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 493 | #[tokio::test] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 494 | async fn combos_are_multi_status_xml() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 495 | let app = seeded_with(Floor::Bathroom, |run| { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 496 | run.foreskin = Some(1.0); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 497 | run.items.blinds = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 498 | }); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 499 | send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 500 | let response = send( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 501 | &app, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 502 | "JELQ", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 503 | "/runs/cafebabe?technique=wet,stretch", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 504 | &[("content-type", "application/baby-oil")], |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 505 | "", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 506 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 507 | .await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 508 | assert_eq!(response.status(), StatusCode::MULTI_STATUS); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 509 | assert!(text(response).await.contains("<D:multistatus")); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 510 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 511 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 512 | #[tokio::test] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 513 | async fn the_elder_is_stale() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 514 | let app = seeded_with(Floor::Forum, |run| run.length = 5.0); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 515 | let unverified = send(&app, "GET", "/runs/cafebabe/elder", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 516 | assert_eq!( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 517 | unverified.status(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 518 | StatusCode::PROXY_AUTHENTICATION_REQUIRED |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 519 | ); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 520 | let lie = send( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 521 | &app, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 522 | "GET", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 523 | "/runs/cafebabe/elder", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 524 | &[("proxy-authorization", "Ruler 9")], |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 525 | "", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 526 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 527 | .await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 528 | assert_eq!(lie.status(), StatusCode::BAD_REQUEST); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 529 | let csv = send( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 530 | &app, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 531 | "GET", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 532 | "/runs/cafebabe/elder", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 533 | &[("proxy-authorization", "Ruler 5.0")], |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 534 | "", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 535 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 536 | .await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 537 | assert_eq!(csv.status(), StatusCode::OK); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 538 | let stale = send( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 539 | &app, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 540 | "GET", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 541 | "/runs/cafebabe/elder", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 542 | &[("if-modified-since", "Mon, 15 Jun 2009 00:00:00 GMT")], |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 543 | "", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 544 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 545 | .await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 546 | assert_eq!(stale.status(), StatusCode::NOT_MODIFIED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 547 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 548 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 549 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 550 | async fn the_displayed_length_is_accepted_as_honest() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 551 | let app = seeded_with(Floor::Forum, |run| run.length = 5.2496); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 552 | let response = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 553 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 554 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 555 | "/runs/cafebabe/elder", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 556 | &[("proxy-authorization", "Ruler 5.25")], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 557 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 558 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 559 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 560 | assert_eq!(response.status(), StatusCode::OK); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 561 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 562 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 563 | #[tokio::test] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 564 | async fn the_hotel_has_a_captive_portal() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 565 | let app = seeded_with(Floor::Hotel, |_| {}); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 566 | let blocked = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 567 | assert_eq!( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 568 | blocked.status(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 569 | StatusCode::NETWORK_AUTHENTICATION_REQUIRED |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 570 | ); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 571 | let accepted = send(&app, "POST", "/runs/cafebabe/portal", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 572 | assert_eq!(accepted.status(), StatusCode::SEE_OTHER); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 573 | let online = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 574 | assert_eq!(online.status(), StatusCode::OK); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 575 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 576 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 577 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 578 | async fn the_internet_never_forgets() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 579 | let app = seeded_with(Floor::Bedroom, |run| { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 580 | run.filmed_at = Some(std::time::SystemTime::now()); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 581 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 582 | let footage = send(&app, "GET", "/runs/cafebabe/footage", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 583 | assert_eq!(footage.status(), StatusCode::OK); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 584 | assert_eq!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 585 | header(&footage, "cache-control"), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 586 | "public, max-age=31536000, immutable" |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 587 | ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 588 | assert!(footage.headers().contains_key(header::AGE)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 589 | let delete = send(&app, "DELETE", "/runs/cafebabe/footage", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 590 | assert_eq!(delete.status(), StatusCode::METHOD_NOT_ALLOWED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 591 | assert!(!header(&delete, "allow").contains("DELETE")); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 592 | } |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 593 | |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 594 | #[tokio::test] |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 595 | async fn forged_ruler_cookies_are_lies() { |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 596 | let forged = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 597 | &app(), |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 598 | "GET", |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 599 | "/leaderboard?sort=content-length", |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 600 | &[("cookie", "ruler=1")], |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 601 | "", |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 602 | ) |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 603 | .await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 604 | assert_eq!(forged.status(), StatusCode::BAD_REQUEST); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 605 | } |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 606 | |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 607 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 608 | async fn listings_never_reveal_the_private_id() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 609 | let app = app(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 610 | let created = send(&app, "POST", "/runs", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 611 | let location = header(&created, "location").to_owned(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 612 | let board = text(send(&app, "GET", "/leaderboard", &[], "").await).await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 613 | let private = location.trim_start_matches("/runs/"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 614 | assert!(!board.contains(private)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 615 | let entry: Value = serde_json::from_str(&board).unwrap(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 616 | let public = entry["entries"][0]["public_id"].as_str().unwrap(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 617 | let guess = send(&app, "DELETE", &format!("/runs/{public}"), &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 618 | assert_eq!(guess.status(), StatusCode::NOT_FOUND); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 619 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 620 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 621 | #[tokio::test] |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 622 | async fn seeded_runs_are_unranked() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 623 | let app = app(); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 624 | send(&app, "POST", "/runs?seed=7", &[], "").await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 625 | let board = json(send(&app, "GET", "/leaderboard", &[], "").await).await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 626 | assert_eq!(board["entries"].as_array().unwrap().len(), 0); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 627 | let all = json(send(&app, "GET", "/leaderboard?seeded=include", &[], "").await).await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 628 | assert_eq!(all["entries"][0]["ranked"], false); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 629 | } |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 630 | |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 631 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 632 | async fn idle_runs_are_evicted_and_the_server_has_a_limit() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 633 | let forgetful = crate::app(Config { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 634 | idle_ttl: Duration::ZERO, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 635 | ..Config::default() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 636 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 637 | let first = send(&forgetful, "POST", "/runs", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 638 | let location = header(&first, "location").to_owned(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 639 | send(&forgetful, "POST", "/runs", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 640 | let gone = send(&forgetful, "GET", &location, &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 641 | assert_eq!(gone.status(), StatusCode::NOT_FOUND); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 642 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 643 | let tiny = crate::app(Config { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 644 | max_runs: 1, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 645 | ..Config::default() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 646 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 647 | send(&tiny, "POST", "/runs", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 648 | let full = send(&tiny, "POST", "/runs", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 649 | assert_eq!(full.status(), StatusCode::SERVICE_UNAVAILABLE); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 650 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 651 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 652 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 653 | async fn shame_from_two_runs_adds_up() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 654 | let state = Arc::new(AppState::default()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 655 | state.insert(fixture()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 656 | state.insert(Run::new("deadbeef".into(), "dead".into(), 7)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 657 | let app = router(state); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 658 | let first = send(&app, "TRACE", "/runs/cafebabe", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 659 | assert_eq!(header(&first, "x-shame"), "1"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 660 | let cookie = header(&first, "set-cookie") |
782069860236 | atagen | 2026-10-10 12:44 UTC | 661 | .split(';') |
782069860236 | atagen | 2026-10-10 12:44 UTC | 662 | .next() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 663 | .unwrap() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 664 | .to_owned(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 665 | let second = send(&app, "TRACE", "/runs/deadbeef", &[("cookie", &cookie)], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 666 | assert_eq!(header(&second, "x-shame"), "2"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 667 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 668 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 669 | #[tokio::test] |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 670 | async fn the_root_negotiates() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 671 | let app = app(); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 672 | let browser = send(&app, "GET", "/", &[("accept", "text/html,*/*")], "").await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 673 | assert_eq!(browser.status(), StatusCode::SEE_OTHER); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 674 | assert_eq!(header(&browser, "location"), "/ui/"); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 675 | let curl = send(&app, "GET", "/", &[("accept", "*/*")], "").await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 676 | assert_eq!(json(curl).await["ui"], "/ui/"); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 677 | let page = send(&app, "GET", "/ui/", &[], "").await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 678 | assert_eq!(page.status(), StatusCode::OK); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 679 | } |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 680 | |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 681 | #[tokio::test] |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 682 | async fn the_ui_replays_what_browsers_cannot_send() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 683 | let app = app(); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 684 | let envelope = |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 685 | r#"{"method": "TRACE", "path": "/graveyard", "headers": [["X-Confession", "I did it"]]}"#; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 686 | let traced = json(send(&app, "POST", "/ui/send", &[], envelope).await).await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 687 | assert_eq!(traced["status"], 405); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 688 | let envelope = r#"{"method": "GET", "path": "/", "headers": [["Accept", "text/html"]]}"#; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 689 | let redirected = json(send(&app, "POST", "/ui/send", &[], envelope).await).await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 690 | assert_eq!(redirected["status"], 303); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 691 | assert_eq!(redirected["reason"], "See Other"); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 692 | } |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 693 | |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 694 | #[tokio::test] |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 695 | async fn the_ui_decodes_gzip_for_display() { |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 696 | let app = seeded_with(Floor::Bedroom, |run| run.items.ring = true); |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 697 | let envelope = |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 698 | r#"{"method": "GET", "path": "/runs/cafebabe", "headers": [["Accept-Encoding", "gzip"]]}"#; |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 699 | let shown = json(send(&app, "POST", "/ui/send", &[], envelope).await).await; |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 700 | assert!( |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 701 | shown["body"] |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 702 | .as_str() |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 703 | .unwrap() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 704 | .contains("\"public_id\":\"cafe\"") |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 705 | ); |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 706 | let encoding = shown["headers"] |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 707 | .as_array() |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 708 | .unwrap() |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 709 | .iter() |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 710 | .any(|h| h[0] == "content-encoding" && h[1] == "gzip"); |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 711 | assert!(encoding); |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 712 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 713 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 714 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 715 | async fn http_1_0_gets_the_pdf_treatment() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 716 | let request = Request::builder() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 717 | .uri("/graveyard") |
782069860236 | atagen | 2026-10-10 12:44 UTC | 718 | .version(Version::HTTP_10) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 719 | .body(Body::empty()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 720 | .unwrap(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 721 | let response = app().oneshot(request).await.unwrap(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 722 | assert_eq!(response.status(), StatusCode::HTTP_VERSION_NOT_SUPPORTED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 723 | } |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 724 | |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 725 | #[tokio::test] |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 726 | async fn mom_speaks_american() { |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 727 | let app = seeded_with(Floor::Nans, mum_at_the_door); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 728 | let us = [("accept-language", "en-US")]; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 729 | let knock = send(&app, "GET", "/runs/cafebabe", &us, "").await; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 730 | assert_eq!(header(&knock, "content-language"), "en-US"); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 731 | assert_eq!(header(&knock, "via"), "1.1 mom"); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 732 | assert!( |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 733 | json(knock).await["detail"] |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 734 | .as_str() |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 735 | .unwrap() |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 736 | .contains("Someone is at the door.") |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 737 | ); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 738 | let excuse = [ |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 739 | ("accept-language", "en-US"), |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 740 | ( |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 741 | "authorization", |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 742 | "Digest username=\"carving the turkey\", nonce=\"abc\"", |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 743 | ), |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 744 | ]; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 745 | let answered = send(&app, "GET", "/runs/cafebabe", &excuse, "").await; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 746 | assert_eq!(answered.status(), StatusCode::OK); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 747 | let floor = json(send(&app, "GET", "/runs/cafebabe/floor", &us, "").await).await; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 748 | assert_eq!(floor["name"], "Grandma's house for Thanksgiving"); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 749 | } |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 750 | |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 751 | #[tokio::test] |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 752 | async fn the_default_locale_is_british() { |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 753 | let (app, _) = seeded(Floor::Nans); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 754 | let floor = send(&app, "GET", "/runs/cafebabe/floor", &[], "").await; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 755 | assert_eq!(header(&floor, "content-language"), "en-GB"); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 756 | assert!(header(&floor, "vary").contains("Accept-Language")); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 757 | assert_eq!(json(floor).await["name"], "Nan's house at Christmas"); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 758 | } |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 759 | |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 760 | fn advertised(response: &Response) -> Vec<String> { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 761 | header(response, "link") |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 762 | .split(", <") |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 763 | .filter(|entry| entry.contains("rels/technique")) |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 764 | .filter_map(|entry| { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 765 | entry |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 766 | .split("title=\"") |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 767 | .nth(1)? |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 768 | .split('"') |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 769 | .next() |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 770 | .map(str::to_owned) |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 771 | }) |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 772 | .collect() |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 773 | } |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 774 | |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 775 | #[tokio::test] |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 776 | async fn links_offer_only_usable_techniques() { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 777 | let app = seeded_with(Floor::Bedroom, |run| run.foreskin = Some(1.0)); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 778 | let cold = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 779 | assert_eq!(advertised(&cold), ["warmup", "ice"]); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 780 | let warm = send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await; |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 781 | let usable = advertised(&warm); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 782 | assert!(usable.contains(&"wet".to_owned()) && usable.contains(&"dry".to_owned())); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 783 | assert!(!usable.contains(&"uli".to_owned()), "uli needs the forum"); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 784 | assert!(!usable.contains(&"pump".to_owned()), "pump needs a pump"); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 785 | assert!( |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 786 | header(&warm, "link").contains("title=\"wet\"; allow=\"JELQ\"; lubricant=\"required\"") |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 787 | ); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 788 | |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 789 | let (forum, _) = seeded(Floor::Forum); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 790 | let response = send(&forum, "GET", "/runs/cafebabe", &[], "").await; |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 791 | assert!(advertised(&response).is_empty()); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 792 | } |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 793 | |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 794 | fn linked_rels(response: &Response) -> Vec<String> { |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 795 | header(response, "link") |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 796 | .split(", <") |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 797 | .filter_map(|entry| { |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 798 | entry |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 799 | .split("rels/") |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 800 | .nth(1)? |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 801 | .split('"') |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 802 | .next() |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 803 | .map(str::to_owned) |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 804 | }) |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 805 | .filter(|rel| rel != "technique") |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 806 | .collect() |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 807 | } |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 808 | |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 809 | #[tokio::test] |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 810 | async fn links_hide_resources_that_would_do_nothing() { |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 811 | let (bedroom, _) = seeded(Floor::Bedroom); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 812 | let before = linked_rels(&send(&bedroom, "GET", "/runs/cafebabe", &[], "").await); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 813 | assert!(before.contains(&"drawer".to_owned())); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 814 | assert!(!before.contains(&"diagnosis".to_owned())); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 815 | assert!(!before.contains(&"thread".to_owned())); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 816 | let searched = send(&bedroom, "POST", "/runs/cafebabe/drawer", &[], "").await; |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 817 | assert!(!linked_rels(&searched).contains(&"drawer".to_owned())); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 818 | |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 819 | let (clinic, _) = seeded(Floor::Clinic); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 820 | let rels = linked_rels(&send(&clinic, "GET", "/runs/cafebabe", &[], "").await); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 821 | assert!(rels.contains(&"diagnosis".to_owned()) && rels.contains(&"thread".to_owned())); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 822 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 823 | |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 824 | #[tokio::test] |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 825 | async fn ignoring_mum_has_consequences() { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 826 | let app = seeded_with(Floor::Bedroom, |run| { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 827 | mum_at_the_door(run); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 828 | run.here.turns = 6; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 829 | }); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 830 | let knock = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 831 | assert_eq!( |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 832 | json(knock).await["type"], |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 833 | "https://jelq.dev/problems/someone-at-the-door" |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 834 | ); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 835 | let leave = send(&app, "POST", "/runs/cafebabe/floor", &[], "").await; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 836 | assert_eq!( |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 837 | leave.status(), |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 838 | StatusCode::UNAUTHORIZED, |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 839 | "no leaving with Mum at the door" |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 840 | ); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 841 | send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 842 | let opened = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 843 | assert_eq!(opened.status(), StatusCode::GONE); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 844 | assert_eq!( |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 845 | json(opened).await["type"], |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 846 | "https://jelq.dev/problems/opened" |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 847 | ); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 848 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 849 | |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 850 | #[tokio::test] |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 851 | async fn caged_drawers_are_noisy_and_eventually_give_up_the_key() { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 852 | let app = seeded_with(Floor::ChangingRoom, |run| run.items.cage = true); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 853 | let mut statuses = Vec::new(); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 854 | for _ in 0..12 { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 855 | let response = send(&app, "POST", "/runs/cafebabe/drawer", &[], "").await; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 856 | statuses.push(response.status()); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 857 | if response.status() == StatusCode::OK { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 858 | break; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 859 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 860 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 861 | assert_eq!(statuses.last(), Some(&StatusCode::OK), "{statuses:?}"); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 862 | assert!( |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 863 | statuses[..statuses.len() - 1] |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 864 | .iter() |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 865 | .all(|s| *s == StatusCode::NO_CONTENT) |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 866 | ); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 867 | } |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 868 | |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 869 | #[tokio::test] |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 870 | async fn the_ruler_replaces_the_self_report() { |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 871 | let app = seeded_with(Floor::Bedroom, |_| {}); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 872 | let before = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 873 | assert!(before.headers().contains_key("x-self-reported-length")); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 874 | assert!(!before.headers().contains_key("x-length")); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 875 | |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 876 | let app = seeded_with(Floor::Bedroom, |run| run.items.ruler = true); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 877 | let after = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 878 | assert!(!after.headers().contains_key("x-self-reported-length")); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 879 | assert!(after.headers().contains_key("x-length")); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 880 | } |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 881 | |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 882 | #[tokio::test] |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 883 | async fn an_open_tab_is_linked_and_jelq_still_answers_with_choices() { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 884 | let app = seeded_with(Floor::Bathroom, |run| { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 885 | run.story = Story::Pending; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 886 | run.warmed_up = true; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 887 | }); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 888 | let response = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 889 | let links = header(&response, "link"); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 890 | assert!(links.contains("/branches/forum>; rel=\"https://jelq.dev/rels/branch\"")); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 891 | assert!(links.contains("/branches/close-tab>; rel=\"https://jelq.dev/rels/branch\"")); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 892 | assert!(links.contains("?technique=wet>")); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 893 | let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=edge", &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 894 | assert_eq!(jelq.status(), StatusCode::MULTIPLE_CHOICES); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 895 | } |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 896 | |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 897 | #[tokio::test] |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 898 | async fn either_story_choice_is_reachable_during_cooldown() { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 899 | for choice in ["forum", "close-tab"] { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 900 | let app = seeded_with(Floor::Bathroom, |run| { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 901 | run.turn = 9; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 902 | run.warmed_up = true; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 903 | run.stamina = 1; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 904 | run.items.door_locks = 1; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 905 | }); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 906 | let tenth = send(&app, "JELQ", "/runs/cafebabe?technique=edge", &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 907 | assert_eq!(tenth.status(), StatusCode::OK); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 908 | let response = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 909 | assert!(!header(&response, "link").contains("?technique=")); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 910 | let path = format!("/runs/cafebabe/branches/{choice}"); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 911 | assert!( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 912 | header(&response, "link") |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 913 | .contains(&format!("<{path}>; rel=\"https://jelq.dev/rels/branch\"")) |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 914 | ); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 915 | let chosen = send(&app, "POST", &path, &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 916 | assert_eq!(chosen.status(), StatusCode::SEE_OTHER); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 917 | assert!(!header(&chosen, "link").contains("/branches/")); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 918 | let repeated = send(&app, "POST", &path, &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 919 | assert_eq!(repeated.status(), StatusCode::CONFLICT); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 920 | } |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 921 | } |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 922 | |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 923 | #[tokio::test] |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 924 | async fn a_door_lock_says_when_it_was_used() { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 925 | let app = seeded_with(Floor::Bathroom, |run| { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 926 | run.items.door_locks = 1; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 927 | run.suspicion = SUSPICION_LIMIT; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 928 | run.warmed_up = true; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 929 | }); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 930 | let response = send(&app, "JELQ", "/runs/cafebabe?technique=dry", &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 931 | assert_ne!(response.status(), StatusCode::CONFLICT); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 932 | assert!( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 933 | response |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 934 | .headers() |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 935 | .get_all("warning") |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 936 | .iter() |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 937 | .any(|w| w.to_str().unwrap().contains("your brother tried the door")) |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 938 | ); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 939 | } |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 940 | |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 941 | #[tokio::test] |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 942 | async fn shopping_survives_browsing_but_not_jelqing() { |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 943 | let app = seeded_with(Floor::ChangingRoom, |run| run.cash = 50); |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 944 | send(&app, "GET", "/runs/cafebabe/shop", &[], "").await; |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 945 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 946 | assert!(header(&view, "link").contains("shop-item")); |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 947 | let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await; |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 948 | assert_ne!(jelq.status(), StatusCode::METHOD_NOT_ALLOWED); |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 949 | let after = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 950 | assert!(!header(&after, "link").contains("shop-item")); |
7d3fb63208bf | atagen | 2026-10-11 04:38 UTC | 951 | } |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 952 | |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 953 | #[tokio::test] |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 954 | async fn the_thread_announces_itself_at_the_branch() { |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 955 | let app = seeded_with(Floor::Bathroom, |run| { |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 956 | run.turn = 8; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 957 | run.warmed_up = true; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 958 | run.items.baby_oil = 9; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 959 | }); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 960 | send( |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 961 | &app, |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 962 | "JELQ", |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 963 | "/runs/cafebabe?technique=wet", |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 964 | &[("content-type", "application/baby-oil")], |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 965 | "", |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 966 | ) |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 967 | .await; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 968 | let ninth = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 969 | assert!(!header(&ninth, "link").contains("/forum/threads/2009")); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 970 | let tenth = send( |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 971 | &app, |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 972 | "JELQ", |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 973 | "/runs/cafebabe?technique=wet", |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 974 | &[("content-type", "application/baby-oil")], |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 975 | "", |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 976 | ) |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 977 | .await; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 978 | assert!( |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 979 | tenth |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 980 | .headers() |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 981 | .get_all("warning") |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 982 | .iter() |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 983 | .any(|w| w.to_str().unwrap().contains("a forum thread from 2009")) |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 984 | ); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 985 | assert!(header(&tenth, "link").contains("/forum/threads/2009")); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 986 | let announced = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 987 | assert!(header(&announced, "link").contains("/forum/threads/2009")); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 988 | } |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 989 | |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 990 | #[tokio::test] |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 991 | async fn reading_the_forum_may_teach_meditation() { |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 992 | let taught = (0..50u64) |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 993 | .filter(|seed| { |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 994 | let mut run = Run::new("cafebabe".into(), "cafe".into(), *seed); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 995 | run.story = Story::Pending; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 996 | run.turn = BRANCH_TURN; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 997 | run.choose("forum").is_ok() && run.meditation_taught |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 998 | }) |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 999 | .count(); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1000 | assert!( |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1001 | taught > 0 && taught < 50, |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1002 | "the teach roll should be a coin, it landed {taught}/50" |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1003 | ); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1004 | } |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1005 | |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1006 | #[tokio::test] |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1007 | async fn meditation_is_free_but_only_once_per_floor() { |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1008 | let app = seeded_with(Floor::Bedroom, |run| run.meditation_taught = true); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1009 | let response = send(&app, "JELQ", "/runs/cafebabe?technique=meditate", &[], "").await; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1010 | assert_eq!(response.status(), StatusCode::OK); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1011 | assert_eq!(header(&response, "x-eq"), "10"); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1012 | assert_eq!(header(&response, "x-stamina"), "10/10"); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1013 | let again = send(&app, "JELQ", "/runs/cafebabe?technique=meditate", &[], "").await; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1014 | assert_eq!(again.status(), StatusCode::CONFLICT); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1015 | } |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1016 | |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1017 | #[tokio::test] |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1018 | async fn meditation_stays_hidden_until_the_forum_teaches_it() { |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1019 | let app = seeded_with(Floor::Bedroom, |_| {}); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1020 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1021 | assert!(!header(&view, "link").contains("technique=meditate")); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1022 | let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=meditate", &[], "").await; |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1023 | assert_eq!(jelq.status(), StatusCode::FORBIDDEN); |
0fdc47364c8c | atagen | 2026-10-11 04:45 UTC | 1024 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1025 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1026 | fn app_with(floor: Floor, seed: u64, setup: impl FnOnce(&mut Run)) -> Router { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1027 | let state = Arc::new(AppState::default()); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1028 | let mut run = Run::new("cafebabe".into(), "cafe".into(), seed); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1029 | run.floor = floor; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1030 | setup(&mut run); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1031 | state.insert(run); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1032 | router(state) |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1033 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1034 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1035 | #[tokio::test] |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1036 | async fn hold_is_offered_only_at_the_edges() { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1037 | let calm = seeded_with(Floor::Bedroom, |_| {}); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1038 | let refused = send(&calm, "HOLD", "/runs/cafebabe", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1039 | assert_eq!(refused.status(), StatusCode::METHOD_NOT_ALLOWED); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1040 | assert!(!header(&refused, "allow").contains("HOLD")); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1041 | let view = send(&calm, "GET", "/runs/cafebabe", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1042 | assert!(!header(&view, "link").contains("HOLD")); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1043 | let options = send(&calm, "OPTIONS", "/runs/cafebabe", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1044 | assert!(!header(&options, "allow").contains("HOLD")); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1045 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1046 | let winded = seeded_with(Floor::Bedroom, |run| run.stamina = 2); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1047 | let listed = send(&winded, "GET", "/runs/cafebabe", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1048 | assert!(header(&listed, "link").contains("HOLD")); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1049 | let options = send(&winded, "OPTIONS", "/runs/cafebabe", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1050 | assert!(header(&options, "allow").contains("HOLD")); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1051 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1052 | let hot = seeded_with(Floor::Bedroom, |run| { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1053 | run.eq = 75; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1054 | run.warmed_up = true; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1055 | }); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1056 | let held = send(&hot, "HOLD", "/runs/cafebabe", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1057 | assert_eq!(held.status(), StatusCode::NO_CONTENT); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1058 | assert_eq!(header(&held, "x-stamina"), "10/10"); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1059 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1060 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1061 | #[tokio::test] |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1062 | async fn holding_calms_and_sometimes_reflects() { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1063 | let calmed = (0..60u64) |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1064 | .filter(|seed| { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1065 | let mut run = Run::new("cafebabe".into(), "cafe".into(), *seed); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1066 | run.eq = 75; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1067 | run.hold(Instant::now()).is_ok() && run.eq == 60 |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1068 | }) |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1069 | .count(); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1070 | let reflected = (0..60u64) |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1071 | .filter(|seed| { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1072 | let mut run = Run::new("cafebabe".into(), "cafe".into(), *seed); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1073 | run.eq = 75; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1074 | run.hold(Instant::now()).is_ok() && run.eq == 0 |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1075 | }) |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1076 | .count(); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1077 | assert!( |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1078 | calmed > 40 && reflected > 0 && calmed + reflected == 60, |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1079 | "one HOLD in twelve should reflect, got {calmed} calm and {reflected} reflective of 60" |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1080 | ); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1081 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1082 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1083 | #[tokio::test] |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1084 | async fn leaving_the_band_warms_the_next_floor() { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1085 | let app = seeded_with(Floor::Bedroom, |run| { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1086 | run.eq = 60; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1087 | run.warmed_up = true; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1088 | run.here.turns = 6; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1089 | run.items.baby_oil = 9; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1090 | }); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1091 | let left = send(&app, "POST", "/runs/cafebabe/floor", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1092 | assert_eq!(left.status(), StatusCode::SEE_OTHER); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1093 | let detail = json(left).await["detail"].as_str().unwrap().to_owned(); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1094 | assert!(detail.contains("the warmth came with you")); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1095 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1096 | let lube = [("content-type", "application/baby-oil")]; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1097 | send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1098 | // The shower is a +35 warm-up, so EQ lands in the band and the band bonus rides along. |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1099 | // The arrival bonus is the one point the second jelq loses. |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1100 | let first = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1101 | assert!( |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1102 | header(&first, "server-timing").contains("d20+4"), |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1103 | "the first jelq of a warm arrival rolls with +1, got {}", |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1104 | header(&first, "server-timing") |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1105 | ); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1106 | let second = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1107 | assert!(header(&second, "server-timing").contains("d20+3")); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1108 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1109 | |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1110 | #[tokio::test] |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1111 | async fn greed_multiplies_gains_above_the_band() { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1112 | let lube = [("content-type", "application/baby-oil")]; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1113 | for seed in 0..60u64 { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1114 | let app = app_with(Floor::Bedroom, seed, |run| { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1115 | run.eq = 60; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1116 | run.warmed_up = true; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1117 | }); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1118 | let in_band = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1119 | let app = app_with(Floor::Bedroom, seed, |run| { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1120 | run.eq = 75; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1121 | run.warmed_up = true; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1122 | }); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1123 | let greedy = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1124 | if in_band.status() != StatusCode::OK || greedy.status() != StatusCode::OK { |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1125 | continue; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1126 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1127 | let steady = json(in_band).await["length"].as_f64().unwrap(); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1128 | let eager = json(greedy).await["length"].as_f64().unwrap(); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1129 | assert!( |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1130 | (eager - steady * 1.5).abs() < 1e-9, |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1131 | "seed {seed} gained {eager} above the band against {steady} inside it" |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1132 | ); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1133 | return; |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1134 | } |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1135 | panic!("no seed in 60 produced two clean rolls to compare"); |
4347977b8192 | atagen | 2026-10-11 04:56 UTC | 1136 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1137 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1138 | #[tokio::test] |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1139 | async fn the_kitchen_is_only_on_the_home_floors() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1140 | let absent = seeded_with(Floor::Bathroom, |_| {}); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1141 | let no_kitchen = send(&absent, "POST", "/runs/cafebabe/kitchen", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1142 | assert_eq!(no_kitchen.status(), StatusCode::NOT_FOUND); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1143 | let view = send(&absent, "GET", "/runs/cafebabe", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1144 | assert!(!header(&view, "link").contains("/kitchen")); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1145 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1146 | let app = seeded_with(Floor::Bedroom, |_| {}); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1147 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1148 | assert!(header(&view, "link").contains("/kitchen")); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1149 | let raid = send(&app, "POST", "/runs/cafebabe/kitchen", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1150 | assert_ne!(raid.status(), StatusCode::NOT_FOUND); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1151 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1152 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1153 | #[tokio::test] |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1154 | async fn raids_cost_the_turn_and_the_fridge_pays_out_sometimes() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1155 | let mut bounties = std::collections::BTreeSet::new(); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1156 | let mut told = 0; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1157 | for seed in 0..80u64 { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1158 | let mut run = Run::new("cafebabe".into(), "cafe".into(), seed); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1159 | let Ok(outcome) = run.raid_kitchen() else { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1160 | panic!("the first raid should never fail"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1161 | }; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1162 | assert_eq!(run.turn, 1, "a raid costs the floor turn"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1163 | assert!(!run.here.melon_offered, "no melon at starting EQ"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1164 | if outcome.status == StatusCode::NO_CONTENT { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1165 | bounties.insert("empty"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1166 | } else { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1167 | bounties.insert("loot"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1168 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1169 | told += u32::from(run.kitchen_tellings); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1170 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1171 | assert!(bounties.contains("loot") && bounties.contains("empty")); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1172 | assert!( |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1173 | (0..80).any(|seed| { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1174 | let mut run = Run::new("cafebabe".into(), "cafe".into(), seed); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1175 | run.raid_kitchen().is_ok() && run.kitchen_tellings == 0 |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1176 | }), |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1177 | "most raids go unremarked" |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1178 | ); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1179 | assert!(told > 0, "someone should have been told across 80 raids"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1180 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1181 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1182 | #[tokio::test] |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1183 | async fn the_watermelon_offers_itself_above_ninety() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1184 | let mut offered = 0; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1185 | let mut caught = 0; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1186 | let mut survived = 0; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1187 | for seed in 0..120u64 { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1188 | let mut run = Run::new("cafebabe".into(), "cafe".into(), seed); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1189 | run.eq = 95; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1190 | let Ok(outcome) = run.raid_kitchen() else { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1191 | continue; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1192 | }; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1193 | if outcome.status != StatusCode::MULTIPLE_CHOICES { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1194 | continue; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1195 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1196 | offered += 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1197 | let gains = run.length; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1198 | let disgrace = run.shame; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1199 | if run.commit_melon().is_err() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1200 | caught += 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1201 | assert_eq!(run.ended.as_ref().unwrap().cause.slug(), "watermelon"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1202 | } else { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1203 | survived += 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1204 | assert_eq!(run.eq, 0); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1205 | assert_eq!(run.shame, disgrace + 5); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1206 | assert_eq!(run.length, gains, "the gains are kept"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1207 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1208 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1209 | assert!( |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1210 | offered > 20, |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1211 | "the melon should appear in two fifths of raids" |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1212 | ); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1213 | assert!(caught > 0 && survived > 0, "caught is one in three"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1214 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1215 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1216 | #[tokio::test] |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1217 | async fn the_kitchen_closes_after_two_tellings() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1218 | let mut closed = None; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1219 | for seed in 0..300u64 { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1220 | let mut run = Run::new("cafebabe".into(), "cafe".into(), seed); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1221 | let first = run.raid_kitchen(); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1222 | let second = run.raid_kitchen(); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1223 | if second.is_err() && first.is_ok() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1224 | assert_eq!(run.kitchen_tellings, 2); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1225 | let Err(third) = run.raid_kitchen() else { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1226 | panic!("the kitchen should be gone"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1227 | }; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1228 | assert_eq!(third.status(), StatusCode::GONE); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1229 | closed = Some(seed); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1230 | break; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1231 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1232 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1233 | assert!( |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1234 | closed.is_some(), |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1235 | "two tellings should occur within 300 seeds" |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1236 | ); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1237 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1238 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1239 | #[tokio::test] |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1240 | async fn lubes_run_out_but_spit_never_does() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1241 | let app = seeded_with(Floor::Bedroom, |run| { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1242 | run.warmed_up = true; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1243 | run.items.baby_oil = 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1244 | }); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1245 | let lube = [("content-type", "application/baby-oil")]; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1246 | let first = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1247 | assert_ne!(first.status(), StatusCode::PRECONDITION_FAILED); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1248 | let second = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1249 | assert_eq!(second.status(), StatusCode::PRECONDITION_FAILED); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1250 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1251 | let spit = [("content-type", "text/plain; charset=spit")]; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1252 | for _ in 0..3 { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1253 | let wet = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &spit, "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1254 | assert_ne!(wet.status(), StatusCode::PRECONDITION_FAILED); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1255 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1256 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1257 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1258 | #[tokio::test] |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1259 | async fn energy_drinks_add_three_stamina() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1260 | let app = seeded_with(Floor::Bedroom, |run| { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1261 | run.stamina = 2; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1262 | run.items.energy_drinks = 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1263 | }); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1264 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1265 | assert!(header(&view, "link").contains("technique=energy")); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1266 | let drink = send(&app, "JELQ", "/runs/cafebabe?technique=energy", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1267 | assert_eq!(drink.status(), StatusCode::OK); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1268 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1269 | assert_eq!(header(&view, "x-stamina"), "5/10"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1270 | let again = send(&app, "JELQ", "/runs/cafebabe?technique=energy", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1271 | assert_eq!(again.status(), StatusCode::FAILED_DEPENDENCY); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1272 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1273 | |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1274 | #[tokio::test] |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1275 | async fn the_working_supplement_resets_stamina() { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1276 | let mut worked = 0; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1277 | let mut bunk = 0; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1278 | for seed in 0..60u64 { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1279 | let app = app_with(Floor::Bedroom, seed, |run| { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1280 | run.stamina = 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1281 | run.items.supplements = 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1282 | }); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1283 | let taken = send(&app, "JELQ", "/runs/cafebabe?technique=supplement", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1284 | if taken.status() == StatusCode::OK { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1285 | worked += 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1286 | let view = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1287 | assert_eq!(header(&view, "x-stamina"), "10/10"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1288 | } else { |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1289 | assert_eq!(taken.status(), StatusCode::BAD_GATEWAY); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1290 | bunk += 1; |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1291 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1292 | } |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1293 | assert!(worked > 0 && bunk > 0, "one in five should work too well"); |
0a0bfee8329e | atagen | 2026-10-11 05:11 UTC | 1294 | } |