aboutsummaryrefslogtreecommitdiffstats
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/products/query.rs143
1 files changed, 143 insertions, 0 deletions
diff --git a/crates/rocie-server/tests/products/query.rs b/crates/rocie-server/tests/products/query.rs
new file mode 100644
index 0000000..8adfbb5
--- /dev/null
+++ b/crates/rocie-server/tests/products/query.rs
@@ -0,0 +1,143 @@
+use rocie_client::{
+ apis::{
+ api_get_product_api::{product_by_name, product_suggestion_by_name},
+ api_set_unit_property_api::register_unit_property,
+ },
+ models::UnitPropertyStub,
+};
+
+use crate::{
+ _testenv::{TestEnv, init::function_name, log::request},
+ products::create_product,
+};
+
+#[tokio::test]
+#[expect(clippy::similar_names)]
+async fn test_product_name_suggestions() {
+ let env = TestEnv::new(function_name!());
+
+ let unit_property = request!(
+ env,
+ register_unit_property(UnitPropertyStub {
+ description: None,
+ name: "Voluem".to_string(),
+ })
+ );
+
+ let milk_1_id = create_product(&env, unit_property, "Milk 1").await;
+ let milk_12_id = create_product(&env, unit_property, "Milk 12").await;
+ let milk_2_id = create_product(&env, unit_property, "Milk 2").await;
+ let milk_3_id = create_product(&env, unit_property, "Milk 3").await;
+
+ let products = request!(env, product_suggestion_by_name("Milk"))
+ .into_iter()
+ .map(|p| p.id)
+ .collect::<Vec<_>>();
+
+ assert_eq!(products, vec![milk_1_id, milk_12_id, milk_2_id, milk_3_id]);
+
+ let products = request!(env, product_suggestion_by_name("Milk 1"))
+ .into_iter()
+ .map(|p| p.id)
+ .collect::<Vec<_>>();
+
+ assert_eq!(products, vec![milk_1_id, milk_12_id]);
+}
+
+#[tokio::test]
+async fn test_product_name_suggest_space() {
+ let env = TestEnv::new(function_name!());
+
+ let unit_property = request!(
+ env,
+ register_unit_property(UnitPropertyStub {
+ description: None,
+ name: "Voluem".to_string(),
+ })
+ );
+
+ let milk_1_id = create_product(&env, unit_property, "Milk 1").await;
+
+ let products = request!(env, product_suggestion_by_name("Milk "))
+ .into_iter()
+ .map(|s| s.id)
+ .collect::<Vec<_>>();
+
+ assert_eq!(products, vec![milk_1_id]);
+}
+
+#[tokio::test]
+async fn test_product_name_lookup_space() {
+ let env = TestEnv::new(function_name!());
+
+ let unit_property = request!(
+ env,
+ register_unit_property(UnitPropertyStub {
+ description: None,
+ name: "Voluem".to_string(),
+ })
+ );
+
+ let milk_1_id = create_product(&env, unit_property, "Milk 1").await;
+
+ let product = request!(env, product_by_name("Milk 1"));
+
+ assert_eq!(product.id, milk_1_id);
+}
+
+#[tokio::test]
+async fn test_product_name_lookup_fancy() {
+ let env = TestEnv::new(function_name!());
+
+ let unit_property = request!(
+ env,
+ register_unit_property(UnitPropertyStub {
+ description: None,
+ name: "Voluem".to_string(),
+ })
+ );
+
+ let milk_1_id = create_product(&env, unit_property, "Roglič 1 (Čebule in Česen)").await;
+
+ let product = request!(env, product_by_name("Roglič 1 (Čebule in Česen)"));
+
+ assert_eq!(product.id, milk_1_id);
+}
+
+#[tokio::test]
+async fn test_product_name_lookup_emoji() {
+ let env = TestEnv::new(function_name!());
+
+ let unit_property = request!(
+ env,
+ register_unit_property(UnitPropertyStub {
+ description: None,
+ name: "Voluem".to_string(),
+ })
+ );
+
+ let milk_1_id = create_product(&env, unit_property, "👾 Milk").await;
+
+ let product = request!(env, product_by_name("👾 Milk"));
+
+ assert_eq!(product.id, milk_1_id);
+}
+
+#[tokio::test]
+async fn test_product_name_lookup_plus() {
+ let env = TestEnv::new(function_name!());
+
+ let unit_property = request!(
+ env,
+ register_unit_property(UnitPropertyStub {
+ description: None,
+ name: "Voluem".to_string(),
+ })
+ );
+
+ let milk_1_id = create_product(&env, unit_property, "Milk + Chocolate").await;
+
+ let product = request!(env, product_by_name("Milk + Chocolate"));
+
+ assert_eq!(product.id, milk_1_id);
+}