atagen

jelq

public

an http based roguelike rpg about jelqing

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