Skip to content
This repository has been archived by the owner on Jun 6, 2024. It is now read-only.

Commit

Permalink
add test
Browse files Browse the repository at this point in the history
  • Loading branch information
SimranMakhija7 committed May 2, 2024
1 parent 4dab2be commit 71e6639
Showing 1 changed file with 65 additions and 0 deletions.
65 changes: 65 additions & 0 deletions src/dto/set_namespace_properties_req.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,68 @@ pub struct SetNamespacePropertiesRequest {
pub removals: Vec<String>,
pub updates: Map<String, Value>,
}

#[cfg(test)]
mod tests {
use super::*;
use serde_json::json;

#[test]
fn test_set_namespace_properties_request() {
let removals = vec!["property1".to_string(), "property2".to_string()];
let updates = json!({
"property3": "value3",
"property4": "value4"
})
.as_object()
.unwrap()
.clone();

let request = SetNamespacePropertiesRequest { removals, updates };

assert_eq!(request.removals[0], "property1");
assert_eq!(request.removals[1], "property2");
assert_eq!(request.updates["property3"], "value3");
assert_eq!(request.updates["property4"], "value4");
}

#[test]
fn test_set_namespace_properties_request_serialization() {
let removals = vec!["property1".to_string(), "property2".to_string()];
let updates = json!({
"property3": "value3",
"property4": "value4"
})
.as_object()
.unwrap()
.clone();

let request = SetNamespacePropertiesRequest { removals, updates };
let serialized = serde_json::to_string(&request).unwrap();

assert!(serialized.contains("property1"));
assert!(serialized.contains("property2"));
assert!(serialized.contains("value3"));
assert!(serialized.contains("value4"));
}

#[test]
fn test_set_namespace_properties_request_deserialization() {
let data = r#"
{
"removals": ["property1", "property2"],
"updates": {
"property3": "value3",
"property4": "value4"
}
}
"#;

let request: SetNamespacePropertiesRequest = serde_json::from_str(data).unwrap();

assert_eq!(request.removals[0], "property1");
assert_eq!(request.removals[1], "property2");
assert_eq!(request.updates["property3"], "value3");
assert_eq!(request.updates["property4"], "value4");
}
}

0 comments on commit 71e6639

Please sign in to comment.