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!["g".to_owned(), "kg".to_owned(),] ); assert_eq!( other_units .iter() .map(|unit| unit.short_name.clone()) .collect::>(), vec!["l".to_owned(), "ml".to_owned(),] ); }