an http based roguelike rpg about jelqing
| 1 | use super::*; |
| 2 | |
| 3 | #[tokio::test] |
| 4 | async fn only_the_key_opens_the_cage() { |
| 5 | let app = seeded_with(Floor::ChangingRoom, |run| run.items.kit.cage = true); |
| 6 | send(&app, "POST", "/runs/cafebabe/shop/ice-pack", &[], "").await; |
| 7 | let still = send( |
| 8 | &app, |
| 9 | "GET", |
| 10 | "/runs/cafebabe/inventory/chastity-cage", |
| 11 | &[], |
| 12 | "", |
| 13 | ) |
| 14 | .await; |
| 15 | assert_eq!(still.status(), StatusCode::OK); |
| 16 | send(&app, "POST", "/runs/cafebabe/shop/cage-key", &[], "").await; |
| 17 | let gone = send( |
| 18 | &app, |
| 19 | "GET", |
| 20 | "/runs/cafebabe/inventory/chastity-cage", |
| 21 | &[], |
| 22 | "", |
| 23 | ) |
| 24 | .await; |
| 25 | assert_eq!(gone.status(), StatusCode::NOT_FOUND); |
| 26 | } |
| 27 | |
| 28 | #[tokio::test] |
| 29 | async fn pump_bro_upsells() { |
| 30 | let closed = seeded_with(Floor::Bedroom, |_| {}); |
| 31 | let response = send(&closed, "GET", "/runs/cafebabe/shop", &[], "").await; |
| 32 | assert_eq!(response.status(), StatusCode::NOT_FOUND); |
| 33 | |
| 34 | let app = seeded_with(Floor::ChangingRoom, |_| {}); |
| 35 | let pump = send(&app, "POST", "/runs/cafebabe/shop/pump", &[], "").await; |
| 36 | assert_eq!(pump.status(), StatusCode::UPGRADE_REQUIRED); |
| 37 | assert_eq!(header(&pump, "upgrade"), "pump-pro/2.0"); |
| 38 | let pro = send(&app, "POST", "/runs/cafebabe/shop/pump-pro", &[], "").await; |
| 39 | assert_eq!(pro.status(), StatusCode::CREATED); |
| 40 | let broke = send(&app, "POST", "/runs/cafebabe/shop/extender", &[], "").await; |
| 41 | assert_eq!(broke.status(), StatusCode::PAYMENT_REQUIRED); |
| 42 | } |
| 43 | |
| 44 | #[tokio::test] |
| 45 | async fn the_elder_is_stale() { |
| 46 | let app = seeded_with(Floor::Forum, |run| run.body.length = 5.0); |
| 47 | let unverified = send(&app, "GET", "/runs/cafebabe/elder", &[], "").await; |
| 48 | assert_eq!( |
| 49 | unverified.status(), |
| 50 | StatusCode::PROXY_AUTHENTICATION_REQUIRED |
| 51 | ); |
| 52 | let lie = send( |
| 53 | &app, |
| 54 | "GET", |
| 55 | "/runs/cafebabe/elder", |
| 56 | &[("proxy-authorization", "Ruler 9")], |
| 57 | "", |
| 58 | ) |
| 59 | .await; |
| 60 | assert_eq!(lie.status(), StatusCode::BAD_REQUEST); |
| 61 | let csv = send( |
| 62 | &app, |
| 63 | "GET", |
| 64 | "/runs/cafebabe/elder", |
| 65 | &[("proxy-authorization", "Ruler 5.0")], |
| 66 | "", |
| 67 | ) |
| 68 | .await; |
| 69 | assert_eq!(csv.status(), StatusCode::OK); |
| 70 | let stale = send( |
| 71 | &app, |
| 72 | "GET", |
| 73 | "/runs/cafebabe/elder", |
| 74 | &[("if-modified-since", "Mon, 15 Jun 2009 00:00:00 GMT")], |
| 75 | "", |
| 76 | ) |
| 77 | .await; |
| 78 | assert_eq!(stale.status(), StatusCode::NOT_MODIFIED); |
| 79 | } |
| 80 | |
| 81 | #[tokio::test] |
| 82 | async fn the_hotel_has_a_captive_portal() { |
| 83 | let app = seeded_with(Floor::Hotel, |_| {}); |
| 84 | let blocked = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
| 85 | assert_eq!( |
| 86 | blocked.status(), |
| 87 | StatusCode::NETWORK_AUTHENTICATION_REQUIRED |
| 88 | ); |
| 89 | let accepted = send(&app, "POST", "/runs/cafebabe/portal", &[], "").await; |
| 90 | assert_eq!(accepted.status(), StatusCode::SEE_OTHER); |
| 91 | let online = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
| 92 | assert_eq!(online.status(), StatusCode::OK); |
| 93 | } |
| 94 | |
| 95 | #[tokio::test] |
| 96 | async fn caged_drawers_are_noisy_and_eventually_give_up_the_key() { |
| 97 | let app = seeded_with(Floor::ChangingRoom, |run| run.items.kit.cage = true); |
| 98 | let mut statuses = Vec::new(); |
| 99 | for _ in 0..30 { |
| 100 | let response = send(&app, "POST", "/runs/cafebabe/drawer", &[], "").await; |
| 101 | statuses.push(response.status()); |
| 102 | if response.status() == StatusCode::OK { |
| 103 | break; |
| 104 | } |
| 105 | } |
| 106 | assert_eq!(statuses.last(), Some(&StatusCode::OK), "{statuses:?}"); |
| 107 | assert!( |
| 108 | statuses[..statuses.len() - 1] |
| 109 | .iter() |
| 110 | .all(|s| *s == StatusCode::NO_CONTENT) |
| 111 | ); |
| 112 | } |
| 113 | |
| 114 | #[tokio::test] |
| 115 | async fn an_open_tab_is_linked_and_jelq_still_answers_with_choices() { |
| 116 | let app = seeded_with(Floor::Bathroom, |run| { |
| 117 | run.online.story = Story::Pending; |
| 118 | run.body.warmed_up = true; |
| 119 | }); |
| 120 | let response = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
| 121 | let links = header(&response, "link"); |
| 122 | assert!(links.contains("/branches/forum>; rel=\"https://jelq.dev/rels/branch\"")); |
| 123 | assert!(links.contains("/branches/close-tab>; rel=\"https://jelq.dev/rels/branch\"")); |
| 124 | assert!(links.contains("?technique=wet>")); |
| 125 | let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=edge", &[], "").await; |
| 126 | assert_eq!(jelq.status(), StatusCode::MULTIPLE_CHOICES); |
| 127 | } |
| 128 | |
| 129 | #[tokio::test] |
| 130 | async fn either_story_choice_is_reachable_during_cooldown() { |
| 131 | for choice in ["forum", "close-tab"] { |
| 132 | let app = seeded_with(Floor::Bathroom, |run| { |
| 133 | run.turn = 9; |
| 134 | run.body.warmed_up = true; |
| 135 | run.body.eq = 45; |
| 136 | run.body.stamina = 1; |
| 137 | run.items.stores.door_locks = 1; |
| 138 | }); |
| 139 | let tenth = send(&app, "JELQ", "/runs/cafebabe?technique=edge", &[], "").await; |
| 140 | assert_eq!(tenth.status(), StatusCode::OK); |
| 141 | let response = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
| 142 | assert!(!header(&response, "link").contains("?technique=")); |
| 143 | let path = format!("/runs/cafebabe/branches/{choice}"); |
| 144 | assert!( |
| 145 | header(&response, "link") |
| 146 | .contains(&format!("<{path}>; rel=\"https://jelq.dev/rels/branch\"")) |
| 147 | ); |
| 148 | let chosen = send(&app, "POST", &path, &[], "").await; |
| 149 | assert_eq!(chosen.status(), StatusCode::SEE_OTHER); |
| 150 | assert!(!header(&chosen, "link").contains("/branches/")); |
| 151 | let repeated = send(&app, "POST", &path, &[], "").await; |
| 152 | assert_eq!(repeated.status(), StatusCode::CONFLICT); |
| 153 | } |
| 154 | } |
| 155 | |
| 156 | #[tokio::test] |
| 157 | async fn the_thread_announces_itself_at_the_branch() { |
| 158 | let app = seeded_with(Floor::Bathroom, |run| { |
| 159 | run.turn = 8; |
| 160 | run.body.warmed_up = true; |
| 161 | run.items.lubes.baby_oil = 9; |
| 162 | }); |
| 163 | send( |
| 164 | &app, |
| 165 | "JELQ", |
| 166 | "/runs/cafebabe?technique=wet", |
| 167 | &[("content-type", "application/baby-oil")], |
| 168 | "", |
| 169 | ) |
| 170 | .await; |
| 171 | let ninth = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
| 172 | assert!(!header(&ninth, "link").contains("/forum/threads/2009")); |
| 173 | let tenth = send( |
| 174 | &app, |
| 175 | "JELQ", |
| 176 | "/runs/cafebabe?technique=wet", |
| 177 | &[("content-type", "application/baby-oil")], |
| 178 | "", |
| 179 | ) |
| 180 | .await; |
| 181 | assert!( |
| 182 | tenth |
| 183 | .headers() |
| 184 | .get_all("warning") |
| 185 | .iter() |
| 186 | .any(|w| w.to_str().unwrap().contains("a forum thread from 2009")) |
| 187 | ); |
| 188 | assert!(header(&tenth, "link").contains("/forum/threads/2009")); |
| 189 | let announced = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
| 190 | assert!(header(&announced, "link").contains("/forum/threads/2009")); |
| 191 | } |
| 192 | |
| 193 | #[tokio::test] |
| 194 | async fn rereading_the_thread_teaches_uli() { |
| 195 | let mut taught_runs = 0; |
| 196 | for seed in 0..100u64 { |
| 197 | let app = app_with(Floor::Bedroom, seed, |run| { |
| 198 | run.turn = BRANCH_TURN; |
| 199 | run.body.warmed_up = true; |
| 200 | run.online.story = Story::ClosedTab; |
| 201 | }); |
| 202 | let mut taught = false; |
| 203 | for _ in 0..2 { |
| 204 | let read = send(&app, "POST", "/runs/cafebabe/re-read", &[], "").await; |
| 205 | match read.status() { |
| 206 | StatusCode::NOT_MODIFIED => { |
| 207 | assert!(header(&read, "warning").contains("2009")); |
| 208 | } |
| 209 | StatusCode::OK => { |
| 210 | assert!(header(&read, "location").contains("/techniques")); |
| 211 | taught = true; |
| 212 | break; |
| 213 | } |
| 214 | other => panic!("seed {seed} read the thread into {other}"), |
| 215 | } |
| 216 | } |
| 217 | let state = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
| 218 | assert_eq!(header(&state, "x-stamina"), "10/10", "reading is free"); |
| 219 | if taught { |
| 220 | taught_runs += 1; |
| 221 | let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=uli", &[], "").await; |
| 222 | assert_ne!(jelq.status(), StatusCode::FORBIDDEN); |
| 223 | } else { |
| 224 | let cached = send(&app, "POST", "/runs/cafebabe/re-read", &[], "").await; |
| 225 | assert_eq!(cached.status(), StatusCode::OK); |
| 226 | assert!(header(&cached, "warning").starts_with("112")); |
| 227 | assert!(header(&cached, "age").parse::<u64>().unwrap() > 0); |
| 228 | } |
| 229 | } |
| 230 | assert!( |
| 231 | (30..=58).contains(&taught_runs), |
| 232 | "{taught_runs}/100 learned uli in two reads" |
| 233 | ); |
| 234 | } |
| 235 | |
| 236 | #[tokio::test] |
| 237 | async fn the_thread_cannot_be_reread_before_anyone_mentions_it() { |
| 238 | let app = seeded_with(Floor::Bedroom, |run| run.body.warmed_up = true); |
| 239 | let read = send(&app, "POST", "/runs/cafebabe/re-read", &[], "").await; |
| 240 | assert_eq!(read.status(), StatusCode::NOT_FOUND); |
| 241 | let after = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
| 242 | assert!(!header(&after, "link").contains("/re-read")); |
| 243 | } |
| 244 | |
| 245 | #[tokio::test] |
| 246 | async fn rummaging_for_the_key_leaves_the_drawer_unsearched() { |
| 247 | let mut found = 0; |
| 248 | for seed in 0..20u64 { |
| 249 | let app = app_with(Floor::Hotel, seed, |run| { |
| 250 | run.here.wifi_accepted = true; |
| 251 | run.items.kit.cage = true; |
| 252 | }); |
| 253 | for _ in 0..30 { |
| 254 | let rummage = send(&app, "POST", "/runs/cafebabe/drawer", &[], "").await; |
| 255 | if rummage.status() == StatusCode::OK { |
| 256 | break; |
| 257 | } |
| 258 | } |
| 259 | let search = send(&app, "POST", "/runs/cafebabe/drawer", &[], "").await; |
| 260 | if search.status() == StatusCode::FOUND { |
| 261 | assert!(header(&search, "location").ends_with("/inventory/do-not-disturb-sign")); |
| 262 | found += 1; |
| 263 | } |
| 264 | } |
| 265 | assert!( |
| 266 | found >= 18, |
| 267 | "only {found} of 20 hotel drawers survived the rummage" |
| 268 | ); |
| 269 | } |
| 270 | |
| 271 | #[tokio::test] |
| 272 | async fn kev_is_the_bar_in_the_changing_room() { |
| 273 | for (length, shamed) in [(5.0, true), (7.0, false)] { |
| 274 | let app = seeded_with(Floor::Bathroom, |run| { |
| 275 | run.body.length = length; |
| 276 | run.here.turns = 6; |
| 277 | }); |
| 278 | let left = send(&app, "POST", "/runs/cafebabe/floor", &[], "").await; |
| 279 | assert_eq!(header(&left, "x-floor"), "3"); |
| 280 | let warning = left |
| 281 | .headers() |
| 282 | .get("warning") |
| 283 | .map(|w| w.to_str().unwrap().to_owned()); |
| 284 | assert_eq!( |
| 285 | warning.is_some_and(|w| w.contains("Kev")), |
| 286 | shamed, |
| 287 | "length {length}" |
| 288 | ); |
| 289 | } |
| 290 | } |
| 291 | |
| 292 | #[tokio::test] |
| 293 | async fn pump_bro_charges_the_thin_more_for_girth() { |
| 294 | for (girth, ring, oil) in [(4.5, 11, 4), (5.2, 8, 4)] { |
| 295 | let app = seeded_with(Floor::ChangingRoom, |run| run.body.girth = girth); |
| 296 | let shop = json(send(&app, "GET", "/runs/cafebabe/shop", &[], "").await).await; |
| 297 | let price = |slug: &str| { |
| 298 | shop["stock"] |
| 299 | .as_array() |
| 300 | .unwrap() |
| 301 | .iter() |
| 302 | .find(|item| item["item"] == slug) |
| 303 | .unwrap()["price"] |
| 304 | .as_u64() |
| 305 | .unwrap() |
| 306 | }; |
| 307 | assert_eq!(price("cock-ring"), ring, "girth {girth}"); |
| 308 | assert_eq!(price("baby-oil"), oil, "girth {girth}"); |
| 309 | } |
| 310 | } |
| 311 | |
| 312 | #[tokio::test] |
| 313 | async fn the_clinic_escalates_toward_honesty() { |
| 314 | let Harness { app, .. } = harness(Floor::Clinic, SEED, |_| {}); |
| 315 | let mut hints = Vec::new(); |
| 316 | for _ in 0..3 { |
| 317 | let response = send( |
| 318 | &app, |
| 319 | "GET", |
| 320 | "/runs/cafebabe/diagnosis", |
| 321 | &[("authorization", "Excuse \"changing\"")], |
| 322 | "", |
| 323 | ) |
| 324 | .await; |
| 325 | assert_eq!(response.status(), StatusCode::UNAUTHORIZED); |
| 326 | hints.push(header(&response, "www-authenticate").to_owned()); |
| 327 | } |
| 328 | assert!(hints[2].contains("Be honest.")); |
| 329 | } |
| 330 | |
| 331 | #[tokio::test] |
| 332 | async fn the_true_ending_is_not_modified() { |
| 333 | let Harness { app: early, .. } = harness(Floor::Bedroom, SEED, |_| {}); |
| 334 | let response = send(&early, "GET", "/runs/cafebabe/diagnosis", &[], "").await; |
| 335 | assert_eq!(response.status(), StatusCode::TOO_EARLY); |
| 336 | |
| 337 | let Harness { |
| 338 | app, origin: etag, .. |
| 339 | } = harness(Floor::Clinic, SEED, |_| {}); |
| 340 | assert!( |
| 341 | !etag.contains("cafebabe"), |
| 342 | "the origin ETag must not be derivable from the id" |
| 343 | ); |
| 344 | let response = send( |
| 345 | &app, |
| 346 | "GET", |
| 347 | "/runs/cafebabe/diagnosis", |
| 348 | &[ |
| 349 | ("authorization", "Bearer honesty"), |
| 350 | ("if-none-match", &etag), |
| 351 | ], |
| 352 | "", |
| 353 | ) |
| 354 | .await; |
| 355 | assert_eq!(response.status(), StatusCode::NOT_MODIFIED); |
| 356 | assert_eq!(header(&response, "x-diagnosis"), "normal"); |
| 357 | } |
| 358 | |
| 359 | #[tokio::test] |
| 360 | async fn the_elder_bans_three_lies_unless_the_girth_impresses() { |
| 361 | let forum = |girth: f64| { |
| 362 | seeded_with(Floor::Forum, move |run| { |
| 363 | run.body.length = 6.0; |
| 364 | run.body.girth = girth; |
| 365 | }) |
| 366 | }; |
| 367 | let fib = [("proxy-authorization", "Ruler 6.5")]; |
| 368 | let thin = forum(4.5); |
| 369 | for _ in 0..2 { |
| 370 | let strike = send(&thin, "GET", "/runs/cafebabe/elder", &fib, "").await; |
| 371 | assert_eq!(strike.status(), StatusCode::PROXY_AUTHENTICATION_REQUIRED); |
| 372 | } |
| 373 | let banned = send(&thin, "GET", "/runs/cafebabe/elder", &fib, "").await; |
| 374 | assert_eq!(banned.status(), StatusCode::FORBIDDEN); |
| 375 | assert!( |
| 376 | json(banned).await["type"] |
| 377 | .as_str() |
| 378 | .unwrap() |
| 379 | .ends_with("banned") |
| 380 | ); |
| 381 | |
| 382 | let thick = forum(5.2); |
| 383 | for _ in 0..4 { |
| 384 | let excused = send(&thick, "GET", "/runs/cafebabe/elder", &fib, "").await; |
| 385 | assert_eq!(excused.status(), StatusCode::PROXY_AUTHENTICATION_REQUIRED); |
| 386 | assert!(header(&excused, "x-forum-note").contains("Girth is also a dimension")); |
| 387 | } |
| 388 | } |
| 389 | |
| 390 | #[tokio::test] |
| 391 | async fn the_zip_ends_one_exit_in_two_hundred() { |
| 392 | let mut zipped = 0; |
| 393 | for seed in 0..4000u64 { |
| 394 | let mut run = Run::new("cafebabe".into(), "cafe".into(), seed); |
| 395 | run.here.turns = 6; |
| 396 | if run.advance().is_err() && run.ended.is_some() { |
| 397 | zipped += 1; |
| 398 | } |
| 399 | } |
| 400 | assert!( |
| 401 | (8..=35).contains(&zipped), |
| 402 | "{zipped} zips in 4000 exits, about 20 expected" |
| 403 | ); |
| 404 | } |
| 405 | |
| 406 | #[tokio::test] |
| 407 | async fn a_prescription_ends_the_run_and_the_true_ending_still_waits() { |
| 408 | let Harness { app, origin, .. } = harness(Floor::Clinic, SEED, |_| {}); |
| 409 | let honest = [("authorization", "Bearer honesty")]; |
| 410 | let prescribed = send(&app, "GET", "/runs/cafebabe/diagnosis", &honest, "").await; |
| 411 | assert_eq!(prescribed.status(), StatusCode::OK); |
| 412 | assert!(header(&prescribed, "server-timing").contains("volume;")); |
| 413 | assert!( |
| 414 | json(prescribed).await["detail"] |
| 415 | .as_str() |
| 416 | .unwrap() |
| 417 | .starts_with("Congratulations") |
| 418 | ); |
| 419 | let board = json(send(&app, "GET", "/leaderboard?seeded=include", &[], "").await).await; |
| 420 | assert_eq!(board["entries"][0]["status"], "prescribed"); |
| 421 | |
| 422 | let conditional = [ |
| 423 | ("authorization", "Bearer honesty"), |
| 424 | ("if-none-match", origin.as_str()), |
| 425 | ]; |
| 426 | let cured = send(&app, "GET", "/runs/cafebabe/diagnosis", &conditional, "").await; |
| 427 | assert_eq!(cured.status(), StatusCode::NOT_MODIFIED); |
| 428 | let view = json(send(&app, "GET", "/runs/cafebabe", &[], "").await).await; |
| 429 | assert_eq!(view["status"], "normal"); |
| 430 | } |
| 431 | |
| 432 | #[tokio::test] |
| 433 | async fn the_foreskin_window_has_hard_edges() { |
| 434 | for (foreskin, refused) in [ |
| 435 | (0.79, Some(StatusCode::LENGTH_REQUIRED)), |
| 436 | (0.8, None), |
| 437 | (2.0, None), |
| 438 | (2.01, Some(StatusCode::PAYLOAD_TOO_LARGE)), |
| 439 | ] { |
| 440 | let app = seeded_with(Floor::Hotel, |run| { |
| 441 | run.here.wifi_accepted = true; |
| 442 | run.body.warmed_up = true; |
| 443 | run.body.eq = 55; |
| 444 | run.body.foreskin = Some(foreskin); |
| 445 | }); |
| 446 | let dry = send(&app, "JELQ", "/runs/cafebabe?technique=dry", &[], "").await; |
| 447 | match refused { |
| 448 | Some(status) => assert_eq!(dry.status(), status, "foreskin {foreskin}"), |
| 449 | None => assert!( |
| 450 | ![StatusCode::LENGTH_REQUIRED, StatusCode::PAYLOAD_TOO_LARGE] |
| 451 | .contains(&dry.status()), |
| 452 | "foreskin {foreskin} sits inside the window" |
| 453 | ), |
| 454 | } |
| 455 | } |
| 456 | } |