From 0ba32fa30396433c8154f57ccdcfdabae32626be Mon Sep 17 00:00:00 2001 From: Diane Huxley Date: Mon, 3 Jun 2024 12:31:12 -0700 Subject: [PATCH] Add happy path tests for alsoKnownAs and controller --- .../dht/document_packet/also_known_as.rs | 32 +++++++++++++++++++ .../methods/dht/document_packet/controller.rs | 15 +++++++++ 2 files changed, 47 insertions(+) diff --git a/crates/dids/src/methods/dht/document_packet/also_known_as.rs b/crates/dids/src/methods/dht/document_packet/also_known_as.rs index 1a50d8f1..cfc3aacc 100644 --- a/crates/dids/src/methods/dht/document_packet/also_known_as.rs +++ b/crates/dids/src/methods/dht/document_packet/also_known_as.rs @@ -43,3 +43,35 @@ impl AlsoKnownAs { Ok(also_known_as) } } + +#[cfg(test)] +mod test { + use crate::methods::dht::document_packet::controller::Controller; + + use super::*; + + #[test] + fn test_to_and_from_resource_record() { + let also_known_as = vec!["Dave".to_string(), "Bartholemoop".to_string()]; + let record = AlsoKnownAs::to_resource_record(&also_known_as) + .expect("expected to convert to DNS record"); + let also_known_as2 = AlsoKnownAs::from_resource_record(&record) + .expect("Expected to convert from DNS record"); + assert_eq!(also_known_as, also_known_as2); + + + } + + #[test] + fn test_is_aka_record() { + let also_known_as = vec!["Dave".to_string(), "Bartholemoop".to_string()]; + let record = AlsoKnownAs::to_resource_record(&also_known_as) + .expect("expected to convert to DNS record"); + + assert!(AlsoKnownAs::is_aka_record(&record)); + + let controllers = vec!["Jerb".to_string(), "Carrie Bradshaw".to_string()]; + let record = Controller::to_resource_record(&controllers).unwrap(); + assert!(!AlsoKnownAs::is_aka_record(&record)); + } +} \ No newline at end of file diff --git a/crates/dids/src/methods/dht/document_packet/controller.rs b/crates/dids/src/methods/dht/document_packet/controller.rs index 66373e0b..48bda60e 100644 --- a/crates/dids/src/methods/dht/document_packet/controller.rs +++ b/crates/dids/src/methods/dht/document_packet/controller.rs @@ -44,6 +44,8 @@ impl Controller { #[cfg(test)] mod tests { + use crate::methods::dht::document_packet::also_known_as::AlsoKnownAs; + use super::*; #[test] @@ -62,4 +64,17 @@ mod tests { .expect("Expected to get a list of strings from resource record"); assert_eq!(controllers, controllers2); } + + #[test] + fn test_is_cnt_record() { + let also_known_as = vec!["Dave".to_string(), "Bartholemoop".to_string()]; + let record = Controller::to_resource_record(&also_known_as) + .expect("expected to convert to DNS record"); + + assert!(Controller::is_cnt_record(&record)); + + let controllers = vec!["Jerb".to_string(), "Carrie Bradshaw".to_string()]; + let record = AlsoKnownAs::to_resource_record(&controllers).unwrap(); + assert!(!Controller::is_cnt_record(&record)); + } }