atagen

jelq

public

an http based roguelike rpg about jelqing

Star0
Watch0
f3a1913c1299571fbfcb552007761bae715c4434
1
ssh://brewery@pls.lobotomise.me:33/atagen/jelq.git
src/tests/methods.rsRust152 lines6.0 KB
1
use super::*;
2
3
#[tokio::test]
4
async fn creating_a_run_returns_location_and_etag() {
5
    let response = send(&app(), "POST", "/runs?seed=1", &[], "").await;
6
    assert_eq!(response.status(), StatusCode::CREATED);
7
    assert!(header(&response, "location").starts_with("/runs/"));
8
    assert!(response.headers().contains_key(header::ETAG));
9
    assert_eq!(header(&response, "server"), "jelqd/0.6.9");
10
}
11
12
#[tokio::test]
13
async fn bodies_do_not_repeat_the_headers() {
14
    let Harness { app, .. } = harness(Floor::Bedroom, SEED, |_| {});
15
    let response = send(&app, "GET", "/runs/cafebabe", &[], "").await;
16
    assert!(response.headers().contains_key("x-eq"));
17
    assert_eq!(header(&response, "x-turn"), "0");
18
    assert_eq!(header(&response, "x-floor-turn"), "0/10");
19
    let body = json(response).await;
20
    for stat in [
21
        "eq",
22
        "girth",
23
        "foreskin",
24
        "stamina",
25
        "cash",
26
        "self_reported_length",
27
    ] {
28
        assert!(body.get(stat).is_none(), "{stat} is already a header");
29
    }
30
}
31
32
#[tokio::test]
33
async fn jelqing_cold_goes_through_at_a_price() {
34
    let friction = async |warm: bool| {
35
        let app = seeded_with(Floor::Bedroom, |run| {
36
            run.body.eq = if warm { 40 } else { 20 };
37
            run.body.foreskin = Some(1.0);
38
        });
39
        let response = send(&app, "JELQ", "/runs/cafebabe?technique=stretch", &[], "").await;
40
        let noted = warnings(&response).iter().any(|w| w.contains("Cold start"));
41
        assert_eq!(noted, !warm);
42
        header(&response, "x-friction").to_owned()
43
    };
44
    assert_eq!(friction(true).await, "1/10");
45
    assert_eq!(friction(false).await, "3/10");
46
}
47
48
#[tokio::test]
49
async fn wet_without_lube_is_unsupported_media() {
50
    let Harness { app, .. } = harness(Floor::Bedroom, SEED, |_| {});
51
    send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await;
52
    let response = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &[], "").await;
53
    assert_eq!(response.status(), StatusCode::UNSUPPORTED_MEDIA_TYPE);
54
    let images = send(
55
        &app,
56
        "JELQ",
57
        "/runs/cafebabe?technique=wet",
58
        &[("content-type", "image/jpeg")],
59
        "",
60
    )
61
    .await;
62
    assert_eq!(json(images).await["detail"], "No.");
63
}
64
65
#[tokio::test]
66
async fn unknown_methods_are_not_implemented() {
67
    let Harness { app, .. } = harness(Floor::Bedroom, SEED, |_| {});
68
    let response = send(&app, "MILK", "/runs/cafebabe", &[], "").await;
69
    assert_eq!(response.status(), StatusCode::NOT_IMPLEMENTED);
70
    let teapot = send(&app, "BREW", "/runs/cafebabe", &[], "").await;
71
    assert_eq!(teapot.status(), StatusCode::IM_A_TEAPOT);
72
}
73
74
#[tokio::test]
75
async fn the_clinic_does_not_advertise_jelq() {
76
    let Harness { app, .. } = harness(Floor::Clinic, SEED, |_| {});
77
    let options = send(&app, "OPTIONS", "/runs/cafebabe", &[], "").await;
78
    assert!(!header(&options, "allow").contains("JELQ"));
79
    let jelq = send(&app, "JELQ", "/runs/cafebabe?technique=wet", &[], "").await;
80
    assert_eq!(jelq.status(), StatusCode::METHOD_NOT_ALLOWED);
81
    assert!(!header(&jelq, "allow").contains("JELQ"));
82
    let Harness { app: bedroom, .. } = harness(Floor::Bedroom, SEED, |_| {});
83
    let options = send(&bedroom, "OPTIONS", "/runs/cafebabe", &[], "").await;
84
    assert!(header(&options, "allow").contains("JELQ"));
85
}
86
87
#[tokio::test]
88
async fn http_1_0_gets_the_pdf_treatment() {
89
    let request = Request::builder()
90
        .uri("/graveyard")
91
        .version(Version::HTTP_10)
92
        .body(Body::empty())
93
        .unwrap();
94
    let response = app().oneshot(request).await.unwrap();
95
    assert_eq!(response.status(), StatusCode::HTTP_VERSION_NOT_SUPPORTED);
96
}
97
98
#[tokio::test]
99
async fn links_offer_only_usable_techniques() {
100
    let app = seeded_with(Floor::Bedroom, |run| run.body.foreskin = Some(1.0));
101
    let cold = send(&app, "GET", "/runs/cafebabe", &[], "").await;
102
    assert!(
103
        advertised(&cold).contains(&"stretch".to_owned()),
104
        "a cold jelq is allowed"
105
    );
106
    let warm = send(&app, "JELQ", "/runs/cafebabe?technique=warmup", &[], "").await;
107
    let usable = advertised(&warm);
108
    assert!(usable.contains(&"wet".to_owned()) && usable.contains(&"dry".to_owned()));
109
    assert!(!usable.contains(&"uli".to_owned()), "uli needs the forum");
110
    assert!(!usable.contains(&"pump".to_owned()), "pump needs a pump");
111
    assert!(
112
        header(&warm, "link")
113
            .contains("title=\"wet\"; allow=\"JELQ\"; lubricant=\"required\"; intensity=\"1-10\"")
114
    );
115
    let edge = header(&warm, "link")
116
        .split(", ")
117
        .find(|link| link.contains("title=\"edge\""))
118
        .unwrap();
119
    assert!(
120
        edge.ends_with("allow=\"JELQ\"; lubricant=\"optional\""),
121
        "an edge takes lube but no intensity"
122
    );
123
124
    let Harness { app: forum, .. } = harness(Floor::Forum, SEED, |_| {});
125
    let response = send(&forum, "GET", "/runs/cafebabe", &[], "").await;
126
    assert!(advertised(&response).is_empty());
127
}
128
129
#[tokio::test]
130
async fn links_hide_resources_that_would_do_nothing() {
131
    let Harness { app: bedroom, .. } = harness(Floor::Bedroom, SEED, |_| {});
132
    let before = linked_rels(&send(&bedroom, "GET", "/runs/cafebabe", &[], "").await);
133
    assert!(before.contains(&"drawer".to_owned()));
134
    assert!(!before.contains(&"diagnosis".to_owned()));
135
    assert!(!before.contains(&"thread".to_owned()));
136
    let searched = send(&bedroom, "POST", "/runs/cafebabe/drawer", &[], "").await;
137
    assert!(!linked_rels(&searched).contains(&"drawer".to_owned()));
138
139
    let Harness { app: clinic, .. } = harness(Floor::Clinic, SEED, |_| {});
140
    let rels = linked_rels(&send(&clinic, "GET", "/runs/cafebabe", &[], "").await);
141
    assert!(rels.contains(&"diagnosis".to_owned()) && rels.contains(&"thread".to_owned()));
142
}
143
144
#[tokio::test]
145
async fn an_ended_run_names_its_cause() {
146
    let app = seeded_with(Floor::Bedroom, |_| {});
147
    let abandoned = send(&app, "DELETE", "/runs/cafebabe", &[], "").await;
148
    assert_eq!(header(&abandoned, "x-run-over"), "abandoned");
149
    let after = send(&app, "GET", "/runs/cafebabe", &[], "").await;
150
    assert_eq!(after.status(), StatusCode::GONE);
151
    assert_eq!(header(&after, "x-run-over"), "abandoned");
152
}