an http based roguelike rpg about jelqing
| 1 | use super::*; |
| 2 | |
| 3 | #[tokio::test] |
| 4 | async fn creating_a_run_returns_location_and_etag() { |
| 5 | let response = send(&app(), "POST", "/runs?seed=1", &[], "").await; |
| 6 | assert_eq!(response.status(), StatusCode::CREATED); |
| 7 | assert!(header(&response, "location").starts_with("/runs/")); |
| 8 | assert!(response.headers().contains_key(header::ETAG)); |
| 9 | assert_eq!(header(&response, "server"), "jelqd/0.6.9"); |
| 10 | } |
| 11 | |
| 12 | #[tokio::test] |
| 13 | async fn bodies_do_not_repeat_the_headers() { |
| 14 | let Harness { app, .. } = harness(Floor::Bedroom, SEED, |_| {}); |
| 15 | let response = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
| 16 | assert!(response.headers().contains_key("x-eq")); |
| 17 | let body = json(response).await; |
| 18 | for stat in [ |
| 19 | "eq", |
| 20 | "girth", |
| 21 | "foreskin", |
| 22 | "stamina", |
| 23 | "cash", |
| 24 | "self_reported_length", |
| 25 | ] { |
| 26 | assert!(body.get(stat).is_none(), "{stat} is already a header"); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | #[tokio::test] |
| 31 | async fn jelqing_cold_goes_through_at_a_price() { |
| 32 | let friction = async |warm: bool| { |
| 33 | let app = seeded_with(Floor::Bedroom, |run| { |
| 34 | run.body.eq = if warm { 40 } else { 20 }; |
| 35 | run.body.foreskin = Some(1.0); |
| 36 | }); |
| 37 | let response = send(&app, "JELQ", "/runs/cafebabe?technique=stretch", &[], "").await; |
| 38 | let noted = warnings(&response).iter().any(|w| w.contains("Cold start")); |
| 39 | assert_eq!(noted, !warm); |
| 40 | header(&response, "x-friction").to_owned() |
| 41 | }; |
| 42 | assert_eq!(friction(true).await, "1/10"); |
| 43 | assert_eq!(friction(false).await, "3/10"); |
| 44 | } |
| 45 | |
| 46 | #[tokio::test] |
| 47 | async fn wet_without_lube_is_unsupported_media() { |
| 48 | let Harness { app, .. } = harness(Floor::Bedroom, SEED, |_| {}); |
| 49 | send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await; |
| 50 | let response = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &[], "").await; |
| 51 | assert_eq!(response.status(), StatusCode::UNSUPPORTED_MEDIA_TYPE); |
| 52 | let images = send( |
| 53 | &app, |
| 54 | "JELQ", |
| 55 | "/runs/cafebabe?technique=wet", |
| 56 | &[("content-type", "image/jpeg")], |
| 57 | "", |
| 58 | ) |
| 59 | .await; |
| 60 | assert_eq!(json(images).await["detail"], "No."); |
| 61 | } |
| 62 | |
| 63 | #[tokio::test] |
| 64 | async fn unknown_methods_are_not_implemented() { |
| 65 | let Harness { app, .. } = harness(Floor::Bedroom, SEED, |_| {}); |
| 66 | let response = send(&app, "MILK", "/runs/cafebabe", &[], "").await; |
| 67 | assert_eq!(response.status(), StatusCode::NOT_IMPLEMENTED); |
| 68 | let teapot = send(&app, "BREW", "/runs/cafebabe", &[], "").await; |
| 69 | assert_eq!(teapot.status(), StatusCode::IM_A_TEAPOT); |
| 70 | } |
| 71 | |
| 72 | #[tokio::test] |
| 73 | async fn the_clinic_does_not_advertise_jelq() { |
| 74 | let Harness { app, .. } = harness(Floor::Clinic, SEED, |_| {}); |
| 75 | let options = send(&app, "OPTIONS", "/runs/cafebabe", &[], "").await; |
| 76 | assert!(!header(&options, "allow").contains("JELQ")); |
| 77 | let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &[], "").await; |
| 78 | assert_eq!(jelq.status(), StatusCode::METHOD_NOT_ALLOWED); |
| 79 | assert!(!header(&jelq, "allow").contains("JELQ")); |
| 80 | let Harness { app: bedroom, .. } = harness(Floor::Bedroom, SEED, |_| {}); |
| 81 | let options = send(&bedroom, "OPTIONS", "/runs/cafebabe", &[], "").await; |
| 82 | assert!(header(&options, "allow").contains("JELQ")); |
| 83 | } |
| 84 | |
| 85 | #[tokio::test] |
| 86 | async fn http_1_0_gets_the_pdf_treatment() { |
| 87 | let request = Request::builder() |
| 88 | .uri("/graveyard") |
| 89 | .version(Version::HTTP_10) |
| 90 | .body(Body::empty()) |
| 91 | .unwrap(); |
| 92 | let response = app().oneshot(request).await.unwrap(); |
| 93 | assert_eq!(response.status(), StatusCode::HTTP_VERSION_NOT_SUPPORTED); |
| 94 | } |
| 95 | |
| 96 | #[tokio::test] |
| 97 | async fn links_offer_only_usable_techniques() { |
| 98 | let app = seeded_with(Floor::Bedroom, |run| run.body.foreskin = Some(1.0)); |
| 99 | let cold = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
| 100 | assert!( |
| 101 | advertised(&cold).contains(&"stretch".to_owned()), |
| 102 | "a cold jelq is allowed" |
| 103 | ); |
| 104 | let warm = send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await; |
| 105 | let usable = advertised(&warm); |
| 106 | assert!(usable.contains(&"wet".to_owned()) && usable.contains(&"dry".to_owned())); |
| 107 | assert!(!usable.contains(&"uli".to_owned()), "uli needs the forum"); |
| 108 | assert!(!usable.contains(&"pump".to_owned()), "pump needs a pump"); |
| 109 | assert!( |
| 110 | header(&warm, "link") |
| 111 | .contains("title=\"wet\"; allow=\"JELQ\"; lubricant=\"required\"; intensity=\"1-10\"") |
| 112 | ); |
| 113 | let edge = header(&warm, "link") |
| 114 | .split(", ") |
| 115 | .find(|link| link.contains("title=\"edge\"")) |
| 116 | .unwrap(); |
| 117 | assert!( |
| 118 | edge.ends_with("allow=\"JELQ\"; lubricant=\"optional\""), |
| 119 | "an edge takes lube but no intensity" |
| 120 | ); |
| 121 | |
| 122 | let Harness { app: forum, .. } = harness(Floor::Forum, SEED, |_| {}); |
| 123 | let response = send(&forum, "GET", "/runs/cafebabe", &[], "").await; |
| 124 | assert!(advertised(&response).is_empty()); |
| 125 | } |
| 126 | |
| 127 | #[tokio::test] |
| 128 | async fn links_hide_resources_that_would_do_nothing() { |
| 129 | let Harness { app: bedroom, .. } = harness(Floor::Bedroom, SEED, |_| {}); |
| 130 | let before = linked_rels(&send(&bedroom, "GET", "/runs/cafebabe", &[], "").await); |
| 131 | assert!(before.contains(&"drawer".to_owned())); |
| 132 | assert!(!before.contains(&"diagnosis".to_owned())); |
| 133 | assert!(!before.contains(&"thread".to_owned())); |
| 134 | let searched = send(&bedroom, "POST", "/runs/cafebabe/drawer", &[], "").await; |
| 135 | assert!(!linked_rels(&searched).contains(&"drawer".to_owned())); |
| 136 | |
| 137 | let Harness { app: clinic, .. } = harness(Floor::Clinic, SEED, |_| {}); |
| 138 | let rels = linked_rels(&send(&clinic, "GET", "/runs/cafebabe", &[], "").await); |
| 139 | assert!(rels.contains(&"diagnosis".to_owned()) && rels.contains(&"thread".to_owned())); |
| 140 | } |
| 141 | |
| 142 | #[tokio::test] |
| 143 | async fn an_ended_run_names_its_cause() { |
| 144 | let app = seeded_with(Floor::Bedroom, |_| {}); |
| 145 | let abandoned = send(&app, "DELETE", "/runs/cafebabe", &[], "").await; |
| 146 | assert_eq!(header(&abandoned, "x-run-over"), "abandoned"); |
| 147 | let after = send(&app, "GET", "/runs/cafebabe", &[], "").await; |
| 148 | assert_eq!(after.status(), StatusCode::GONE); |
| 149 | assert_eq!(header(&after, "x-run-over"), "abandoned"); |
| 150 | } |