Move mocked test to own mod
This commit is contained in:
parent
31ed4a0eaa
commit
54850ad139
|
@ -29,8 +29,9 @@ struct Err {
|
|||
error_type: String,
|
||||
}
|
||||
#[cfg(test)]
|
||||
fn mock_get_rates(code: &String) -> Result<Status, reqwest::Error> {
|
||||
let response: ConversionRates = match code.as_str() {
|
||||
mod test {
|
||||
pub fn mock_get_rates(code: &String) -> Result<super::Status, reqwest::Error> {
|
||||
let response: super::ConversionRates = match code.as_str() {
|
||||
"PLN" => serde_json::from_str(include_str!(concat!(
|
||||
".",
|
||||
crate::main_separator!(),
|
||||
|
@ -51,17 +52,16 @@ fn mock_get_rates(code: &String) -> Result<Status, reqwest::Error> {
|
|||
panic!("Unknown code")
|
||||
}
|
||||
};
|
||||
cache::add_rates(
|
||||
crate::cache::add_rates(
|
||||
response.time_next_update_unix,
|
||||
&response.base_code,
|
||||
&response.conversion_rates,
|
||||
)
|
||||
.expect("Error while caching response");
|
||||
Ok(Status::OK)
|
||||
}
|
||||
#[cfg(test)]
|
||||
pub fn mock_get_currencies() -> Result<Status, reqwest::Error> {
|
||||
let codes: CurrencyCodes = serde_json::from_str(include_str!(concat!(
|
||||
Ok(super::Status::OK)
|
||||
}
|
||||
pub fn mock_get_currencies() -> Result<super::Status, reqwest::Error> {
|
||||
let codes: super::CurrencyCodes = serde_json::from_str(include_str!(concat!(
|
||||
".",
|
||||
crate::main_separator!(),
|
||||
"mock_data",
|
||||
|
@ -70,15 +70,16 @@ pub fn mock_get_currencies() -> Result<Status, reqwest::Error> {
|
|||
)))
|
||||
.expect("Error when deserializng");
|
||||
for code in codes.supported_codes {
|
||||
cache::add_code(code).expect("Error when adding code to cache");
|
||||
crate::cache::add_code(code).expect("Error when adding code to cache");
|
||||
}
|
||||
return Ok(super::Status::OK);
|
||||
}
|
||||
return Ok(Status::OK);
|
||||
}
|
||||
|
||||
pub fn get_rates(code: &String) -> Result<Status, reqwest::Error> {
|
||||
if cfg!(test) {
|
||||
#[cfg(test)]
|
||||
return mock_get_rates(code);
|
||||
return test::mock_get_rates(code);
|
||||
}
|
||||
let response = reqwest::blocking::get(format!(
|
||||
"{}{}{}{}",
|
||||
|
@ -111,7 +112,7 @@ pub fn get_rates(code: &String) -> Result<Status, reqwest::Error> {
|
|||
pub fn get_currencies() -> Result<Status, reqwest::Error> {
|
||||
if cfg!(test) {
|
||||
#[cfg(test)]
|
||||
return mock_get_currencies();
|
||||
return test::mock_get_currencies();
|
||||
}
|
||||
let response = reqwest::blocking::get(format!(
|
||||
"{}{}{}",
|
||||
|
|
Reference in New Issue