Section I - module
use super::*;
use serde_json::value::*;static DELIMITER: &str = "|";Tests
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_new_ob_ok() {
let src = "iStore".to_string();
let uid = 5000;
let cat = "order".to_string();
let sub = "clothing".to_string();
let auth = "istore_app".to_string();
let data = json!({
"status": "new"
});
let _doc = DaaSDoc::new(src, uid, cat, sub, auth, data);
assert!(true);
}
#[test]
fn test_doc_id_ok() {
let src = "iStore".to_string();
let uid = 5000;
let cat = "order".to_string();
let sub = "clothing".to_string();
let auth = "istore_app".to_string();
let id = format!("{}|{}|{}|{}",cat, sub, src, uid).to_string();
let data = json!({
"status": "new"
});
let doc = DaaSDoc::new(src, uid, cat, sub, auth, data);
assert_eq!(doc._id, id);
}
#[test]
fn test_doc_rev_empty() {
let src = "iStore".to_string();
let uid = 5000;
let cat = "order".to_string();
let sub = "clothing".to_string();
let auth = "istore_app".to_string();
let data = json!({
"status": "new"
});
let doc = DaaSDoc::new(src, uid, cat, sub, auth, data);
assert!(doc._rev.is_none());
}
#[test]
fn test_doc_attributes_ok() {
let src = "iStore".to_string();
let uid = 5000;
let cat = "order".to_string();
let sub = "clothing".to_string();
let auth = "istore_app".to_string();
let data = json!({
"status": "new"
});
let doc = DaaSDoc::new(src.clone(), uid, cat.clone(), sub.clone(), auth.clone(), data);
assert_eq!(doc.source_name, src);
assert_eq!(doc.source_uid, uid);
assert_eq!(doc.category, cat);
assert_eq!(doc.subcategory, sub);
assert_eq!(doc.process_ind, false);
}
#[test]
fn test_doc_data_ok() {
let src = "iStore".to_string();
let uid = 5000;
let cat = "order".to_string();
let sub = "clothing".to_string();
let auth = "istore_app".to_string();
let data = json!({
"status": "new"
});
let doc = DaaSDoc::new(src.clone(), uid, cat.clone(), sub.clone(), auth.clone(), data);
assert_eq!(doc.data_obj.get("status").unwrap(), "new");
}
#[test]
fn test_from_serialize(){
let src = "iStore".to_string();
let uid = 5000;
let cat = "order".to_string();
let sub = "clothing".to_string();
let auth = "istore_app".to_string();
let id = format!("{}|{}|{}|{}",cat, sub, src, uid).to_string();
let serialized = r#"{"_id":"order|clothing|iStore|5000","_rev":null,"source_name":"iStore","source_uid":5000,"category":"order","subcategory":"clothing","author":"istore_app","process_ind":false,"last_updated":1553988607,"data_obj":{"status":"new"}}"#;
let doc = DaaSDoc::from_serialized(&serialized);
assert_eq!(doc._id, id);
assert!(doc._rev.is_none());
assert_eq!(doc.source_name, src);
assert_eq!(doc.source_uid, uid);
assert_eq!(doc.category, cat);
assert_eq!(doc.subcategory, sub);
assert_eq!(doc.author, auth);
assert_eq!(doc.process_ind, false);
assert_eq!(doc.data_obj.get("status").unwrap(), "new");
}
#[ignore]
#[test]
fn test_serialize(){
let src = "iStore".to_string();
let uid = 5000;
let cat = "order".to_string();
let sub = "clothing".to_string();
let auth = "istore_app".to_string();
let data = json!({
"status": "new"
});
let mut doc = DaaSDoc::new(src.clone(), uid, cat.clone(), sub.clone(), auth, data);
let serialized = r#"{"_id":"order|clothing|iStore|5000","_rev":null,"source_name":"iStore","source_uid":5000,"category":"order","subcategory":"clothing","author":"istore_app","process_ind":false,"data_obj":{"status":"new"}}"#;
assert_eq!(doc.serialize(), serialized);
}
#[ignore]
#[test]
fn test_serialize_without_rev(){
let src = "iStore".to_string();
let uid = 5000;
let cat = "order".to_string();
let sub = "clothing".to_string();
let auth = "istore_app".to_string();
let data = json!({
"status": "new"
});
let mut doc = DaaSDoc::new(src.clone(), uid, cat.clone(), sub.clone(), auth.clone(), data);
let no_rev = r#"{"_id":"order|clothing|iStore|5000","source_name":"iStore","source_uid":5000,"category":"order","subcategory":"clothing","author":"istore_app","process_ind":false,"data_obj":{"status":"new"}}"#;
assert_eq!(doc.serialize_without_rev(), no_rev.to_string());
}
}Code
Last updated