atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
8b8e83329a1daec70177de3e129964094a711509
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/tests/turns.rsRust225 lines8.8 KB
1
use super::*;
2
3
#[tokio::test]
4
async fn meditation_is_free_but_only_once_per_floor() {
5
    let app = seeded_with(Floor::Bedroom, |_| {});
6
    let response = send(&app, "JELQ", "/runs/cafebabe?technique=meditate", &[], "").await;
7
    assert_eq!(response.status(), StatusCode::OK);
8
    assert_eq!(header(&response, "x-eq"), "10");
9
    assert_eq!(header(&response, "x-stamina"), "10/10");
10
    let again = send(&app, "JELQ", "/runs/cafebabe?technique=meditate", &[], "").await;
11
    assert_eq!(again.status(), StatusCode::CONFLICT);
12
}
13
14
#[tokio::test]
15
async fn meditation_respects_the_priapism_floor() {
16
    let app = seeded_with(Floor::Bedroom, |run| {
17
        run.body.eq = 80;
18
        run.body.conditions.priapism_turns = 3;
19
    });
20
    let calmed = send(&app, "JELQ", "/runs/cafebabe?technique=meditate", &[], "").await;
21
    assert_eq!(calmed.status(), StatusCode::OK);
22
    let view = send(&app, "GET", "/runs/cafebabe", &[], "").await;
23
    assert_eq!(header(&view, "x-eq"), "75");
24
}
25
26
#[tokio::test]
27
async fn priapism_holds_the_floor_through_every_reset() {
28
    let exit = seeded_with(Floor::Bedroom, |run| {
29
        run.body.warmed_up = true;
30
        run.body.eq = 90;
31
        run.here.turns = 99;
32
        run.body.conditions.priapism_turns = 3;
33
    });
34
    let out = send(&exit, "POST", "/runs/cafebabe/floor", &[], "").await;
35
    assert_eq!(out.status(), StatusCode::SEE_OTHER);
36
    let view = send(&exit, "GET", "/runs/cafebabe", &[], "").await;
37
    assert_eq!(header(&view, "x-eq"), "75");
38
39
    let melon = seeded_with(Floor::Bedroom, |run| {
40
        run.body.eq = 95;
41
        run.here.kitchen.melon_offered = true;
42
        run.body.conditions.priapism_turns = 2;
43
    });
44
    let bite = send(&melon, "POST", "/runs/cafebabe/kitchen/watermelon", &[], "").await;
45
    assert_eq!(bite.status(), StatusCode::OK);
46
    let view = send(&melon, "GET", "/runs/cafebabe", &[], "").await;
47
    assert_eq!(header(&view, "x-eq"), "75");
48
}
49
50
#[tokio::test]
51
async fn the_towel_warms_once_until_the_kettle_boils() {
52
    let app = seeded_with(Floor::Bedroom, |_| {});
53
    let warm = send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await;
54
    assert_eq!(warm.status(), StatusCode::OK);
55
    let again = send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await;
56
    assert_eq!(again.status(), StatusCode::CONFLICT);
57
58
    let app = seeded_with(Floor::Bedroom, |run| {
59
        run.body.warmed_up = true;
60
        run.here.kitchen.kettle_boiled = true;
61
    });
62
    let reheated = send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await;
63
    assert_eq!(reheated.status(), StatusCode::OK);
64
    let cold = send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await;
65
    assert_eq!(cold.status(), StatusCode::CONFLICT);
66
}
67
68
#[tokio::test]
69
async fn the_refractory_period_is_the_next_hold() {
70
    let app = seeded_with(Floor::Hotel, |run| {
71
        run.here.wifi_accepted = true;
72
        run.body.warmed_up = true;
73
        run.body.eq = 60;
74
        run.body.stamina = 0;
75
        run.body.exhausted = true;
76
    });
77
    let tired = send(&app, "JELQ", "/runs/cafebabe?technique=edge", &[], "").await;
78
    assert_eq!(tired.status(), StatusCode::TOO_MANY_REQUESTS);
79
    let hold = send(&app, "HOLD", "/runs/cafebabe", &[], "").await;
80
    assert_eq!(hold.status(), StatusCode::OK);
81
    assert_eq!(header(&hold, "x-stamina"), "10/10");
82
    let cold = send(&app, "JELQ", "/runs/cafebabe?technique=edge", &[], "").await;
83
    assert_eq!(cold.status(), StatusCode::PRECONDITION_FAILED);
84
}
85
86
#[tokio::test]
87
async fn a_refused_jelq_does_not_break_the_edging_streak() {
88
    let app = seeded_with(Floor::ChangingRoom, |run| {
89
        run.body.warmed_up = true;
90
        run.body.eq = 45;
91
        run.here.edges = 2;
92
    });
93
    let refused = send(
94
        &app,
95
        "JELQ",
96
        "/runs/cafebabe?technique=dry",
97
        &[("content-type", "application/baby-oil")],
98
        "",
99
    )
100
    .await;
101
    assert_eq!(refused.status(), StatusCode::UNSUPPORTED_MEDIA_TYPE);
102
    let third = send(&app, "JELQ", "/runs/cafebabe?technique=edge", &[], "").await;
103
    assert_eq!(third.status(), StatusCode::LOOP_DETECTED);
104
}
105
106
#[tokio::test]
107
async fn an_interrupted_edge_keeps_no_gains() {
108
    let app = seeded_with(Floor::ChangingRoom, |run| {
109
        run.body.warmed_up = true;
110
        run.body.eq = 10;
111
    });
112
    let before = send(&app, "GET", "/runs/cafebabe", &[], "").await;
113
    let girth = header(&before, "x-girth").to_owned();
114
    let edge = send(&app, "JELQ", "/runs/cafebabe?technique=edge", &[], "").await;
115
    assert_eq!(edge.status(), StatusCode::NOT_FOUND);
116
    assert_eq!(header(&edge, "x-girth"), girth);
117
}
118
119
#[tokio::test]
120
async fn greed_multiplies_gains_above_the_band() {
121
    let lube = [("content-type", "application/baby-oil")];
122
    for (eq, greed) in [(75, 1.5), (88, 2.0)] {
123
        let mut compared = false;
124
        for seed in 0..120u64 {
125
            let app = app_with(Floor::Bedroom, seed, |run| {
126
                run.body.eq = 60;
127
                run.body.warmed_up = true;
128
            });
129
            let in_band = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await;
130
            let app = app_with(Floor::Bedroom, seed, |run| {
131
                run.body.eq = eq;
132
                run.body.warmed_up = true;
133
            });
134
            let greedy = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await;
135
            if in_band.status() != StatusCode::OK || greedy.status() != StatusCode::OK {
136
                continue;
137
            }
138
            let steady = json(in_band).await["length"].as_f64().unwrap();
139
            let eager = json(greedy).await["length"].as_f64().unwrap();
140
            assert!(
141
                (eager - steady * greed).abs() < 1e-9,
142
                "seed {seed} gained {eager} at {eq} EQ against {steady} inside the band"
143
            );
144
            compared = true;
145
            break;
146
        }
147
        assert!(compared, "no seed produced two clean rolls at {eq} EQ");
148
    }
149
}
150
151
#[tokio::test]
152
async fn queued_gains_arrive_on_their_turn() {
153
    let mut run = Run::new("cafebabe".into(), "cafe".into(), SEED);
154
    run.body.eq = 75;
155
    let before = run.body.length;
156
    run.body.pending.push(crate::game::Pending {
157
        due: run.turn + 1,
158
        length: 0.5,
159
        girth: 0.0,
160
        foreskin: 0.0,
161
    });
162
    assert!(run.hold().is_ok());
163
    assert!((run.body.length - before - 0.5).abs() < 1e-9);
164
    assert!(run.body.pending.is_empty());
165
}
166
167
#[tokio::test]
168
async fn hold_keeps_the_shop_and_the_melon_open() {
169
    let hotel = seeded_with(Floor::Hotel, |run| {
170
        run.here.wifi_accepted = true;
171
        run.body.eq = 80;
172
    });
173
    send(&hotel, "GET", "/runs/cafebabe/shop", &[], "").await;
174
    let held = send(&hotel, "HOLD", "/runs/cafebabe", &[], "").await;
175
    assert!(linked_rels(&held).contains(&"shop-item".to_owned()));
176
177
    let mut run = Run::new("cafebabe".into(), "cafe".into(), SEED);
178
    run.body.eq = 80;
179
    run.here.kitchen.melon_offered = true;
180
    assert!(run.hold().is_ok());
181
    assert!(run.here.kitchen.melon_offered, "the offer survives a HOLD");
182
}
183
184
#[tokio::test]
185
async fn leaving_the_band_warms_the_next_floor() {
186
    let app = seeded_with(Floor::Bedroom, |run| {
187
        run.body.eq = 60;
188
        run.body.warmed_up = true;
189
        run.here.turns = 6;
190
        run.items.lubes.baby_oil = 9;
191
    });
192
    let left = send(&app, "POST", "/runs/cafebabe/floor", &[], "").await;
193
    assert_eq!(left.status(), StatusCode::SEE_OTHER);
194
    let detail = json(left).await["detail"].as_str().unwrap().to_owned();
195
    assert!(detail.contains("the warmth came with you"));
196
197
    let lube = [("content-type", "application/baby-oil")];
198
    send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await;
199
    // The shower is a +35 warm-up, so EQ lands in the band and the band bonus rides along.
200
    // The arrival bonus is the one point the second jelq loses.
201
    let first = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await;
202
    assert!(
203
        header(&first, "server-timing").contains("d20+4"),
204
        "the first jelq of a warm arrival rolls with +1, got {}",
205
        header(&first, "server-timing")
206
    );
207
    let second = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &lube, "").await;
208
    assert!(header(&second, "server-timing").contains("d20+3"));
209
}
210
211
#[tokio::test]
212
async fn energy_drinks_add_three_stamina() {
213
    let app = seeded_with(Floor::Bedroom, |run| {
214
        run.body.stamina = 2;
215
        run.items.stores.energy_drinks = 1;
216
    });
217
    let view = send(&app, "GET", "/runs/cafebabe", &[], "").await;
218
    assert!(header(&view, "link").contains("technique=energy"));
219
    let drink = send(&app, "JELQ", "/runs/cafebabe?technique=energy", &[], "").await;
220
    assert_eq!(drink.status(), StatusCode::OK);
221
    let view = send(&app, "GET", "/runs/cafebabe", &[], "").await;
222
    assert_eq!(header(&view, "x-stamina"), "5/10");
223
    let again = send(&app, "JELQ", "/runs/cafebabe?technique=energy", &[], "").await;
224
    assert_eq!(again.status(), StatusCode::FAILED_DEPENDENCY);
225
}