atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
97c05b741d8f0a39cec7b9e24bf5491f18c819c5
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/tests/body.rsRust436 lines13.8 KB
1
use super::*;
2
3
#[tokio::test]
4
async fn deleting_the_foreskin_requires_certainty() {
5
    let Harness { app, .. } = harness(Floor::Bedroom, SEED, |_| {});
6
    let response = send(&app, "DELETE", "/runs/cafebabe/foreskin", &[], "").await;
7
    assert_eq!(response.status(), StatusCode::PRECONDITION_REQUIRED);
8
    let look = send(&app, "GET", "/runs/cafebabe/foreskin", &[], "").await;
9
    assert_eq!(look.status(), StatusCode::OK);
10
    let etag = header(&look, "etag").to_owned();
11
    assert!(text(look).await.contains('~'));
12
    let response = send(
13
        &app,
14
        "DELETE",
15
        "/runs/cafebabe/foreskin",
16
        &[("if-match", &etag)],
17
        "",
18
    )
19
    .await;
20
    assert_eq!(response.status(), StatusCode::NO_CONTENT);
21
    let response = send(&app, "GET", "/runs/cafebabe/foreskin", &[], "").await;
22
    assert_eq!(response.status(), StatusCode::GONE);
23
}
24
25
#[tokio::test]
26
async fn length_supports_inch_ranges() {
27
    let Harness { app, .. } = harness(Floor::Bedroom, SEED, |_| {});
28
    let response = send(
29
        &app,
30
        "GET",
31
        "/runs/cafebabe/length",
32
        &[("range", "inches=0-1")],
33
        "",
34
    )
35
    .await;
36
    assert_eq!(response.status(), StatusCode::PARTIAL_CONTENT);
37
    assert!(header(&response, "content-range").starts_with("inches 0.00-1.00/"));
38
    assert_eq!(text(response).await.len(), 25);
39
    let absurd = send(
40
        &app,
41
        "GET",
42
        "/runs/cafebabe/length",
43
        &[("range", "inches=40-50")],
44
        "",
45
    )
46
    .await;
47
    assert_eq!(absurd.status(), StatusCode::RANGE_NOT_SATISFIABLE);
48
    let malformed = send(
49
        &app,
50
        "GET",
51
        "/runs/cafebabe/length",
52
        &[("range", "inches=6.17")],
53
        "",
54
    )
55
    .await;
56
    assert_eq!(malformed.status(), StatusCode::OK);
57
    let suffix = send(
58
        &app,
59
        "GET",
60
        "/runs/cafebabe/length",
61
        &[("range", "inches=-1")],
62
        "",
63
    )
64
    .await;
65
    assert_eq!(suffix.status(), StatusCode::PARTIAL_CONTENT);
66
    assert!(text(suffix).await.ends_with('D'));
67
    for (range, status) in [
68
        ("inches=1-", StatusCode::PARTIAL_CONTENT),
69
        ("inches=40-", StatusCode::RANGE_NOT_SATISFIABLE),
70
        ("inches=-0", StatusCode::RANGE_NOT_SATISFIABLE),
71
        ("inches=2-1", StatusCode::OK),
72
        ("inches=NaN-2", StatusCode::OK),
73
        ("inches=0-inf", StatusCode::OK),
74
    ] {
75
        let response = send(
76
            &app,
77
            "GET",
78
            "/runs/cafebabe/length",
79
            &[("range", range)],
80
            "",
81
        )
82
        .await;
83
        assert_eq!(response.status(), status, "{range}");
84
    }
85
}
86
87
#[tokio::test]
88
async fn the_displayed_length_is_accepted_as_honest() {
89
    let app = seeded_with(Floor::Forum, |run| run.body.length = 5.2496);
90
    let response = send(
91
        &app,
92
        "GET",
93
        "/runs/cafebabe/elder",
94
        &[("proxy-authorization", "Ruler 5.25")],
95
        "",
96
    )
97
    .await;
98
    assert_eq!(response.status(), StatusCode::OK);
99
}
100
101
#[tokio::test]
102
async fn dry_jelqs_build_friction_and_real_lube_does_not() {
103
    let app = seeded_with(Floor::Bedroom, |run| {
104
        run.body.warmed_up = true;
105
        run.items.lubes.baby_oil = 1;
106
        run.body.foreskin = Some(0.9);
107
    });
108
    let dry = send(&app, "JELQ", "/runs/cafebabe?technique=dry", &[], "").await;
109
    assert_eq!(header(&dry, "x-friction"), "2/10");
110
    let lube = [("content-type", "application/baby-oil")];
111
    let wet = send(
112
        &app,
113
        "JELQ",
114
        "/runs/cafebabe?technique=wet&intensity=5",
115
        &lube,
116
        "",
117
    )
118
    .await;
119
    assert_eq!(header(&wet, "x-friction"), "2/10");
120
    let spit = [("content-type", "text/plain; charset=spit")];
121
    let glisten = send(
122
        &app,
123
        "JELQ",
124
        "/runs/cafebabe?technique=wet&intensity=5",
125
        &spit,
126
        "",
127
    )
128
    .await;
129
    assert_eq!(header(&glisten, "x-friction"), "3/10");
130
}
131
132
#[tokio::test]
133
async fn switching_grips_makes_the_friction_cheaper() {
134
    let app = seeded_with(Floor::Bedroom, |run| {
135
        run.body.warmed_up = true;
136
        run.body.foreskin = Some(0.9);
137
    });
138
    let dry = send(&app, "JELQ", "/runs/cafebabe?technique=dry", &[], "").await;
139
    assert_eq!(header(&dry, "x-friction"), "2/10");
140
    send(
141
        &app,
142
        "GET",
143
        "/runs/cafebabe/grip",
144
        &[("upgrade", "underhand"), ("connection", "upgrade")],
145
        "",
146
    )
147
    .await;
148
    let switched = send(&app, "JELQ", "/runs/cafebabe?technique=dry", &[], "").await;
149
    assert_eq!(header(&switched, "x-friction"), "3/10");
150
    let settled = send(&app, "JELQ", "/runs/cafebabe?technique=dry", &[], "").await;
151
    assert_eq!(header(&settled, "x-friction"), "5/10");
152
}
153
154
#[tokio::test]
155
async fn holding_and_meditating_shed_friction() {
156
    let app = seeded_with(Floor::Bedroom, |run| {
157
        run.body.eq = 80;
158
        run.body.friction = 5;
159
    });
160
    let held = send(&app, "HOLD", "/runs/cafebabe", &[], "").await;
161
    assert_eq!(held.status(), StatusCode::NO_CONTENT);
162
    let view = send(&app, "GET", "/runs/cafebabe", &[], "").await;
163
    assert_eq!(header(&view, "x-friction"), "3/10");
164
165
    let taught = seeded_with(Floor::Bedroom, |run| {
166
        run.body.friction = 5;
167
        run.online.meditation_taught = true;
168
    });
169
    let calmed = send(
170
        &taught,
171
        "JELQ",
172
        "/runs/cafebabe?technique=meditate",
173
        &[],
174
        "",
175
    )
176
    .await;
177
    assert_eq!(calmed.status(), StatusCode::OK);
178
    let view = send(&taught, "GET", "/runs/cafebabe", &[], "").await;
179
    assert_eq!(header(&view, "x-friction"), "3/10");
180
}
181
182
#[tokio::test]
183
async fn a_friction_burn_halves_the_gains() {
184
    let lube = [("content-type", "application/baby-oil")];
185
    let path = "/runs/cafebabe?technique=wet&intensity=5";
186
    for seed in 0..60u64 {
187
        let steady = app_with(Floor::Bedroom, seed, |run| {
188
            run.body.warmed_up = true;
189
            run.body.eq = 60;
190
            run.items.lubes.baby_oil = 9;
191
        });
192
        let hurt_app = app_with(Floor::Bedroom, seed, |run| {
193
            run.body.warmed_up = true;
194
            run.body.eq = 60;
195
            run.items.lubes.baby_oil = 9;
196
            run.body.conditions.friction_burn = true;
197
        });
198
        let calm = send(&steady, "JELQ", path, &lube, "").await;
199
        let hurt = send(&hurt_app, "JELQ", path, &lube, "").await;
200
        if calm.status() != StatusCode::OK || hurt.status() != StatusCode::OK {
201
            continue;
202
        }
203
        let calm_gain = json(calm).await["length"].as_f64().unwrap();
204
        let hurt_gain = json(hurt).await["length"].as_f64().unwrap();
205
        assert!(
206
            (hurt_gain * 2.0 - calm_gain).abs() < 1e-9,
207
            "seed {seed} burned {hurt_gain} against {calm_gain}"
208
        );
209
        return;
210
    }
211
    panic!("no seed in 60 produced two clean rolls to compare");
212
}
213
214
#[tokio::test]
215
async fn the_burn_warns_and_the_ice_treats_it() {
216
    let app = seeded_with(Floor::Bedroom, |run| {
217
        run.body.warmed_up = true;
218
        run.body.eq = 60;
219
        run.items.lubes.baby_oil = 9;
220
        run.body.friction = 7;
221
        run.body.conditions.friction_burn = true;
222
    });
223
    let lube = [("content-type", "application/baby-oil")];
224
    let jelq = send(
225
        &app,
226
        "JELQ",
227
        "/runs/cafebabe?technique=wet&intensity=5",
228
        &lube,
229
        "",
230
    )
231
    .await;
232
    let warnings: Vec<_> = jelq
233
        .headers()
234
        .get_all("warning")
235
        .iter()
236
        .filter_map(|w| w.to_str().ok())
237
        .collect();
238
    assert!(warnings.contains(&"199 - \"friction burn\""));
239
    send(&app, "JELQ", "/runs/cafebabe?technique=ice", &[], "").await;
240
    let view = send(&app, "GET", "/runs/cafebabe", &[], "").await;
241
    let warnings: Vec<_> = view
242
        .headers()
243
        .get_all("warning")
244
        .iter()
245
        .filter_map(|w| w.to_str().ok())
246
        .collect();
247
    assert!(!warnings.contains(&"199 - \"friction burn\""));
248
}
249
250
#[tokio::test]
251
async fn friction_rises_with_vigour_and_edging_chafes() {
252
    let spit = [("content-type", "text/plain; charset=spit")];
253
    for (intensity, friction) in [(5, "1/10"), (7, "2/10"), (10, "3/10")] {
254
        let app = seeded_with(Floor::Hotel, |run| {
255
            run.here.wifi_accepted = true;
256
            run.body.warmed_up = true;
257
            run.body.eq = 55;
258
            run.body.foreskin = Some(0.5);
259
        });
260
        let uri = format!("/runs/cafebabe?technique=wet&intensity={intensity}");
261
        let jelq = send(&app, "JELQ", &uri, &spit, "").await;
262
        assert_eq!(
263
            header(&jelq, "x-friction"),
264
            friction,
265
            "intensity {intensity}"
266
        );
267
    }
268
    let app = seeded_with(Floor::Hotel, |run| {
269
        run.here.wifi_accepted = true;
270
        run.body.warmed_up = true;
271
        run.body.eq = 55;
272
        run.body.foreskin = Some(0.5);
273
    });
274
    let edge = send(&app, "JELQ", "/runs/cafebabe?technique=edge", &[], "").await;
275
    assert_eq!(header(&edge, "x-friction"), "2/10");
276
}
277
278
#[tokio::test]
279
async fn the_body_changes_how_the_skin_takes_it() {
280
    let spit = [("content-type", "text/plain; charset=spit")];
281
    for (foreskin, girth, friction) in [(0.5, 4.5, "1/10"), (1.2, 4.5, "0/10"), (0.5, 5.8, "2/10")]
282
    {
283
        let app = seeded_with(Floor::Hotel, |run| {
284
            run.here.wifi_accepted = true;
285
            run.body.warmed_up = true;
286
            run.body.eq = 55;
287
            run.body.foreskin = Some(foreskin);
288
            run.body.girth = girth;
289
        });
290
        let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &spit, "").await;
291
        assert_eq!(header(&jelq, "x-friction"), friction, "{foreskin} {girth}");
292
    }
293
}
294
295
#[tokio::test]
296
async fn a_thick_girth_outgrows_the_underhand_grip() {
297
    let app = seeded_with(Floor::Bedroom, |run| run.body.girth = 5.8);
298
    let grip = send(
299
        &app,
300
        "GET",
301
        "/runs/cafebabe/grip",
302
        &[("upgrade", "underhand"), ("connection", "upgrade")],
303
        "",
304
    )
305
    .await;
306
    assert_eq!(grip.status(), StatusCode::PAYLOAD_TOO_LARGE);
307
}
308
309
#[tokio::test]
310
async fn a_long_run_fills_the_jeans_before_a_thick_one() {
311
    let app = seeded_with(Floor::Bedroom, |run| {
312
        run.body.warmed_up = true;
313
        run.items.kit.extender = true;
314
        run.body.girth = 4.8;
315
        run.body.length = 7.5;
316
    });
317
    let lube = [("content-type", "application/baby-oil")];
318
    let full = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await;
319
    assert_eq!(full.status(), StatusCode::INSUFFICIENT_STORAGE);
320
}
321
322
#[tokio::test]
323
async fn a_refused_jelq_leaves_the_lube_alone() {
324
    let app = seeded_with(Floor::Bedroom, |run| {
325
        run.body.warmed_up = true;
326
        run.items.kit.extender = true;
327
        run.body.girth = 6.0;
328
        run.body.length = 6.0;
329
    });
330
    let lube = [("content-type", "application/baby-oil")];
331
    let full = send(
332
        &app,
333
        "JELQ",
334
        "/runs/cafebabe?technique=wet&intensity=5",
335
        &lube,
336
        "",
337
    )
338
    .await;
339
    assert_eq!(full.status(), StatusCode::INSUFFICIENT_STORAGE);
340
    let inv = send(&app, "GET", "/runs/cafebabe/inventory", &[], "").await;
341
    let body = json(inv).await;
342
    let held = body["items"].as_array().unwrap();
343
    assert!(held.iter().any(|i| i["name"] == "baby-oil"));
344
}
345
346
#[tokio::test]
347
async fn lubes_run_out_but_spit_never_does() {
348
    let app = seeded_with(Floor::Bedroom, |run| {
349
        run.body.warmed_up = true;
350
        run.items.lubes.baby_oil = 1;
351
    });
352
    let lube = [("content-type", "application/baby-oil")];
353
    send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await;
354
    let second = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await;
355
    assert_eq!(second.status(), StatusCode::UNSUPPORTED_MEDIA_TYPE);
356
357
    let spit = [("content-type", "text/plain; charset=spit")];
358
    for _ in 0..3 {
359
        let wet = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &spit, "").await;
360
        assert_ne!(
361
            wet.status(),
362
            StatusCode::UNSUPPORTED_MEDIA_TYPE,
363
            "spit never runs out"
364
        );
365
    }
366
}
367
368
#[tokio::test]
369
async fn patching_costs_a_little_eq() {
370
    let app = seeded_with(Floor::Bedroom, |run| run.body.eq = 50);
371
    let patch = send(
372
        &app,
373
        "PATCH",
374
        "/runs/cafebabe",
375
        &[("content-type", "application/json-patch+json")],
376
        r#"[{"op": "test", "path": "/girth", "value": 1.0}]"#,
377
    )
378
    .await;
379
    assert_eq!(patch.status(), StatusCode::CONFLICT);
380
    assert_eq!(header(&patch, "x-eq"), "47");
381
}
382
383
#[tokio::test]
384
async fn a_combo_chafes_twice_and_costs_two_stamina() {
385
    let app = seeded_with(Floor::Hotel, |run| {
386
        run.here.wifi_accepted = true;
387
        run.body.warmed_up = true;
388
        run.body.eq = 55;
389
        run.body.foreskin = Some(0.5);
390
    });
391
    let spit = [("content-type", "text/plain; charset=spit")];
392
    let combo = send(
393
        &app,
394
        "JELQ",
395
        "/runs/cafebabe?technique=wet,stretch",
396
        &spit,
397
        "",
398
    )
399
    .await;
400
    assert_eq!(header(&combo, "x-friction"), "2/10");
401
    assert_eq!(header(&combo, "x-stamina"), "8/10");
402
}
403
404
#[test]
405
fn the_drawer_starts_with_at_most_one_bottle() {
406
    let mut stocked = 0;
407
    for seed in 0..400u64 {
408
        let lubes = &Run::new("cafebabe".into(), "cafe".into(), seed).items.lubes;
409
        let bottles = lubes.baby_oil + lubes.lotion;
410
        assert!(bottles <= 1 && lubes.coconut_oil + lubes.vaseline == 0);
411
        stocked += bottles;
412
    }
413
    assert!(
414
        (160..=240).contains(&stocked),
415
        "{stocked}/400 started with lube"
416
    );
417
}
418
419
#[tokio::test]
420
async fn stretching_reports_the_foreskin_it_grew() {
421
    let mut landed = 0;
422
    for seed in 0..40u64 {
423
        let app = app_with(Floor::Bedroom, seed, |run| {
424
            run.body.warmed_up = true;
425
            run.body.eq = 60;
426
            run.body.foreskin = Some(1.0);
427
        });
428
        let stretch = send(&app, "JELQ", "/runs/cafebabe?technique=stretch", &[], "").await;
429
        if stretch.status() == StatusCode::OK {
430
            assert_eq!(header(&stretch, "x-foreskin"), "1.03");
431
            assert_eq!(json(stretch).await["foreskin"], 0.03);
432
            landed += 1;
433
        }
434
    }
435
    assert!(landed > 0, "forty stretches and none landed clean");
436
}