Minor testing
This commit is contained in:
@@ -51,6 +51,8 @@ pub struct CompState {
|
||||
pub rank: DanceRank,
|
||||
pub points: u16,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct DanceInfo {
|
||||
pub firstname: String,
|
||||
pub lastname: String,
|
||||
|
||||
@@ -11,12 +11,15 @@ pub async fn fetch_wsdc_info(id: u32) -> Result<DanceInfo, DanceInfoError> {
|
||||
.map_err(DanceInfoError::ClientBuild)?;
|
||||
|
||||
let mut params = HashMap::new();
|
||||
|
||||
let url = if cfg!(test) {
|
||||
"https://o5grQU3Y.free.beeceptor.com/lookup2020/find"
|
||||
} else {
|
||||
"https://points.worldsdc.com/lookup2020/find"
|
||||
};
|
||||
params.insert("num", id.to_string());
|
||||
let request = client
|
||||
.request(
|
||||
reqwest::Method::POST,
|
||||
"https://points.worldsdc.com/lookup2020/find",
|
||||
)
|
||||
.request(reqwest::Method::POST, url)
|
||||
.form(¶ms)
|
||||
.build()
|
||||
.map_err(DanceInfoError::RequestBuild)?;
|
||||
@@ -29,6 +32,23 @@ pub async fn fetch_wsdc_info(id: u32) -> Result<DanceInfo, DanceInfoError> {
|
||||
Ok(x.into())
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "Only run when the mock api is setup"]
|
||||
fn test_fetch_wsdc() {
|
||||
let rt = match tokio::runtime::Builder::new_current_thread()
|
||||
.enable_all()
|
||||
.build()
|
||||
{
|
||||
Ok(o) => o,
|
||||
Err(e) => {
|
||||
tracing::error!("Could not start runtime: {e}");
|
||||
return;
|
||||
}
|
||||
};
|
||||
let x = rt.block_on(fetch_wsdc_info(7));
|
||||
dbg!(x);
|
||||
}
|
||||
|
||||
#[derive(thiserror::Error, Debug)]
|
||||
pub enum DanceInfoError {
|
||||
#[error("Failed to build client: {0}")]
|
||||
|
||||
Reference in New Issue
Block a user