#[cfg(test)]
mod database_tests {
use serde_json::json;
use serde::{Serialize, Deserialize};
use soap_tools::database::create_response;
#[derive(Serialize, Deserialize)]
struct TestStruct {
test: String,
test_int: i32
}
impl TestStruct {
pub fn new(test: String, test_int: i32) -> Self {
TestStruct {
test,
test_int
}
}
}
#[test]
fn should_create_response_with_data_success() {
let test = TestStruct::new("test".to_string(), 1);
let response = create_response(0, "ok".to_string(), Some(test));
assert_eq!(json!({
"status": 0,
"message": "ok",
"data": {
"test": "test",
"test_int": 1
}
}), response);
}
#[test]
fn should_create_response_with_no_data_success() {
let response = create_response(0, "ok".to_string(), None::<()>);
assert_eq!(json!({
"status": 0,
"message": "ok"
}), response);
}
}