an http based roguelike rpg about jelqing
Blame: src/tests.rs
782069860236 | atagen | 2026-10-10 12:44 UTC | 1 | use std::{sync::Arc, time::Duration}; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 2 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 3 | use axum::{ |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 4 | Router, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 5 | body::{Body, to_bytes}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 6 | http::{Method, Request, StatusCode, Version, header}, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 7 | response::Response, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 8 | }; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 9 | use serde_json::Value; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 10 | use tower::ServiceExt; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 11 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 12 | use crate::{ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 13 | AppState, Config, |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 14 | game::{Floor, MumVisit, Run, Story, balance::SUSPICION_LIMIT}, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 15 | router, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 16 | }; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 17 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 18 | async fn send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 19 | app: &Router, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 20 | method: &str, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 21 | uri: &str, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 22 | headers: &[(&str, &str)], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 23 | body: &str, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 24 | ) -> Response { |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 25 | let mut request = Request::builder() |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 26 | .method(Method::from_bytes(method.as_bytes()).unwrap()) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 27 | .uri(uri); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 28 | for (name, value) in headers { |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 29 | request = request.header(*name, *value); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 30 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 31 | app.clone() |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 32 | .oneshot(request.body(Body::from(body.to_owned())).unwrap()) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 33 | .await |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 34 | .unwrap() |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 35 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 36 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 37 | async fn json(response: Response) -> Value { |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 38 | serde_json::from_slice(&to_bytes(response.into_body(), usize::MAX).await.unwrap()).unwrap() |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 39 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 40 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 41 | async fn text(response: Response) -> String { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 42 | String::from_utf8( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 43 | to_bytes(response.into_body(), usize::MAX) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 44 | .await |
782069860236 | atagen | 2026-10-10 12:44 UTC | 45 | .unwrap() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 46 | .to_vec(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 47 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 48 | .unwrap() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 49 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 50 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 51 | fn header<'a>(response: &'a Response, name: &str) -> &'a str { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 52 | response.headers()[name].to_str().unwrap() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 53 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 54 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 55 | fn fixture() -> Run { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 56 | Run::new("cafebabe".into(), "cafe".into(), 69) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 57 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 58 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 59 | fn seeded_with(floor: Floor, setup: impl FnOnce(&mut Run)) -> Router { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 60 | let state = Arc::new(AppState::default()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 61 | let mut run = fixture(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 62 | run.floor = floor; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 63 | setup(&mut run); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 64 | state.insert(run); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 65 | router(state) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 66 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 67 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 68 | fn seeded(floor: Floor) -> (Router, String) { |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 69 | let state = Arc::new(AppState::default()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 70 | let mut run = fixture(); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 71 | run.floor = floor; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 72 | let etag = run.origin_etag(); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 73 | state.insert(run); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 74 | (router(state), etag) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 75 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 76 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 77 | fn app() -> Router { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 78 | crate::app(Config::default()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 79 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 80 | |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 81 | fn mum_at_the_door(run: &mut Run) { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 82 | run.mum = Some(MumVisit { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 83 | errand: "She heard a noise.", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 84 | nonce: "abc".into(), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 85 | strikes: 0, |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 86 | knocked: false, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 87 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 88 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 89 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 90 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 91 | async fn creating_a_run_returns_location_and_etag() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 92 | let response = send(&app(), "POST", "/runs?seed=1", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 93 | assert_eq!(response.status(), StatusCode::CREATED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 94 | assert!(header(&response, "location").starts_with("/runs/")); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 95 | assert!(response.headers().contains_key(header::ETAG)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 96 | assert_eq!(header(&response, "server"), "jelqd/0.6.9"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 97 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 98 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 99 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 100 | async fn bodies_do_not_repeat_the_headers() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 101 | let (app, _) = seeded(Floor::Bedroom); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 102 | let response = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 103 | assert!(response.headers().contains_key("x-eq")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 104 | let body = json(response).await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 105 | for stat in [ |
782069860236 | atagen | 2026-10-10 12:44 UTC | 106 | "eq", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 107 | "girth", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 108 | "foreskin", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 109 | "stamina", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 110 | "cash", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 111 | "self_reported_length", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 112 | ] { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 113 | assert!(body.get(stat).is_none(), "{stat} is already a header"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 114 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 115 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 116 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 117 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 118 | async fn jelqing_cold_fails_the_precondition() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 119 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 120 | let response = send(&app, "JELQ", "/runs/cafebabe?technique=stretch", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 121 | assert_eq!(response.status(), StatusCode::PRECONDITION_FAILED); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 122 | assert_eq!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 123 | header(&response, "content-type"), |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 124 | "application/problem+json" |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 125 | ); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 126 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 127 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 128 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 129 | async fn wet_without_lube_is_unsupported_media() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 130 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 131 | send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 132 | let response = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 133 | assert_eq!(response.status(), StatusCode::UNSUPPORTED_MEDIA_TYPE); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 134 | let images = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 135 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 136 | "JELQ", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 137 | "/runs/cafebabe?technique=wet", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 138 | &[("content-type", "image/jpeg")], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 139 | "", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 140 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 141 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 142 | assert_eq!(json(images).await["detail"], "No."); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 143 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 144 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 145 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 146 | async fn unknown_methods_are_not_implemented() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 147 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 148 | let response = send(&app, "MILK", "/runs/cafebabe", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 149 | assert_eq!(response.status(), StatusCode::NOT_IMPLEMENTED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 150 | let teapot = send(&app, "BREW", "/runs/cafebabe", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 151 | assert_eq!(teapot.status(), StatusCode::IM_A_TEAPOT); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 152 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 153 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 154 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 155 | async fn the_clinic_does_not_advertise_jelq() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 156 | let (app, _) = seeded(Floor::Clinic); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 157 | let options = send(&app, "OPTIONS", "/runs/cafebabe", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 158 | assert!(!header(&options, "allow").contains("JELQ")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 159 | let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 160 | assert_eq!(jelq.status(), StatusCode::METHOD_NOT_ALLOWED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 161 | assert!(!header(&jelq, "allow").contains("JELQ")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 162 | let (bedroom, _) = seeded(Floor::Bedroom); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 163 | let options = send(&bedroom, "OPTIONS", "/runs/cafebabe", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 164 | assert!(header(&options, "allow").contains("JELQ")); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 165 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 166 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 167 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 168 | async fn patch_only_accepts_the_truth() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 169 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 170 | let patch = [("content-type", "application/json-patch+json")]; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 171 | let replace = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 172 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 173 | "PATCH", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 174 | "/runs/cafebabe", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 175 | &patch, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 176 | r#"[{"op":"replace","path":"/length","value":12}]"#, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 177 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 178 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 179 | assert_eq!(replace.status(), StatusCode::UNPROCESSABLE_ENTITY); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 180 | let lie = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 181 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 182 | "PATCH", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 183 | "/runs/cafebabe", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 184 | &patch, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 185 | r#"[{"op":"test","path":"/length","value":40}]"#, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 186 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 187 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 188 | assert_eq!( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 189 | json(lie).await["type"], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 190 | "https://jelq.dev/problems/exaggeration" |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 191 | ); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 192 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 193 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 194 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 195 | async fn deleting_the_foreskin_requires_certainty() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 196 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 197 | let response = send(&app, "DELETE", "/runs/cafebabe/foreskin", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 198 | assert_eq!(response.status(), StatusCode::PRECONDITION_REQUIRED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 199 | let look = send(&app, "GET", "/runs/cafebabe/foreskin", &[], "").await; |
ec6fd4bb5b60 | atagen | 2026-10-11 04:34 UTC | 200 | assert_eq!(look.status(), StatusCode::OK); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 201 | let etag = header(&look, "etag").to_owned(); |
ec6fd4bb5b60 | atagen | 2026-10-11 04:34 UTC | 202 | assert!(text(look).await.contains('~')); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 203 | let response = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 204 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 205 | "DELETE", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 206 | "/runs/cafebabe/foreskin", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 207 | &[("if-match", &etag)], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 208 | "", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 209 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 210 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 211 | assert_eq!(response.status(), StatusCode::NO_CONTENT); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 212 | let response = send(&app, "GET", "/runs/cafebabe/foreskin", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 213 | assert_eq!(response.status(), StatusCode::GONE); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 214 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 215 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 216 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 217 | async fn length_is_chunked_until_the_ruler() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 218 | let (app, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 219 | let lie = send(&app, "GET", "/runs/cafebabe/length", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 220 | assert!(!lie.headers().contains_key(header::CONTENT_LENGTH)); |
ad00e0e051a1 | atagen | 2026-10-10 14:00 UTC | 221 | let app = seeded_with(Floor::Bedroom, |run| run.items.ruler = true); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 222 | let truth = send(&app, "GET", "/runs/cafebabe/length", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 223 | let declared: usize = header(&truth, "content-length").parse().unwrap(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 224 | let body = text(truth).await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 225 | assert_eq!(body.len(), declared); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 226 | assert!(body.starts_with("8=") && body.ends_with('D')); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 227 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 228 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 229 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 230 | async fn length_supports_inch_ranges() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 231 | let (app, _) = seeded(Floor::Bedroom); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 232 | let response = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 233 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 234 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 235 | "/runs/cafebabe/length", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 236 | &[("range", "inches=0-1")], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 237 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 238 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 239 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 240 | assert_eq!(response.status(), StatusCode::PARTIAL_CONTENT); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 241 | assert!(header(&response, "content-range").starts_with("inches 0.00-1.00/")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 242 | assert_eq!(text(response).await.len(), 25); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 243 | let absurd = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 244 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 245 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 246 | "/runs/cafebabe/length", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 247 | &[("range", "inches=40-50")], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 248 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 249 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 250 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 251 | assert_eq!(absurd.status(), StatusCode::RANGE_NOT_SATISFIABLE); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 252 | let malformed = send( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 253 | &app, |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 254 | "GET", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 255 | "/runs/cafebabe/length", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 256 | &[("range", "inches=6.17")], |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 257 | "", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 258 | ) |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 259 | .await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 260 | assert_eq!(malformed.status(), StatusCode::OK); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 261 | let suffix = send( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 262 | &app, |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 263 | "GET", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 264 | "/runs/cafebabe/length", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 265 | &[("range", "inches=-1")], |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 266 | "", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 267 | ) |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 268 | .await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 269 | assert_eq!(suffix.status(), StatusCode::PARTIAL_CONTENT); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 270 | assert!(text(suffix).await.ends_with('D')); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 271 | for (range, status) in [ |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 272 | ("inches=1-", StatusCode::PARTIAL_CONTENT), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 273 | ("inches=40-", StatusCode::RANGE_NOT_SATISFIABLE), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 274 | ("inches=-0", StatusCode::RANGE_NOT_SATISFIABLE), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 275 | ("inches=2-1", StatusCode::OK), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 276 | ("inches=NaN-2", StatusCode::OK), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 277 | ("inches=0-inf", StatusCode::OK), |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 278 | ] { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 279 | let response = send( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 280 | &app, |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 281 | "GET", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 282 | "/runs/cafebabe/length", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 283 | &[("range", range)], |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 284 | "", |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 285 | ) |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 286 | .await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 287 | assert_eq!(response.status(), status, "{range}"); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 288 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 289 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 290 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 291 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 292 | async fn the_clinic_escalates_toward_honesty() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 293 | let (app, _) = seeded(Floor::Clinic); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 294 | let mut hints = Vec::new(); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 295 | for _ in 0..3 { |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 296 | let response = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 297 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 298 | "GET", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 299 | "/runs/cafebabe/diagnosis", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 300 | &[("authorization", "Excuse \"changing\"")], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 301 | "", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 302 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 303 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 304 | assert_eq!(response.status(), StatusCode::UNAUTHORIZED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 305 | hints.push(header(&response, "www-authenticate").to_owned()); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 306 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 307 | assert!(hints[2].contains("Be honest.")); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 308 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 309 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 310 | #[tokio::test] |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 311 | async fn the_true_ending_is_not_modified() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 312 | let (early, _) = seeded(Floor::Bedroom); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 313 | let response = send(&early, "GET", "/runs/cafebabe/diagnosis", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 314 | assert_eq!(response.status(), StatusCode::TOO_EARLY); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 315 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 316 | let (app, etag) = seeded(Floor::Clinic); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 317 | assert!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 318 | !etag.contains("cafebabe"), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 319 | "the origin ETag must not be derivable from the id" |
782069860236 | atagen | 2026-10-10 12:44 UTC | 320 | ); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 321 | let response = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 322 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 323 | "GET", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 324 | "/runs/cafebabe/diagnosis", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 325 | &[ |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 326 | ("authorization", "Bearer honesty"), |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 327 | ("if-none-match", &etag), |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 328 | ], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 329 | "", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 330 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 331 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 332 | assert_eq!(response.status(), StatusCode::NOT_MODIFIED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 333 | assert_eq!(header(&response, "x-diagnosis"), "normal"); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 334 | } |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 335 | |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 336 | #[tokio::test] |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 337 | async fn mum_accepts_a_known_excuse() { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 338 | let app = seeded_with(Floor::Bedroom, mum_at_the_door); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 339 | let response = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 340 | assert_eq!(response.status(), StatusCode::UNAUTHORIZED); |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 341 | assert_eq!(header(&response, "via"), "1.1 mum"); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 342 | let response = send( |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 343 | &app, |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 344 | "GET", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 345 | "/runs/cafebabe", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 346 | &[("authorization", "Excuse \"homework\"")], |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 347 | "", |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 348 | ) |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 349 | .await; |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 350 | assert_eq!(response.status(), StatusCode::OK); |
a9b016e4b248 | atagen | 2026-10-10 08:12 UTC | 351 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 352 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 353 | #[tokio::test] |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 354 | async fn mum_runs_out_of_patience() { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 355 | let app = seeded_with(Floor::Bedroom, mum_at_the_door); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 356 | let lie = [("authorization", "Excuse \"it is for science\"")]; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 357 | for _ in 0..2 { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 358 | let response = send(&app, "GET", "/runs/cafebabe", &lie, "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 359 | assert_eq!(response.status(), StatusCode::UNAUTHORIZED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 360 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 361 | let caught = send(&app, "GET", "/runs/cafebabe", &lie, "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 362 | assert_eq!(caught.status(), StatusCode::GONE); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 363 | assert_eq!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 364 | json(caught).await["type"], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 365 | "https://jelq.dev/problems/caught" |
782069860236 | atagen | 2026-10-10 12:44 UTC | 366 | ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 367 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 368 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 369 | #[tokio::test] |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 370 | async fn mum_remembers_excuses_by_christmas() { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 371 | let app = seeded_with(Floor::Nans, |run| { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 372 | mum_at_the_door(run); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 373 | run.heard.push("homework".into()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 374 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 375 | let basic = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 376 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 377 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 378 | "/runs/cafebabe", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 379 | &[("authorization", "Excuse \"changing\"")], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 380 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 381 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 382 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 383 | assert_eq!(basic.status(), StatusCode::UNAUTHORIZED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 384 | assert!(header(&basic, "www-authenticate").starts_with("Digest")); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 385 | let replay = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 386 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 387 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 388 | "/runs/cafebabe", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 389 | &[( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 390 | "authorization", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 391 | "Digest username=\"homework\", nonce=\"abc\"", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 392 | )], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 393 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 394 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 395 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 396 | assert_eq!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 397 | json(replay).await["type"], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 398 | "https://jelq.dev/problems/excuse-replayed" |
782069860236 | atagen | 2026-10-10 12:44 UTC | 399 | ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 400 | let fresh = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 401 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 402 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 403 | "/runs/cafebabe", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 404 | &[( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 405 | "authorization", |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 406 | "Digest username=\"wrapping presents\", nonce=\"abc\"", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 407 | )], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 408 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 409 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 410 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 411 | assert_eq!(fresh.status(), StatusCode::OK); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 412 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 413 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 414 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 415 | async fn a_pulled_muscle_is_a_true_excuse() { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 416 | let app = seeded_with(Floor::Nans, |run| { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 417 | mum_at_the_door(run); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 418 | run.conditions.pulled_muscle = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 419 | run.heard.push("pulled a muscle".into()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 420 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 421 | let response = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 422 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 423 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 424 | "/runs/cafebabe", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 425 | &[( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 426 | "authorization", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 427 | "Digest username=\"pulled a muscle\", nonce=\"abc\"", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 428 | )], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 429 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 430 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 431 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 432 | assert_eq!(response.status(), StatusCode::OK); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 433 | assert!(header(&response, "x-stamina").ends_with("/7")); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 434 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 435 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 436 | #[tokio::test] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 437 | async fn floors_end_when_they_end() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 438 | let app = seeded_with(Floor::Bedroom, |_| {}); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 439 | let early = send(&app, "POST", "/runs/cafebabe/floor", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 440 | assert_eq!(early.status(), StatusCode::TOO_EARLY); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 441 | let app = seeded_with(Floor::Bedroom, |run| run.here.turns = 6); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 442 | let next = send(&app, "POST", "/runs/cafebabe/floor", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 443 | assert!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 444 | next.status() == StatusCode::SEE_OTHER || next.status() == StatusCode::CONFLICT, |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 445 | "either the floor changed or the zip did" |
782069860236 | atagen | 2026-10-10 12:44 UTC | 446 | ); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 447 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 448 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 449 | #[tokio::test] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 450 | async fn pump_bro_upsells() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 451 | let closed = seeded_with(Floor::Bedroom, |_| {}); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 452 | let response = send(&closed, "GET", "/runs/cafebabe/shop", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 453 | assert_eq!(response.status(), StatusCode::NOT_FOUND); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 454 | |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 455 | let app = seeded_with(Floor::ChangingRoom, |_| {}); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 456 | let pump = send(&app, "POST", "/runs/cafebabe/shop/pump", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 457 | assert_eq!(pump.status(), StatusCode::UPGRADE_REQUIRED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 458 | assert_eq!(header(&pump, "upgrade"), "pump-pro/2.0"); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 459 | let pro = send(&app, "POST", "/runs/cafebabe/shop/pump-pro", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 460 | assert_eq!(pro.status(), StatusCode::CREATED); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 461 | let broke = send(&app, "POST", "/runs/cafebabe/shop/extender", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 462 | assert_eq!(broke.status(), StatusCode::PAYMENT_REQUIRED); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 463 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 464 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 465 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 466 | async fn only_the_key_opens_the_cage() { |
9683736a2c5e | atagen | 2026-10-10 13:15 UTC | 467 | let app = seeded_with(Floor::ChangingRoom, |run| run.items.cage = true); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 468 | send(&app, "POST", "/runs/cafebabe/shop/ice-pack", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 469 | let still = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 470 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 471 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 472 | "/runs/cafebabe/inventory/chastity-cage", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 473 | &[], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 474 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 475 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 476 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 477 | assert_eq!(still.status(), StatusCode::OK); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 478 | send(&app, "POST", "/runs/cafebabe/shop/cage-key", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 479 | let gone = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 480 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 481 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 482 | "/runs/cafebabe/inventory/chastity-cage", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 483 | &[], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 484 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 485 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 486 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 487 | assert_eq!(gone.status(), StatusCode::NOT_FOUND); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 488 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 489 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 490 | #[tokio::test] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 491 | async fn combos_are_multi_status_xml() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 492 | let app = seeded_with(Floor::Bathroom, |run| { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 493 | run.foreskin = Some(1.0); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 494 | run.items.blinds = true; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 495 | }); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 496 | send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 497 | let response = send( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 498 | &app, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 499 | "JELQ", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 500 | "/runs/cafebabe?technique=wet,stretch", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 501 | &[("content-type", "application/baby-oil")], |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 502 | "", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 503 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 504 | .await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 505 | assert_eq!(response.status(), StatusCode::MULTI_STATUS); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 506 | assert!(text(response).await.contains("<D:multistatus")); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 507 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 508 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 509 | #[tokio::test] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 510 | async fn the_elder_is_stale() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 511 | let app = seeded_with(Floor::Forum, |run| run.length = 5.0); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 512 | let unverified = send(&app, "GET", "/runs/cafebabe/elder", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 513 | assert_eq!( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 514 | unverified.status(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 515 | StatusCode::PROXY_AUTHENTICATION_REQUIRED |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 516 | ); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 517 | let lie = send( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 518 | &app, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 519 | "GET", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 520 | "/runs/cafebabe/elder", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 521 | &[("proxy-authorization", "Ruler 9")], |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 522 | "", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 523 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 524 | .await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 525 | assert_eq!(lie.status(), StatusCode::BAD_REQUEST); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 526 | let csv = send( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 527 | &app, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 528 | "GET", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 529 | "/runs/cafebabe/elder", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 530 | &[("proxy-authorization", "Ruler 5.0")], |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 531 | "", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 532 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 533 | .await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 534 | assert_eq!(csv.status(), StatusCode::OK); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 535 | let stale = send( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 536 | &app, |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 537 | "GET", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 538 | "/runs/cafebabe/elder", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 539 | &[("if-modified-since", "Mon, 15 Jun 2009 00:00:00 GMT")], |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 540 | "", |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 541 | ) |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 542 | .await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 543 | assert_eq!(stale.status(), StatusCode::NOT_MODIFIED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 544 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 545 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 546 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 547 | async fn the_displayed_length_is_accepted_as_honest() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 548 | let app = seeded_with(Floor::Forum, |run| run.length = 5.2496); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 549 | let response = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 550 | &app, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 551 | "GET", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 552 | "/runs/cafebabe/elder", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 553 | &[("proxy-authorization", "Ruler 5.25")], |
782069860236 | atagen | 2026-10-10 12:44 UTC | 554 | "", |
782069860236 | atagen | 2026-10-10 12:44 UTC | 555 | ) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 556 | .await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 557 | assert_eq!(response.status(), StatusCode::OK); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 558 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 559 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 560 | #[tokio::test] |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 561 | async fn the_hotel_has_a_captive_portal() { |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 562 | let app = seeded_with(Floor::Hotel, |_| {}); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 563 | let blocked = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 564 | assert_eq!( |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 565 | blocked.status(), |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 566 | StatusCode::NETWORK_AUTHENTICATION_REQUIRED |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 567 | ); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 568 | let accepted = send(&app, "POST", "/runs/cafebabe/portal", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 569 | assert_eq!(accepted.status(), StatusCode::SEE_OTHER); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 570 | let online = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 571 | assert_eq!(online.status(), StatusCode::OK); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 572 | } |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 573 | |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 574 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 575 | async fn the_internet_never_forgets() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 576 | let app = seeded_with(Floor::Bedroom, |run| { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 577 | run.filmed_at = Some(std::time::SystemTime::now()); |
dfa38cf4cd4b | atagen | 2026-10-10 09:17 UTC | 578 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 579 | let footage = send(&app, "GET", "/runs/cafebabe/footage", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 580 | assert_eq!(footage.status(), StatusCode::OK); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 581 | assert_eq!( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 582 | header(&footage, "cache-control"), |
782069860236 | atagen | 2026-10-10 12:44 UTC | 583 | "public, max-age=31536000, immutable" |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 584 | ); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 585 | assert!(footage.headers().contains_key(header::AGE)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 586 | let delete = send(&app, "DELETE", "/runs/cafebabe/footage", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 587 | assert_eq!(delete.status(), StatusCode::METHOD_NOT_ALLOWED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 588 | assert!(!header(&delete, "allow").contains("DELETE")); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 589 | } |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 590 | |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 591 | #[tokio::test] |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 592 | async fn forged_ruler_cookies_are_lies() { |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 593 | let forged = send( |
782069860236 | atagen | 2026-10-10 12:44 UTC | 594 | &app(), |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 595 | "GET", |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 596 | "/leaderboard?sort=content-length", |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 597 | &[("cookie", "ruler=1")], |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 598 | "", |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 599 | ) |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 600 | .await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 601 | assert_eq!(forged.status(), StatusCode::BAD_REQUEST); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 602 | } |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 603 | |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 604 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 605 | async fn listings_never_reveal_the_private_id() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 606 | let app = app(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 607 | let created = send(&app, "POST", "/runs", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 608 | let location = header(&created, "location").to_owned(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 609 | let board = text(send(&app, "GET", "/leaderboard", &[], "").await).await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 610 | let private = location.trim_start_matches("/runs/"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 611 | assert!(!board.contains(private)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 612 | let entry: Value = serde_json::from_str(&board).unwrap(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 613 | let public = entry["entries"][0]["public_id"].as_str().unwrap(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 614 | let guess = send(&app, "DELETE", &format!("/runs/{public}"), &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 615 | assert_eq!(guess.status(), StatusCode::NOT_FOUND); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 616 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 617 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 618 | #[tokio::test] |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 619 | async fn seeded_runs_are_unranked() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 620 | let app = app(); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 621 | send(&app, "POST", "/runs?seed=7", &[], "").await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 622 | let board = json(send(&app, "GET", "/leaderboard", &[], "").await).await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 623 | assert_eq!(board["entries"].as_array().unwrap().len(), 0); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 624 | let all = json(send(&app, "GET", "/leaderboard?seeded=include", &[], "").await).await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 625 | assert_eq!(all["entries"][0]["ranked"], false); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 626 | } |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 627 | |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 628 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 629 | async fn idle_runs_are_evicted_and_the_server_has_a_limit() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 630 | let forgetful = crate::app(Config { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 631 | idle_ttl: Duration::ZERO, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 632 | ..Config::default() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 633 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 634 | let first = send(&forgetful, "POST", "/runs", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 635 | let location = header(&first, "location").to_owned(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 636 | send(&forgetful, "POST", "/runs", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 637 | let gone = send(&forgetful, "GET", &location, &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 638 | assert_eq!(gone.status(), StatusCode::NOT_FOUND); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 639 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 640 | let tiny = crate::app(Config { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 641 | max_runs: 1, |
782069860236 | atagen | 2026-10-10 12:44 UTC | 642 | ..Config::default() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 643 | }); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 644 | send(&tiny, "POST", "/runs", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 645 | let full = send(&tiny, "POST", "/runs", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 646 | assert_eq!(full.status(), StatusCode::SERVICE_UNAVAILABLE); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 647 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 648 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 649 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 650 | async fn shame_from_two_runs_adds_up() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 651 | let state = Arc::new(AppState::default()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 652 | state.insert(fixture()); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 653 | state.insert(Run::new("deadbeef".into(), "dead".into(), 7)); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 654 | let app = router(state); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 655 | let first = send(&app, "TRACE", "/runs/cafebabe", &[], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 656 | assert_eq!(header(&first, "x-shame"), "1"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 657 | let cookie = header(&first, "set-cookie") |
782069860236 | atagen | 2026-10-10 12:44 UTC | 658 | .split(';') |
782069860236 | atagen | 2026-10-10 12:44 UTC | 659 | .next() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 660 | .unwrap() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 661 | .to_owned(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 662 | let second = send(&app, "TRACE", "/runs/deadbeef", &[("cookie", &cookie)], "").await; |
782069860236 | atagen | 2026-10-10 12:44 UTC | 663 | assert_eq!(header(&second, "x-shame"), "2"); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 664 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 665 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 666 | #[tokio::test] |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 667 | async fn the_root_negotiates() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 668 | let app = app(); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 669 | let browser = send(&app, "GET", "/", &[("accept", "text/html,*/*")], "").await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 670 | assert_eq!(browser.status(), StatusCode::SEE_OTHER); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 671 | assert_eq!(header(&browser, "location"), "/ui/"); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 672 | let curl = send(&app, "GET", "/", &[("accept", "*/*")], "").await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 673 | assert_eq!(json(curl).await["ui"], "/ui/"); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 674 | let page = send(&app, "GET", "/ui/", &[], "").await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 675 | assert_eq!(page.status(), StatusCode::OK); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 676 | } |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 677 | |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 678 | #[tokio::test] |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 679 | async fn the_ui_replays_what_browsers_cannot_send() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 680 | let app = app(); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 681 | let envelope = |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 682 | r#"{"method": "TRACE", "path": "/graveyard", "headers": [["X-Confession", "I did it"]]}"#; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 683 | let traced = json(send(&app, "POST", "/ui/send", &[], envelope).await).await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 684 | assert_eq!(traced["status"], 405); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 685 | let envelope = r#"{"method": "GET", "path": "/", "headers": [["Accept", "text/html"]]}"#; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 686 | let redirected = json(send(&app, "POST", "/ui/send", &[], envelope).await).await; |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 687 | assert_eq!(redirected["status"], 303); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 688 | assert_eq!(redirected["reason"], "See Other"); |
99524cf9f17c | atagen | 2026-10-10 10:53 UTC | 689 | } |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 690 | |
c3e0c27cf8fd | atagen | 2026-10-10 11:28 UTC | 691 | #[tokio::test] |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 692 | async fn the_ui_decodes_gzip_for_display() { |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 693 | let app = seeded_with(Floor::Bedroom, |run| run.items.ring = true); |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 694 | let envelope = |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 695 | r#"{"method": "GET", "path": "/runs/cafebabe", "headers": [["Accept-Encoding", "gzip"]]}"#; |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 696 | let shown = json(send(&app, "POST", "/ui/send", &[], envelope).await).await; |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 697 | assert!( |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 698 | shown["body"] |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 699 | .as_str() |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 700 | .unwrap() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 701 | .contains("\"public_id\":\"cafe\"") |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 702 | ); |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 703 | let encoding = shown["headers"] |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 704 | .as_array() |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 705 | .unwrap() |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 706 | .iter() |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 707 | .any(|h| h[0] == "content-encoding" && h[1] == "gzip"); |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 708 | assert!(encoding); |
ba879f96510d | atagen | 2026-10-10 12:03 UTC | 709 | } |
782069860236 | atagen | 2026-10-10 12:44 UTC | 710 | |
782069860236 | atagen | 2026-10-10 12:44 UTC | 711 | #[tokio::test] |
782069860236 | atagen | 2026-10-10 12:44 UTC | 712 | async fn http_1_0_gets_the_pdf_treatment() { |
782069860236 | atagen | 2026-10-10 12:44 UTC | 713 | let request = Request::builder() |
782069860236 | atagen | 2026-10-10 12:44 UTC | 714 | .uri("/graveyard") |
782069860236 | atagen | 2026-10-10 12:44 UTC | 715 | .version(Version::HTTP_10) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 716 | .body(Body::empty()) |
782069860236 | atagen | 2026-10-10 12:44 UTC | 717 | .unwrap(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 718 | let response = app().oneshot(request).await.unwrap(); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 719 | assert_eq!(response.status(), StatusCode::HTTP_VERSION_NOT_SUPPORTED); |
782069860236 | atagen | 2026-10-10 12:44 UTC | 720 | } |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 721 | |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 722 | #[tokio::test] |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 723 | async fn mom_speaks_american() { |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 724 | let app = seeded_with(Floor::Nans, mum_at_the_door); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 725 | let us = [("accept-language", "en-US")]; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 726 | let knock = send(&app, "GET", "/runs/cafebabe", &us, "").await; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 727 | assert_eq!(header(&knock, "content-language"), "en-US"); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 728 | assert_eq!(header(&knock, "via"), "1.1 mom"); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 729 | assert!( |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 730 | json(knock).await["detail"] |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 731 | .as_str() |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 732 | .unwrap() |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 733 | .contains("Someone is at the door.") |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 734 | ); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 735 | let excuse = [ |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 736 | ("accept-language", "en-US"), |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 737 | ( |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 738 | "authorization", |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 739 | "Digest username=\"carving the turkey\", nonce=\"abc\"", |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 740 | ), |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 741 | ]; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 742 | let answered = send(&app, "GET", "/runs/cafebabe", &excuse, "").await; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 743 | assert_eq!(answered.status(), StatusCode::OK); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 744 | let floor = json(send(&app, "GET", "/runs/cafebabe/floor", &us, "").await).await; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 745 | assert_eq!(floor["name"], "Grandma's house for Thanksgiving"); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 746 | } |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 747 | |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 748 | #[tokio::test] |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 749 | async fn the_default_locale_is_british() { |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 750 | let (app, _) = seeded(Floor::Nans); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 751 | let floor = send(&app, "GET", "/runs/cafebabe/floor", &[], "").await; |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 752 | assert_eq!(header(&floor, "content-language"), "en-GB"); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 753 | assert!(header(&floor, "vary").contains("Accept-Language")); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 754 | assert_eq!(json(floor).await["name"], "Nan's house at Christmas"); |
ef7d6dee5976 | atagen | 2026-10-10 13:23 UTC | 755 | } |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 756 | |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 757 | fn advertised(response: &Response) -> Vec<String> { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 758 | header(response, "link") |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 759 | .split(", <") |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 760 | .filter(|entry| entry.contains("rels/technique")) |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 761 | .filter_map(|entry| { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 762 | entry |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 763 | .split("title=\"") |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 764 | .nth(1)? |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 765 | .split('"') |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 766 | .next() |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 767 | .map(str::to_owned) |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 768 | }) |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 769 | .collect() |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 770 | } |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 771 | |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 772 | #[tokio::test] |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 773 | async fn links_offer_only_usable_techniques() { |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 774 | let app = seeded_with(Floor::Bedroom, |run| run.foreskin = Some(1.0)); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 775 | let cold = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 776 | assert_eq!(advertised(&cold), ["warmup", "ice"]); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 777 | let warm = send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await; |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 778 | let usable = advertised(&warm); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 779 | assert!(usable.contains(&"wet".to_owned()) && usable.contains(&"dry".to_owned())); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 780 | assert!(!usable.contains(&"uli".to_owned()), "uli needs the forum"); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 781 | assert!(!usable.contains(&"pump".to_owned()), "pump needs a pump"); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 782 | assert!( |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 783 | header(&warm, "link").contains("title=\"wet\"; allow=\"JELQ\"; lubricant=\"required\"") |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 784 | ); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 785 | |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 786 | let (forum, _) = seeded(Floor::Forum); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 787 | let response = send(&forum, "GET", "/runs/cafebabe", &[], "").await; |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 788 | assert!(advertised(&response).is_empty()); |
58e1fb3943e6 | atagen | 2026-10-10 13:30 UTC | 789 | } |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 790 | |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 791 | fn linked_rels(response: &Response) -> Vec<String> { |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 792 | header(response, "link") |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 793 | .split(", <") |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 794 | .filter_map(|entry| { |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 795 | entry |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 796 | .split("rels/") |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 797 | .nth(1)? |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 798 | .split('"') |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 799 | .next() |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 800 | .map(str::to_owned) |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 801 | }) |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 802 | .filter(|rel| rel != "technique") |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 803 | .collect() |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 804 | } |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 805 | |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 806 | #[tokio::test] |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 807 | async fn links_hide_resources_that_would_do_nothing() { |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 808 | let (bedroom, _) = seeded(Floor::Bedroom); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 809 | let before = linked_rels(&send(&bedroom, "GET", "/runs/cafebabe", &[], "").await); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 810 | assert!(before.contains(&"drawer".to_owned())); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 811 | assert!(!before.contains(&"diagnosis".to_owned())); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 812 | assert!(!before.contains(&"thread".to_owned())); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 813 | let searched = send(&bedroom, "POST", "/runs/cafebabe/drawer", &[], "").await; |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 814 | assert!(!linked_rels(&searched).contains(&"drawer".to_owned())); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 815 | |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 816 | let (clinic, _) = seeded(Floor::Clinic); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 817 | let rels = linked_rels(&send(&clinic, "GET", "/runs/cafebabe", &[], "").await); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 818 | assert!(rels.contains(&"diagnosis".to_owned()) && rels.contains(&"thread".to_owned())); |
d604371299fb | atagen | 2026-10-10 13:54 UTC | 819 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 820 | |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 821 | #[tokio::test] |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 822 | async fn ignoring_mum_has_consequences() { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 823 | let app = seeded_with(Floor::Bedroom, |run| { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 824 | mum_at_the_door(run); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 825 | run.here.turns = 6; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 826 | }); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 827 | let knock = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 828 | assert_eq!( |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 829 | json(knock).await["type"], |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 830 | "https://jelq.dev/problems/someone-at-the-door" |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 831 | ); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 832 | let leave = send(&app, "POST", "/runs/cafebabe/floor", &[], "").await; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 833 | assert_eq!( |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 834 | leave.status(), |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 835 | StatusCode::UNAUTHORIZED, |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 836 | "no leaving with Mum at the door" |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 837 | ); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 838 | send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 839 | let opened = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 840 | assert_eq!(opened.status(), StatusCode::GONE); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 841 | assert_eq!( |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 842 | json(opened).await["type"], |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 843 | "https://jelq.dev/problems/opened" |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 844 | ); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 845 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 846 | |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 847 | #[tokio::test] |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 848 | async fn caged_drawers_are_noisy_and_eventually_give_up_the_key() { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 849 | let app = seeded_with(Floor::ChangingRoom, |run| run.items.cage = true); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 850 | let mut statuses = Vec::new(); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 851 | for _ in 0..12 { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 852 | let response = send(&app, "POST", "/runs/cafebabe/drawer", &[], "").await; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 853 | statuses.push(response.status()); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 854 | if response.status() == StatusCode::OK { |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 855 | break; |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 856 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 857 | } |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 858 | assert_eq!(statuses.last(), Some(&StatusCode::OK), "{statuses:?}"); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 859 | assert!( |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 860 | statuses[..statuses.len() - 1] |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 861 | .iter() |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 862 | .all(|s| *s == StatusCode::NO_CONTENT) |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 863 | ); |
0d604ee39751 | atagen | 2026-10-10 14:15 UTC | 864 | } |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 865 | |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 866 | #[tokio::test] |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 867 | async fn the_ruler_replaces_the_self_report() { |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 868 | let app = seeded_with(Floor::Bedroom, |_| {}); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 869 | let before = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 870 | assert!(before.headers().contains_key("x-self-reported-length")); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 871 | assert!(!before.headers().contains_key("x-length")); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 872 | |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 873 | let app = seeded_with(Floor::Bedroom, |run| run.items.ruler = true); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 874 | let after = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 875 | assert!(!after.headers().contains_key("x-self-reported-length")); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 876 | assert!(after.headers().contains_key("x-length")); |
f39b10e20a0b | atagen | 2026-10-10 14:33 UTC | 877 | } |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 878 | |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 879 | #[tokio::test] |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 880 | async fn an_open_tab_is_linked_and_jelq_still_answers_with_choices() { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 881 | let app = seeded_with(Floor::Bathroom, |run| { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 882 | run.story = Story::Pending; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 883 | run.warmed_up = true; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 884 | }); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 885 | let response = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 886 | let links = header(&response, "link"); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 887 | assert!(links.contains("/branches/forum>; rel=\"https://jelq.dev/rels/branch\"")); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 888 | assert!(links.contains("/branches/close-tab>; rel=\"https://jelq.dev/rels/branch\"")); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 889 | assert!(links.contains("?technique=wet>")); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 890 | let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=edge", &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 891 | assert_eq!(jelq.status(), StatusCode::MULTIPLE_CHOICES); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 892 | } |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 893 | |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 894 | #[tokio::test] |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 895 | async fn either_story_choice_is_reachable_during_cooldown() { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 896 | for choice in ["forum", "close-tab"] { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 897 | let app = seeded_with(Floor::Bathroom, |run| { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 898 | run.turn = 9; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 899 | run.warmed_up = true; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 900 | run.stamina = 1; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 901 | run.items.door_locks = 1; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 902 | }); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 903 | let tenth = send(&app, "JELQ", "/runs/cafebabe?technique=edge", &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 904 | assert_eq!(tenth.status(), StatusCode::OK); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 905 | let response = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 906 | assert!(!header(&response, "link").contains("?technique=")); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 907 | let path = format!("/runs/cafebabe/branches/{choice}"); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 908 | assert!( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 909 | header(&response, "link") |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 910 | .contains(&format!("<{path}>; rel=\"https://jelq.dev/rels/branch\"")) |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 911 | ); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 912 | let chosen = send(&app, "POST", &path, &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 913 | assert_eq!(chosen.status(), StatusCode::SEE_OTHER); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 914 | assert!(!header(&chosen, "link").contains("/branches/")); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 915 | let repeated = send(&app, "POST", &path, &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 916 | assert_eq!(repeated.status(), StatusCode::CONFLICT); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 917 | } |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 918 | } |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 919 | |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 920 | #[tokio::test] |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 921 | async fn a_door_lock_says_when_it_was_used() { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 922 | let app = seeded_with(Floor::Bathroom, |run| { |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 923 | run.items.door_locks = 1; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 924 | run.suspicion = SUSPICION_LIMIT; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 925 | run.warmed_up = true; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 926 | }); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 927 | let response = send(&app, "JELQ", "/runs/cafebabe?technique=dry", &[], "").await; |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 928 | assert_ne!(response.status(), StatusCode::CONFLICT); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 929 | assert!( |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 930 | response |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 931 | .headers() |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 932 | .get_all("warning") |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 933 | .iter() |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 934 | .any(|w| w.to_str().unwrap().contains("the flatmate tried the door")) |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 935 | ); |
d46f9d0b953a | atagen | 2026-10-10 14:41 UTC | 936 | } |