atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
3ac624339c982c4129228c05cb5332f4597fc3f7
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/tests/floors.rsRust488 lines16.7 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
            assert!(warnings(&read).is_empty(), "a live read gives nothing away");
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
                taught = true;
208
                break;
209
            }
210
        }
211
        let state = send(&app, "GET", "/runs/cafebabe", &[], "").await;
212
        assert_eq!(header(&state, "x-stamina"), "10/10", "reading is free");
213
        if taught {
214
            taught_runs += 1;
215
            let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=uli", &[], "").await;
216
            assert_ne!(jelq.status(), StatusCode::FORBIDDEN);
217
        } else {
218
            let cached = send(&app, "GET", "/runs/cafebabe/thread", &[], "").await;
219
            assert_eq!(cached.status(), StatusCode::OK);
220
            assert!(header(&cached, "warning").starts_with("112"));
221
            assert!(header(&cached, "age").parse::<u64>().unwrap() > 0);
222
        }
223
    }
224
    assert!(
225
        (30..=58).contains(&taught_runs),
226
        "{taught_runs}/100 learned uli in two reads"
227
    );
228
}
229
230
#[tokio::test]
231
async fn the_thread_cannot_be_read_before_anyone_mentions_it() {
232
    let app = seeded_with(Floor::Bedroom, |_| {});
233
    let read = send(&app, "GET", "/runs/cafebabe/thread", &[], "").await;
234
    assert_eq!(read.status(), StatusCode::NOT_FOUND);
235
    let after = send(&app, "GET", "/runs/cafebabe", &[], "").await;
236
    assert!(!header(&after, "link").contains("/thread"));
237
}
238
239
#[tokio::test]
240
async fn rummaging_for_the_key_leaves_the_drawer_unsearched() {
241
    let mut found = 0;
242
    for seed in 0..20u64 {
243
        let app = app_with(Floor::Hotel, seed, |run| {
244
            run.here.wifi_accepted = true;
245
            run.items.kit.cage = true;
246
        });
247
        for _ in 0..30 {
248
            let rummage = send(&app, "POST", "/runs/cafebabe/drawer", &[], "").await;
249
            if rummage.status() == StatusCode::OK {
250
                break;
251
            }
252
        }
253
        let search = send(&app, "POST", "/runs/cafebabe/drawer", &[], "").await;
254
        if search.status() == StatusCode::FOUND {
255
            assert!(header(&search, "location").ends_with("/inventory/do-not-disturb-sign"));
256
            found += 1;
257
        }
258
    }
259
    assert!(
260
        found >= 18,
261
        "only {found} of 20 hotel drawers survived the rummage"
262
    );
263
}
264
265
#[tokio::test]
266
async fn kev_is_the_bar_in_the_changing_room() {
267
    for (length, shamed) in [(5.0, true), (7.0, false)] {
268
        let app = seeded_with(Floor::Bathroom, |run| {
269
            run.body.length = length;
270
            run.here.turns = 6;
271
        });
272
        let left = send(&app, "POST", "/runs/cafebabe/floor", &[], "").await;
273
        assert_eq!(header(&left, "x-floor"), "3");
274
        let warning = left
275
            .headers()
276
            .get("warning")
277
            .map(|w| w.to_str().unwrap().to_owned());
278
        assert_eq!(
279
            warning.is_some_and(|w| w.contains("Kev")),
280
            shamed,
281
            "length {length}"
282
        );
283
    }
284
}
285
286
#[tokio::test]
287
async fn pump_bro_charges_the_thin_more_for_girth() {
288
    for (girth, ring, oil) in [(4.5, 11, 4), (5.2, 8, 4)] {
289
        let app = seeded_with(Floor::ChangingRoom, |run| run.body.girth = girth);
290
        let shop = json(send(&app, "GET", "/runs/cafebabe/shop", &[], "").await).await;
291
        let price = |slug: &str| {
292
            shop["stock"]
293
                .as_array()
294
                .unwrap()
295
                .iter()
296
                .find(|item| item["item"] == slug)
297
                .unwrap()["price"]
298
                .as_u64()
299
                .unwrap()
300
        };
301
        assert_eq!(price("cock-ring"), ring, "girth {girth}");
302
        assert_eq!(price("baby-oil"), oil, "girth {girth}");
303
    }
304
}
305
306
#[tokio::test]
307
async fn the_clinic_escalates_toward_honesty() {
308
    let Harness { app, .. } = harness(Floor::Clinic, SEED, |_| {});
309
    let mut hints = Vec::new();
310
    for _ in 0..3 {
311
        let response = send(
312
            &app,
313
            "GET",
314
            "/runs/cafebabe/diagnosis",
315
            &[("authorization", "Excuse \"changing\"")],
316
            "",
317
        )
318
        .await;
319
        assert_eq!(response.status(), StatusCode::UNAUTHORIZED);
320
        hints.push(header(&response, "www-authenticate").to_owned());
321
    }
322
    assert!(hints[2].contains("Be honest."));
323
}
324
325
#[tokio::test]
326
async fn the_true_ending_is_not_modified() {
327
    let Harness { app: early, .. } = harness(Floor::Bedroom, SEED, |_| {});
328
    let response = send(&early, "GET", "/runs/cafebabe/diagnosis", &[], "").await;
329
    assert_eq!(response.status(), StatusCode::TOO_EARLY);
330
331
    let Harness {
332
        app, origin: etag, ..
333
    } = harness(Floor::Clinic, SEED, |_| {});
334
    assert!(
335
        !etag.contains("cafebabe"),
336
        "the origin ETag must not be derivable from the id"
337
    );
338
    let response = send(
339
        &app,
340
        "GET",
341
        "/runs/cafebabe/diagnosis",
342
        &[
343
            ("authorization", "Bearer honesty"),
344
            ("if-none-match", &etag),
345
        ],
346
        "",
347
    )
348
    .await;
349
    assert_eq!(response.status(), StatusCode::NOT_MODIFIED);
350
    assert_eq!(header(&response, "x-diagnosis"), "normal");
351
}
352
353
#[tokio::test]
354
async fn the_elder_bans_three_lies_unless_the_girth_impresses() {
355
    let forum = |girth: f64| {
356
        seeded_with(Floor::Forum, move |run| {
357
            run.body.length = 6.0;
358
            run.body.girth = girth;
359
        })
360
    };
361
    let fib = [("proxy-authorization", "Ruler 6.5")];
362
    let thin = forum(4.5);
363
    for _ in 0..2 {
364
        let strike = send(&thin, "GET", "/runs/cafebabe/elder", &fib, "").await;
365
        assert_eq!(strike.status(), StatusCode::PROXY_AUTHENTICATION_REQUIRED);
366
    }
367
    let banned = send(&thin, "GET", "/runs/cafebabe/elder", &fib, "").await;
368
    assert_eq!(banned.status(), StatusCode::FORBIDDEN);
369
    assert!(
370
        json(banned).await["type"]
371
            .as_str()
372
            .unwrap()
373
            .ends_with("banned")
374
    );
375
376
    let thick = forum(5.2);
377
    for _ in 0..4 {
378
        let excused = send(&thick, "GET", "/runs/cafebabe/elder", &fib, "").await;
379
        assert_eq!(excused.status(), StatusCode::PROXY_AUTHENTICATION_REQUIRED);
380
        assert!(header(&excused, "x-forum-note").contains("Girth is also a dimension"));
381
    }
382
}
383
384
#[tokio::test]
385
async fn the_zip_ends_one_exit_in_two_hundred() {
386
    let mut zipped = 0;
387
    for seed in 0..4000u64 {
388
        let mut run = Run::new("cafebabe".into(), "cafe".into(), seed);
389
        run.here.turns = 6;
390
        if run.advance().is_err() && run.ended.is_some() {
391
            zipped += 1;
392
        }
393
    }
394
    assert!(
395
        (8..=35).contains(&zipped),
396
        "{zipped} zips in 4000 exits, about 20 expected"
397
    );
398
}
399
400
#[tokio::test]
401
async fn a_prescription_ends_the_run_and_the_true_ending_still_waits() {
402
    let Harness { app, origin, .. } = harness(Floor::Clinic, SEED, |_| {});
403
    let honest = [("authorization", "Bearer honesty")];
404
    let prescribed = send(&app, "GET", "/runs/cafebabe/diagnosis", &honest, "").await;
405
    assert_eq!(prescribed.status(), StatusCode::OK);
406
    assert!(header(&prescribed, "server-timing").contains("volume;"));
407
    assert!(
408
        json(prescribed).await["detail"]
409
            .as_str()
410
            .unwrap()
411
            .starts_with("Congratulations")
412
    );
413
    let board = json(send(&app, "GET", "/leaderboard?seeded=include", &[], "").await).await;
414
    assert_eq!(board["entries"][0]["status"], "prescribed");
415
416
    let conditional = [
417
        ("authorization", "Bearer honesty"),
418
        ("if-none-match", origin.as_str()),
419
    ];
420
    let cured = send(&app, "GET", "/runs/cafebabe/diagnosis", &conditional, "").await;
421
    assert_eq!(cured.status(), StatusCode::NOT_MODIFIED);
422
    let view = json(send(&app, "GET", "/runs/cafebabe", &[], "").await).await;
423
    assert_eq!(view["status"], "normal");
424
}
425
426
#[tokio::test]
427
async fn the_foreskin_window_has_hard_edges() {
428
    for (foreskin, refused) in [
429
        (0.79, Some(StatusCode::LENGTH_REQUIRED)),
430
        (0.8, None),
431
        (2.0, None),
432
        (2.01, Some(StatusCode::PAYLOAD_TOO_LARGE)),
433
    ] {
434
        let app = seeded_with(Floor::Hotel, |run| {
435
            run.here.wifi_accepted = true;
436
            run.body.eq = 55;
437
            run.body.foreskin = Some(foreskin);
438
        });
439
        let dry = send(&app, "JELQ", "/runs/cafebabe?technique=dry", &[], "").await;
440
        match refused {
441
            Some(status) => assert_eq!(dry.status(), status, "foreskin {foreskin}"),
442
            None => assert!(
443
                ![StatusCode::LENGTH_REQUIRED, StatusCode::PAYLOAD_TOO_LARGE]
444
                    .contains(&dry.status()),
445
                "foreskin {foreskin} sits inside the window"
446
            ),
447
        }
448
    }
449
}
450
451
#[tokio::test]
452
async fn the_forum_teaches_breathing_before_uli() {
453
    let mut breathing = 0;
454
    for seed in 0..100u64 {
455
        let app = app_with(Floor::Bedroom, seed, |run| {
456
            run.turn = BRANCH_TURN;
457
            run.online.story = Story::Pending;
458
        });
459
        let listed = json(send(&app, "GET", "/runs/cafebabe/techniques", &[], "").await).await;
460
        let meditate = listed["techniques"]
461
            .as_array()
462
            .unwrap()
463
            .iter()
464
            .find(|t| t["name"] == "meditate")
465
            .unwrap();
466
        assert_eq!(meditate["locked"], true);
467
        send(&app, "POST", "/runs/cafebabe/branches/forum", &[], "").await;
468
        for _ in 0..2 {
469
            send(&app, "GET", "/runs/cafebabe/thread", &[], "").await;
470
        }
471
        let meditated = send(&app, "JELQ", "/runs/cafebabe?technique=meditate", &[], "").await;
472
        if meditated.status() == StatusCode::OK {
473
            breathing += 1;
474
        } else {
475
            assert_eq!(meditated.status(), StatusCode::FORBIDDEN);
476
            let uli = send(&app, "JELQ", "/runs/cafebabe?technique=uli", &[], "").await;
477
            assert_eq!(
478
                uli.status(),
479
                StatusCode::FORBIDDEN,
480
                "seed {seed} skipped ahead"
481
            );
482
        }
483
    }
484
    assert!(
485
        (75..=97).contains(&breathing),
486
        "{breathing}/100 learned to breathe on the branch floor"
487
    );
488
}