diff --git a/oca/src/facade/mod.rs b/oca/src/facade/mod.rs index 8b2abb9..2828576 100644 --- a/oca/src/facade/mod.rs +++ b/oca/src/facade/mod.rs @@ -40,34 +40,3 @@ impl Facade { } } } - -#[cfg(test)] -mod test { - use super::*; - use crate::{data_storage::InMemoryDataStorage, facade::build::Error}; - - #[test] - fn facade_build_from_ocafile_from_base() -> Result<(), Vec> { - let db = InMemoryDataStorage::new(); - let db_cache = InMemoryDataStorage::new(); - let cache_storage_config = SQLiteConfig::build().unwrap(); - let ocafile = r#" -ADD ATTRIBUTE d=Text i=Text passed=Boolean -ADD META en PROPS name="Entrance credential" description="Entrance credential" -ADD CHARACTER_ENCODING ATTRS d=utf-8 i=utf-8 passed=utf-8 -ADD CONFORMANCE ATTRS d=M i=M passed=M -ADD LABEL en ATTRS d="Schema digest" i="Credential Issuee" passed="Passed" -ADD INFORMATION en ATTRS d="Schema digest" i="Credential Issuee" passed="Enables or disables passing" -"#.to_string(); - let mut facade = - Facade::new(Box::new(db), Box::new(db_cache), cache_storage_config); - - let result = facade.build_from_ocafile(ocafile)?; - - assert_eq!( - result.said.unwrap().to_string(), - "EF5ERATRBBN_ewEo9buQbznirhBmvrSSC0O2GIR4Gbfs" - ); - Ok(()) - } -} diff --git a/oca/tests/build_from_ocafile.rs b/oca/tests/build_from_ocafile.rs new file mode 100644 index 0000000..b662fdb --- /dev/null +++ b/oca/tests/build_from_ocafile.rs @@ -0,0 +1,96 @@ +use oca_rs::{ + data_storage::{DataStorage, InMemoryDataStorage}, + facade::build::Error, + repositories::SQLiteConfig, + Facade, +}; + +#[cfg(test)] +mod test { + use super::*; + + #[test] + fn build_from_base() -> Result<(), Vec> { + let db = InMemoryDataStorage::new(); + let db_cache = InMemoryDataStorage::new(); + let cache_storage_config = SQLiteConfig::build().unwrap(); + let ocafile = r#" +ADD ATTRIBUTE d=Text i=Text passed=Boolean +ADD META en PROPS name="Entrance credential" description="Entrance credential" +ADD CHARACTER_ENCODING ATTRS d=utf-8 i=utf-8 passed=utf-8 +ADD CONFORMANCE ATTRS d=M i=M passed=M +ADD LABEL en ATTRS d="Schema digest" i="Credential Issuee" passed="Passed" +ADD INFORMATION en ATTRS d="Schema digest" i="Credential Issuee" passed="Enables or disables passing" +"#.to_string(); + let mut facade = + Facade::new(Box::new(db), Box::new(db_cache), cache_storage_config); + + let result = facade.build_from_ocafile(ocafile)?; + + assert_eq!( + result.said.unwrap().to_string(), + "EF5ERATRBBN_ewEo9buQbznirhBmvrSSC0O2GIR4Gbfs" + ); + Ok(()) + } + + #[test] + fn build_from_other_bundle() -> Result<(), Vec> { + let db = InMemoryDataStorage::new(); + let db_cache = InMemoryDataStorage::new(); + let cache_storage_config = SQLiteConfig::build().unwrap(); + let mut facade = + Facade::new(Box::new(db), Box::new(db_cache), cache_storage_config); + let other_ocafile = r#" +ADD ATTRIBUTE d=Text i=Text passed=Boolean +ADD META en PROPS name="Entrance credential" description="Entrance credential" +ADD CHARACTER_ENCODING ATTRS d=utf-8 i=utf-8 passed=utf-8 +ADD CONFORMANCE ATTRS d=M i=M passed=M +ADD LABEL en ATTRS d="Schema digest" i="Credential Issuee" passed="Passed" +ADD INFORMATION en ATTRS d="Schema digest" i="Credential Issuee" passed="Enables or disables passing" +"#.to_string(); + facade.build_from_ocafile(other_ocafile)?; + + let ocafile = r#" +FROM EF5ERATRBBN_ewEo9buQbznirhBmvrSSC0O2GIR4Gbfs +ADD ATTRIBUTE x=Text +"#.to_string(); + let result = facade.build_from_ocafile(ocafile)?; + + assert_eq!( + result.said.unwrap().to_string(), + "EBBLFLhdLLgmVOLJO0G6Bqa4-JhFyP8-E0HikwjuRB6w" + ); + Ok(()) + } + + #[test] + fn build_with_references() -> Result<(), Vec> { + let db = InMemoryDataStorage::new(); + let db_cache = InMemoryDataStorage::new(); + let cache_storage_config = SQLiteConfig::build().unwrap(); + let mut facade = + Facade::new(Box::new(db), Box::new(db_cache), cache_storage_config); + let first_ocafile = r#" +ADD ATTRIBUTE a=Text +"#.to_string(); + facade.build_from_ocafile(first_ocafile)?; + let second_ocafile = r#" +-- name=other +ADD ATTRIBUTE b=Text +"#.to_string(); + facade.build_from_ocafile(second_ocafile)?; + + let ocafile = r#" +ADD ATTRIBUTE A=refs:EI_5ohTYptgOrXldUfZujgd7vcXK9zwa6aNqk4-UDWzq +ADD ATTRIBUTE B=refn:other +"#.to_string(); + let result = facade.build_from_ocafile(ocafile)?; + + assert_eq!( + result.said.unwrap().to_string(), + "EPZNx7Vbl06cYdsAKbRVtgxUOoLcap61Go7ueau1RjEN" + ); + Ok(()) + } +}