atagen

jelq

public

an http based roguelike rpg about jelqing

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