about summary refs log tree commit diff stats
path: root/crates/rocie-server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'crates/rocie-server/tests')
-rw-r--r--crates/rocie-server/tests/_testenv/log.rs2
-rw-r--r--crates/rocie-server/tests/product_parents/mod.rs2
-rw-r--r--crates/rocie-server/tests/product_parents/query.rs144
-rw-r--r--crates/rocie-server/tests/product_parents/register.rs84
-rw-r--r--crates/rocie-server/tests/products/mod.rs4
-rw-r--r--crates/rocie-server/tests/products/register.rs11
-rw-r--r--crates/rocie-server/tests/recipies/mod.rs24
-rw-r--r--crates/rocie-server/tests/tests.rs2
-rw-r--r--crates/rocie-server/tests/units/fetch.rs88
-rw-r--r--crates/rocie-server/tests/units/mod.rs1
-rw-r--r--crates/rocie-server/tests/units/register.rs6
11 files changed, 356 insertions, 12 deletions
diff --git a/crates/rocie-server/tests/_testenv/log.rs b/crates/rocie-server/tests/_testenv/log.rs
index 9a07e78..837ccdd 100644
--- a/crates/rocie-server/tests/_testenv/log.rs
+++ b/crates/rocie-server/tests/_testenv/log.rs
@@ -48,8 +48,10 @@ macro_rules! request {
     }};
 
     (@format, $fn:ident, $($arg:expr),*) => {{
+          #[allow(unused_imports)]
           use std::fmt::Write;
 
+          #[allow(unused_mut)]
           let mut base = String::new();
           $(
               write!(base, "{:?}, ", $arg)
diff --git a/crates/rocie-server/tests/product_parents/mod.rs b/crates/rocie-server/tests/product_parents/mod.rs
new file mode 100644
index 0000000..46ec0ca
--- /dev/null
+++ b/crates/rocie-server/tests/product_parents/mod.rs
@@ -0,0 +1,2 @@
+mod register;
+mod query;
diff --git a/crates/rocie-server/tests/product_parents/query.rs b/crates/rocie-server/tests/product_parents/query.rs
new file mode 100644
index 0000000..6d16ca3
--- /dev/null
+++ b/crates/rocie-server/tests/product_parents/query.rs
@@ -0,0 +1,144 @@
+use rocie_client::{
+    apis::{
+        api_get_product_api::{products_by_product_parent_id_direct, products_by_product_parent_id_indirect},
+        api_get_product_parent_api::{product_parents_toplevel, product_parents_under},
+        api_set_product_api::register_product,
+        api_set_product_parent_api::register_product_parent,
+        api_set_unit_property_api::register_unit_property,
+    },
+    models::{ProductParentStub, ProductStub, UnitPropertyStub},
+};
+
+use crate::{
+    _testenv::init::function_name,
+    testenv::{TestEnv, log::request},
+};
+
+#[tokio::test]
+async fn test_product_parent_query() {
+    let env = TestEnv::new(function_name!());
+
+    let parent_dairy = request!(
+        env,
+        register_product_parent(ProductParentStub {
+            description: Some("Dairy replacment products".to_owned()),
+            name: "Dairy replacements".to_owned(),
+            parent: None,
+        })
+    );
+    request!(
+        env,
+        register_product_parent(ProductParentStub {
+            description: Some("Dairy replacment products".to_owned()),
+            name: "Wheat products".to_owned(),
+            parent: None,
+        })
+    );
+
+    request!(
+        env,
+        register_product_parent(ProductParentStub {
+            description: Some("Milk replacment products".to_owned()),
+            name: "Milk replacements".to_owned(),
+            parent: Some(parent_dairy),
+        })
+    );
+
+    assert_eq!(
+        request!(env, product_parents_toplevel())
+            .into_iter()
+            .map(|parent| parent.name)
+            .collect::<Vec<_>>(),
+        vec!["Dairy replacements".to_owned(), "Wheat products".to_owned(),]
+    );
+
+    assert_eq!(
+        request!(env, product_parents_under(parent_dairy))
+            .into_iter()
+            .map(|parent| parent.name)
+            .collect::<Vec<_>>(),
+        vec!["Milk replacements".to_owned()]
+    );
+}
+
+#[tokio::test]
+async fn test_product_parent_query_product() {
+    let env = TestEnv::new(function_name!());
+
+    let parent_dairy = request!(
+        env,
+        register_product_parent(ProductParentStub {
+            description: Some("Dairy replacment products".to_owned()),
+            name: "Dairy replacements".to_owned(),
+            parent: None,
+        })
+    );
+    let parent_dairy_milk = request!(
+        env,
+        register_product_parent(ProductParentStub {
+            description: Some("Dairy replacment products".to_owned()),
+            name: "milk products".to_owned(),
+            parent: Some(parent_dairy),
+        })
+    );
+
+    let unit_property = request!(
+        env,
+        register_unit_property(UnitPropertyStub {
+            description: None,
+            name: "Volume".to_owned()
+        })
+    );
+
+    request!(
+        env,
+        register_product(ProductStub {
+            description: None,
+            name: "Soy milk".to_owned(),
+            parent: Some(parent_dairy_milk),
+            unit_property,
+        })
+    );
+
+    request!(
+        env,
+        register_product(ProductStub {
+            description: None,
+            name: "Cheese".to_owned(),
+            parent: Some(parent_dairy),
+            unit_property,
+        })
+    );
+
+    assert_eq!(
+        request!(env, products_by_product_parent_id_indirect(parent_dairy_milk))
+            .into_iter()
+            .map(|product| product.name)
+            .collect::<Vec<_>>(),
+        vec!["Soy milk".to_owned()],
+    );
+
+    assert_eq!(
+        request!(env, products_by_product_parent_id_direct(parent_dairy_milk))
+            .into_iter()
+            .map(|product| product.name)
+            .collect::<Vec<_>>(),
+        vec!["Soy milk".to_owned()],
+    );
+
+    assert_eq!(
+        request!(env, products_by_product_parent_id_indirect(parent_dairy))
+            .into_iter()
+            .map(|product| product.name)
+            .collect::<Vec<_>>(),
+        vec!["Cheese".to_owned(), "Soy milk".to_owned(),],
+    );
+
+    assert_eq!(
+        request!(env, products_by_product_parent_id_direct(parent_dairy))
+            .into_iter()
+            .map(|product| product.name)
+            .collect::<Vec<_>>(),
+        vec!["Cheese".to_owned()],
+    );
+}
diff --git a/crates/rocie-server/tests/product_parents/register.rs b/crates/rocie-server/tests/product_parents/register.rs
new file mode 100644
index 0000000..c84ffea
--- /dev/null
+++ b/crates/rocie-server/tests/product_parents/register.rs
@@ -0,0 +1,84 @@
+use rocie_client::{
+    apis::{
+        api_get_product_api::product_by_id, api_set_product_api::register_product,
+        api_set_product_parent_api::register_product_parent,
+        api_set_unit_property_api::register_unit_property,
+    },
+    models::{ProductParentStub, ProductStub, UnitPropertyStub},
+};
+
+use crate::{
+    _testenv::init::function_name,
+    testenv::{TestEnv, log::request},
+};
+
+#[tokio::test]
+async fn test_product_parent_register_roundtrip() {
+    let env = TestEnv::new(function_name!());
+
+    let parent_dairy = request!(
+        env,
+        register_product_parent(ProductParentStub {
+            description: Some("Dairy replacment products".to_owned()),
+            name: "Dairy replacements".to_owned(),
+            parent: None,
+        })
+    );
+    let parent_dairy_milk = request!(
+        env,
+        register_product_parent(ProductParentStub {
+            description: Some("Milk replacment products".to_owned()),
+            name: "Milk replacements".to_owned(),
+            parent: Some(parent_dairy),
+        })
+    );
+
+    let unit_property = request!(
+        env,
+        register_unit_property(UnitPropertyStub {
+            description: Some("The total volume of a product".to_owned()),
+            name: "Volume".to_owned()
+        })
+    );
+
+    let product_soy_milk = request!(
+        env,
+        register_product(ProductStub {
+            description: Some("A soy based alternative to milk".to_owned()),
+            name: "Soy drink".to_owned(),
+            parent: Some(parent_dairy_milk),
+            unit_property,
+        })
+    );
+    let product_oat_milk = request!(
+        env,
+        register_product(ProductStub {
+            description: Some("A oat based alternative to milk".to_owned()),
+            name: "Oat drink".to_owned(),
+            parent: Some(parent_dairy_milk),
+            unit_property,
+        })
+    );
+
+    let product_vegan_cheese = request!(
+        env,
+        register_product(ProductStub {
+            description: None,
+            name: "Vegan cheese".to_owned(),
+            parent: Some(parent_dairy),
+            unit_property,
+        })
+    );
+
+    for product in [product_soy_milk, product_oat_milk] {
+        let product = request!(env, product_by_id(product));
+
+        assert_eq!(product.parent, Some(parent_dairy_milk));
+    }
+
+    {
+        let product = request!(env, product_by_id(product_vegan_cheese));
+
+        assert_eq!(product.parent, Some(parent_dairy));
+    }
+}
diff --git a/crates/rocie-server/tests/products/mod.rs b/crates/rocie-server/tests/products/mod.rs
index 886e5b7..ee139f0 100644
--- a/crates/rocie-server/tests/products/mod.rs
+++ b/crates/rocie-server/tests/products/mod.rs
@@ -20,7 +20,7 @@ async fn create_product(env: &TestEnv, unit_property: UnitPropertyId, name: &str
     request!(
         env,
         register_product(ProductStub {
-            description: Some(None),
+            description: None,
             name: name.to_owned(),
             parent: None,
             unit_property
@@ -31,7 +31,7 @@ async fn create_unit(env: &TestEnv, name: &str, unit_property: UnitPropertyId) -
     request!(
         env,
         register_unit(UnitStub {
-            description: Some(None),
+            description: None,
             full_name_plural: name.to_owned(),
             full_name_singular: name.to_owned(),
             short_name: name.to_owned(),
diff --git a/crates/rocie-server/tests/products/register.rs b/crates/rocie-server/tests/products/register.rs
index 4284bd1..bae7bc7 100644
--- a/crates/rocie-server/tests/products/register.rs
+++ b/crates/rocie-server/tests/products/register.rs
@@ -18,7 +18,7 @@ async fn test_product_register_roundtrip() {
     let unit_property = request!(
         env,
         register_unit_property(UnitPropertyStub {
-            description: Some(Some("The total mass of a product".to_owned())),
+            description: Some("The total mass of a product".to_owned()),
             name: "Mass".to_owned()
         })
     );
@@ -26,7 +26,7 @@ async fn test_product_register_roundtrip() {
     let id = request!(
         env,
         register_product(ProductStub {
-            description: Some(Some("A soy based alternative to milk".to_owned())),
+            description: Some("A soy based alternative to milk".to_owned()),
             name: "Soy drink".to_owned(),
             parent: None,
             unit_property,
@@ -38,11 +38,8 @@ async fn test_product_register_roundtrip() {
     assert_eq!(&product.name, "Soy drink");
     assert_eq!(
         product.description,
-        Some(Some("A soy based alternative to milk".to_owned()))
+        Some("A soy based alternative to milk".to_owned())
     );
     assert_eq!(product.id, id);
-    // assert_eq!(
-    //     product.parent,
-    //     None,
-    // );
+    assert_eq!(product.parent, None);
 }
diff --git a/crates/rocie-server/tests/recipies/mod.rs b/crates/rocie-server/tests/recipies/mod.rs
new file mode 100644
index 0000000..e8aa3c2
--- /dev/null
+++ b/crates/rocie-server/tests/recipies/mod.rs
@@ -0,0 +1,24 @@
+use rocie_client::{
+    apis::{api_get_recipe_api::recipe_by_id, api_set_recipe_api::add_recipe},
+    models::RecipeStub,
+};
+
+use crate::testenv::{TestEnv, init::function_name, log::request};
+
+#[tokio::test]
+async fn test_recipe_roundtrip() {
+    let env = TestEnv::new(function_name!());
+
+    let recipe_id = request!(
+        env,
+        add_recipe(RecipeStub {
+            path: "/asia/curry".to_owned(),
+            content: "just make the curry".to_owned(),
+        })
+    );
+
+    let output = request!(env, recipe_by_id(recipe_id));
+
+    assert_eq!(output.path, "/asia/curry".to_owned());
+    assert_eq!(output.content, "just make the curry".to_owned());
+}
diff --git a/crates/rocie-server/tests/tests.rs b/crates/rocie-server/tests/tests.rs
index cf34156..3759042 100644
--- a/crates/rocie-server/tests/tests.rs
+++ b/crates/rocie-server/tests/tests.rs
@@ -4,4 +4,6 @@ mod _testenv;
 pub(crate) use _testenv as testenv;
 
 mod products;
+mod product_parents;
 mod units;
+mod recipies;
diff --git a/crates/rocie-server/tests/units/fetch.rs b/crates/rocie-server/tests/units/fetch.rs
new file mode 100644
index 0000000..b0bfffb
--- /dev/null
+++ b/crates/rocie-server/tests/units/fetch.rs
@@ -0,0 +1,88 @@
+use rocie_client::{
+    apis::{
+        api_get_unit_api::units_by_property_id, api_set_unit_api::register_unit,
+        api_set_unit_property_api::register_unit_property,
+    },
+    models::{UnitPropertyStub, UnitStub},
+};
+
+use crate::testenv::{TestEnv, init::function_name, log::request};
+
+#[tokio::test]
+async fn test_units_fetch_by_property_id() {
+    let env = TestEnv::new(function_name!());
+
+    let unit_property = request!(
+        env,
+        register_unit_property(UnitPropertyStub {
+            description: Some("The total mass of a product".to_owned()),
+            name: "Mass".to_owned()
+        })
+    );
+    request!(
+        env,
+        register_unit(UnitStub {
+            description: Some("Fancy new unit".to_owned()),
+            full_name_plural: "Grams".to_owned(),
+            full_name_singular: "Gram".to_owned(),
+            short_name: "g".to_owned(),
+            unit_property,
+        })
+    );
+    request!(
+        env,
+        register_unit(UnitStub {
+            description: Some("Better new unit (we should make it SI)".to_owned()),
+            full_name_plural: "Kilograms".to_owned(),
+            full_name_singular: "Kilogram".to_owned(),
+            short_name: "kg".to_owned(),
+            unit_property,
+        })
+    );
+
+    let unit_property2 = request!(
+        env,
+        register_unit_property(UnitPropertyStub {
+            description: Some("The total volume of a product".to_owned()),
+            name: "Volume".to_owned()
+        })
+    );
+    request!(
+        env,
+        register_unit(UnitStub {
+            description: Some("Fancy new unit".to_owned()),
+            full_name_plural: "Liter".to_owned(),
+            full_name_singular: "Liter".to_owned(),
+            short_name: "l".to_owned(),
+            unit_property: unit_property2,
+        })
+    );
+    request!(
+        env,
+        register_unit(UnitStub {
+            description: Some("Better new unit (we should make it SI)".to_owned()),
+            full_name_plural: "Mililiters".to_owned(),
+            full_name_singular: "Mililiter".to_owned(),
+            short_name: "ml".to_owned(),
+            unit_property: unit_property2,
+        })
+    );
+
+    let units = request!(env, units_by_property_id(unit_property));
+    let other_units = request!(env, units_by_property_id(unit_property2));
+
+    assert_eq!(
+        units
+            .iter()
+            .map(|unit| unit.short_name.clone())
+            .collect::<Vec<_>>(),
+        vec!["g".to_owned(), "kg".to_owned(),]
+    );
+    assert_eq!(
+        other_units
+            .iter()
+            .map(|unit| unit.short_name.clone())
+            .collect::<Vec<_>>(),
+        vec!["l".to_owned(), "ml".to_owned(),]
+    );
+}
diff --git a/crates/rocie-server/tests/units/mod.rs b/crates/rocie-server/tests/units/mod.rs
index 5518167..0481d71 100644
--- a/crates/rocie-server/tests/units/mod.rs
+++ b/crates/rocie-server/tests/units/mod.rs
@@ -1 +1,2 @@
 mod register;
+mod fetch;
diff --git a/crates/rocie-server/tests/units/register.rs b/crates/rocie-server/tests/units/register.rs
index 5367b55..8181c25 100644
--- a/crates/rocie-server/tests/units/register.rs
+++ b/crates/rocie-server/tests/units/register.rs
@@ -18,7 +18,7 @@ async fn test_unit_register_roundtrip() {
     let unit_property = request!(
         env,
         register_unit_property(UnitPropertyStub {
-            description: Some(Some("The total mass of a product".to_owned())),
+            description: Some("The total mass of a product".to_owned()),
             name: "Mass".to_owned()
         })
     );
@@ -26,7 +26,7 @@ async fn test_unit_register_roundtrip() {
     let id = request!(
         env,
         register_unit(UnitStub {
-            description: Some(Some("Fancy new unit".to_owned())),
+            description: Some("Fancy new unit".to_owned()),
             full_name_plural: "Grams".to_owned(),
             full_name_singular: "Gram".to_owned(),
             short_name: "g".to_owned(),
@@ -39,7 +39,7 @@ async fn test_unit_register_roundtrip() {
     assert_eq!(&unit.short_name, "g");
     assert_eq!(&unit.full_name_plural, "Grams");
     assert_eq!(&unit.full_name_singular, "Gram");
-    assert_eq!(unit.description, Some(Some("Fancy new unit".to_owned())));
+    assert_eq!(unit.description, Some("Fancy new unit".to_owned()));
     assert_eq!(unit.id, id);
 }