zero2prod_axum/tests/quick_dev.rs

73 lines
1.9 KiB
Rust
Raw Normal View History

2023-07-01 20:34:21 +02:00
#![allow(unused_imports)]
use anyhow::Result;
use serde_json::json;
#[tokio::test]
async fn test_quick_dev() -> Result<()> {
let hc = httpc_test::new_client("http://localhost:3000")?;
hc.do_get("/hello?name=jen").await?.print().await?;
let hc = httpc_test::new_client("http://localhost:3000")?;
hc.do_get("/hello2/mike").await?.print().await?;
hc.do_get("/src/main.rs").await?.print().await?;
hc.do_get("/src/blub.rs").await?.print().await?;
2023-07-01 20:37:21 +02:00
let req_login = hc.do_post(
"/api/login",
json!(
{
"username": "demo1",
2023-10-07 22:14:22 +02:00
"password": "demowrong"
2023-07-01 20:37:21 +02:00
}
)
);
2023-07-01 20:34:21 +02:00
req_login.await?.print().await?;
2023-10-05 14:33:12 +02:00
let req_login = hc.do_post(
"/api/login",
json!(
{
"username": "demo1",
2023-10-07 22:14:22 +02:00
"password": "demo1"
2023-10-05 14:33:12 +02:00
}
)
);
req_login.await?.print().await?;
2023-07-01 20:34:21 +02:00
2023-07-02 13:25:54 +02:00
hc.do_get("/hello2/mike").await?.print().await?;
2023-10-07 22:14:22 +02:00
let req_create_property = hc.do_post(
"/api/properties",
json!(
{
"address": "Lolilat Street 1",
"contact": "01234 567890"
}
)
);
req_create_property.await?.print().await?;
let req_create_property = hc.do_post(
"/api/properties",
json!(
{
"address": "Lolilat Street 2",
"contact": "01243 217890"
}
)
);
req_create_property.await?.print().await?;
let req_get_properties = hc.do_get("/api/properties").await?;
req_get_properties.print().await?;
let req_delete_property = hc.do_delete("/api/properties/1").await?;
req_delete_property.print().await?;
let req_get_properties = hc.do_get("/api/properties").await?;
req_get_properties.print().await?;
let req_delete_property = hc.do_delete("/api/properties/0").await?;
req_delete_property.print().await?;
2023-07-01 20:34:21 +02:00
Ok(())
}