From 4bd331b43137f80085b51af8b7c6311ce8f60ff6 Mon Sep 17 00:00:00 2001 From: Benedikt Peetz Date: Thu, 23 Oct 2025 23:39:19 +0200 Subject: fix(crates/rocie-server/api/buy-barcode): Allow specifying how often to buy --- crates/rocie-server/tests/products/barcode.rs | 37 ++++++++++++++++++++------- crates/rocie-server/tests/products/mod.rs | 15 ++++------- 2 files changed, 33 insertions(+), 19 deletions(-) (limited to 'crates/rocie-server/tests') diff --git a/crates/rocie-server/tests/products/barcode.rs b/crates/rocie-server/tests/products/barcode.rs index 8e1bf42..5335eb7 100644 --- a/crates/rocie-server/tests/products/barcode.rs +++ b/crates/rocie-server/tests/products/barcode.rs @@ -25,7 +25,7 @@ async fn test_barcode_buy() { let (unit_id, product_id) = create_associated_barcode(&env, "Liter", "Milk", "Volume", unit_value, barcode_id).await; - request!(env, buy_barcode(BarcodeId { value: barcode_id })); + request!(env, buy_barcode(BarcodeId { value: barcode_id }, 1)); let product_amount = request!(env, amount_by_id(product_id)); @@ -34,6 +34,25 @@ async fn test_barcode_buy() { assert_eq!(product_amount.amount.value, unit_value); } +#[tokio::test] +async fn test_barcode_buy_multiple() { + let env = TestEnv::new(function_name!()); + + let barcode_id = 23; + let unit_value = 1; + + let (unit_id, product_id) = + create_associated_barcode(&env, "Liter", "Milk", "Volume", unit_value, barcode_id).await; + + request!(env, buy_barcode(BarcodeId { value: barcode_id }, 5)); + + let product_amount = request!(env, amount_by_id(product_id)); + + assert_eq!(product_amount.product_id, product_id); + assert_eq!(product_amount.amount.unit, unit_id); + assert_eq!(product_amount.amount.value, unit_value * 5); +} + #[tokio::test] async fn test_barcode_consume() { let env = TestEnv::new(function_name!()); @@ -51,7 +70,7 @@ async fn test_barcode_consume() { ) .await; - request!(env, buy_barcode(barcode_id)); + request!(env, buy_barcode(barcode_id, 1)); request!( env, @@ -88,7 +107,7 @@ async fn test_barcode_consume_error() { ) .await; - request!(env, buy_barcode(barcode_id)); + request!(env, buy_barcode(barcode_id, 1)); request!( @expect_error "We should not be able to consume more than available." @@ -127,7 +146,7 @@ async fn test_barcode_consume_error_other() { ) .await; - request!(env, buy_barcode(barcode_id)); + request!(env, buy_barcode(barcode_id, 1)); request!( env, @@ -177,9 +196,9 @@ async fn test_barcode_multiple_buy_and_consume() { ) .await; - request!(env, buy_barcode(barcode_id)); + request!(env, buy_barcode(barcode_id, 1)); - request!(env, buy_barcode(barcode_id)); + request!(env, buy_barcode(barcode_id, 1)); env.log("Bought both barcodes"); @@ -228,9 +247,9 @@ async fn test_barcode_fill_up() { let _ = create_associated_barcode(&env, "Kilogram", "Bread", "Mass", 2, bread_id.value).await; let _ = create_associated_barcode(&env, "Piece", "Nut", "Quantity", 2, nuts_id.value).await; - request!(env, buy_barcode(milk_id)); - request!(env, buy_barcode(bread_id)); - request!(env, buy_barcode(nuts_id)); + request!(env, buy_barcode(milk_id, 1)); + request!(env, buy_barcode(bread_id, 1)); + request!(env, buy_barcode(nuts_id, 1)); } #[tokio::test] diff --git a/crates/rocie-server/tests/products/mod.rs b/crates/rocie-server/tests/products/mod.rs index b39a07c..886e5b7 100644 --- a/crates/rocie-server/tests/products/mod.rs +++ b/crates/rocie-server/tests/products/mod.rs @@ -13,14 +13,11 @@ use rocie_client::{ use crate::testenv::{TestEnv, log::request}; mod barcode; +mod query; mod register; -async fn create_product( - env: &TestEnv, - unit_property: UnitPropertyId, - name: &str, -) -> (ProductId, UnitPropertyId) { - let product_id = request!( +async fn create_product(env: &TestEnv, unit_property: UnitPropertyId, name: &str) -> ProductId { + request!( env, register_product(ProductStub { description: Some(None), @@ -28,9 +25,7 @@ async fn create_product( parent: None, unit_property }) - ); - - (product_id, unit_property) + ) } async fn create_unit(env: &TestEnv, name: &str, unit_property: UnitPropertyId) -> UnitId { request!( @@ -61,7 +56,7 @@ async fn create_associated_barcode( }) ); - let (product_id, unit_property) = create_product(env, unit_property, product_name).await; + let product_id = create_product(env, unit_property, product_name).await; let unit_id = create_unit(env, unit_name, unit_property).await; let barcode_id = BarcodeId { value: barcode_id }; -- cgit 1.4.1