aboutsummaryrefslogtreecommitdiffstats
path: root/crates/rocie-server/tests/units
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-11-28 16:30:02 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-11-28 16:30:02 +0100
commita62ab5c6dacaddb67931d7ac160bc7faaa707737 (patch)
treea35fa3540fbb89f575ab1ea72f9b23ace399e01c /crates/rocie-server/tests/units
parentchore(crates/rocie-client): Re-generate (diff)
downloadserver-a62ab5c6dacaddb67931d7ac160bc7faaa707737.zip
feat(crates/rocie-server): Get closer to feature parity between rocie and grocy
Diffstat (limited to '')
-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
3 files changed, 92 insertions, 3 deletions
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);
}