aboutsummaryrefslogtreecommitdiffstats
path: root/crates/rocie-server/tests
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--crates/rocie-server/tests/products/barcode.rs62
-rw-r--r--crates/rocie-server/tests/products/mod.rs26
-rw-r--r--crates/rocie-server/tests/products/register.rs2
3 files changed, 44 insertions, 46 deletions
diff --git a/crates/rocie-server/tests/products/barcode.rs b/crates/rocie-server/tests/products/barcode.rs
index c267006..480dcb9 100644
--- a/crates/rocie-server/tests/products/barcode.rs
+++ b/crates/rocie-server/tests/products/barcode.rs
@@ -3,7 +3,7 @@ use rocie_client::{
api_get_inventory_api::amount_by_id,
api_set_barcode_api::{buy_barcode, consume_barcode},
},
- models::UnitAmount,
+ models::{BarcodeId, UnitAmount},
};
use crate::{
@@ -21,31 +21,31 @@ async fn test_barcode_buy() {
let (unit_id, product_id) =
create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id).await;
- request!(env, buy_barcode(i32::try_from(barcode_id).unwrap()));
+ request!(env, buy_barcode(BarcodeId { value: barcode_id }));
- let product_amount = request!(env, amount_by_id(product_id.to_string().as_str()));
+ 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, i64::from(unit_value));
+ assert_eq!(product_amount.amount.value, unit_value);
}
#[tokio::test]
async fn test_barcode_consume() {
let env = TestEnv::new(module_path!(), 8083);
- let barcode_id = 23;
+ let barcode_id = BarcodeId { value: 23 };
let unit_value = 1;
let (unit_id, product_id) =
- create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id).await;
+ create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id.value).await;
- request!(env, buy_barcode(i32::try_from(barcode_id).unwrap()));
+ request!(env, buy_barcode(barcode_id));
request!(
env,
consume_barcode(
- i32::try_from(barcode_id).unwrap(),
+ barcode_id,
UnitAmount {
unit: unit_id,
value: 1,
@@ -53,7 +53,7 @@ async fn test_barcode_consume() {
)
);
- let product_amount = request!(env, amount_by_id(product_id.to_string().as_str()));
+ 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);
@@ -64,50 +64,50 @@ async fn test_barcode_consume() {
async fn test_barcode_consume_error() {
let env = TestEnv::new(module_path!(), 8084);
- let barcode_id = 23;
+ let barcode_id = BarcodeId { value: 23 };
let unit_value = 1;
let (unit_id, product_id) =
- create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id).await;
+ create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id.value).await;
- request!(env, buy_barcode(i32::try_from(barcode_id).unwrap()));
+ request!(env, buy_barcode(barcode_id));
request!(
@expect_error "We should not be able to consume more than available."
env,
consume_barcode(
- i32::try_from(barcode_id).unwrap(),
+ barcode_id,
UnitAmount {
unit: unit_id,
- value: i64::from(unit_value + 1),
+ value: unit_value + 1,
},
)
);
// Test, that the error does not actually go into the db.
- let product_amount = request!(env, amount_by_id(product_id.to_string().as_str()));
+ 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, i64::from(unit_value));
+ assert_eq!(product_amount.amount.value, unit_value);
}
#[tokio::test]
async fn test_barcode_consume_error_other() {
let env = TestEnv::new(module_path!(), 8085);
- let barcode_id = 23;
+ let barcode_id = BarcodeId { value: 23 };
let unit_value = 1;
let (unit_id, product_id) =
- create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id).await;
+ create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id.value).await;
- request!(env, buy_barcode(i32::try_from(barcode_id).unwrap()));
+ request!(env, buy_barcode(barcode_id));
request!(
env,
consume_barcode(
- i32::try_from(barcode_id).unwrap(),
+ barcode_id,
UnitAmount {
unit: unit_id,
value: 1,
@@ -119,7 +119,7 @@ async fn test_barcode_consume_error_other() {
@expect_error "We already consumed everything, we bought"
env,
consume_barcode(
- i32::try_from(barcode_id).unwrap(),
+ barcode_id,
UnitAmount {
unit: unit_id,
value: 1,
@@ -128,33 +128,33 @@ async fn test_barcode_consume_error_other() {
);
// Test, that the error does not actually go into the db.
- let product_amount = request!(env, amount_by_id(product_id.to_string().as_str()));
+ 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, i64::from(0));
+ assert_eq!(product_amount.amount.value, 0);
}
#[tokio::test]
async fn test_barcode_multiple_buy_and_consume() {
let env = TestEnv::new(module_path!(), 8086);
- let barcode_id = 23;
+ let barcode_id = BarcodeId { value: 23 };
let unit_value = 1;
let (unit_id, product_id) =
- create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id).await;
+ create_associated_barcode(&env, "Liter", "Milk", unit_value, barcode_id.value).await;
- request!(env, buy_barcode(i32::try_from(barcode_id).unwrap()));
+ request!(env, buy_barcode(barcode_id));
- request!(env, buy_barcode(i32::try_from(barcode_id).unwrap()));
+ request!(env, buy_barcode(barcode_id));
env.log("Bought both barcodes");
request!(
env,
consume_barcode(
- i32::try_from(barcode_id).unwrap(),
+ barcode_id,
UnitAmount {
unit: unit_id,
value: 1,
@@ -167,7 +167,7 @@ async fn test_barcode_multiple_buy_and_consume() {
request!(
env,
consume_barcode(
- i32::try_from(barcode_id).unwrap(),
+ barcode_id,
UnitAmount {
unit: unit_id,
value: 1,
@@ -177,9 +177,9 @@ async fn test_barcode_multiple_buy_and_consume() {
env.log("Consumed second barcode");
- let product_amount = request!(env, amount_by_id(product_id.to_string().as_str()));
+ 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, i64::from(0));
+ assert_eq!(product_amount.amount.value, 0);
}
diff --git a/crates/rocie-server/tests/products/mod.rs b/crates/rocie-server/tests/products/mod.rs
index e96ecc9..2ae52fa 100644
--- a/crates/rocie-server/tests/products/mod.rs
+++ b/crates/rocie-server/tests/products/mod.rs
@@ -4,16 +4,15 @@ use rocie_client::{
api_set_product_api::{associate_barcode, register_product},
api_set_unit_api::register_unit,
},
- models::{Barcode, Product, ProductStub, UnitAmount, UnitStub},
+ models::{Barcode, BarcodeId, Product, ProductId, ProductStub, UnitAmount, UnitId, UnitStub},
};
-use uuid::Uuid;
use crate::testenv::{TestEnv, log::request};
mod barcode;
mod register;
-async fn create_product(env: &TestEnv, name: &str) -> Uuid {
+async fn create_product(env: &TestEnv, name: &str) -> ProductId {
request!(
env,
register_product(ProductStub {
@@ -23,7 +22,7 @@ async fn create_product(env: &TestEnv, name: &str) -> Uuid {
},)
)
}
-async fn create_unit(env: &TestEnv, name: &str) -> Uuid {
+async fn create_unit(env: &TestEnv, name: &str) -> UnitId {
request!(
env,
register_unit(UnitStub {
@@ -41,20 +40,21 @@ async fn create_associated_barcode(
product_name: &str,
barcode_value: u32,
barcode_id: u32,
-) -> (Uuid, Uuid) {
+) -> (UnitId, ProductId) {
let unit_id = create_unit(env, unit_name).await;
let product_id = create_product(env, product_name).await;
+ let barcode_id = BarcodeId { value: barcode_id };
request!(
env,
associate_barcode(
- product_id.to_string().as_str(),
+ product_id,
Barcode {
- amount: Box::new(UnitAmount {
+ amount: UnitAmount {
unit: unit_id,
- value: i64::from(barcode_value),
- }),
- id: i32::try_from(barcode_id).unwrap(),
+ value: barcode_value,
+ },
+ id: barcode_id,
},
)
);
@@ -62,8 +62,6 @@ async fn create_associated_barcode(
(unit_id, product_id)
}
-async fn get_product(env: &TestEnv, id: Uuid) -> Product {
- product_by_id(&env.config, id.to_string().as_str())
- .await
- .unwrap()
+async fn get_product(env: &TestEnv, id: ProductId) -> Product {
+ product_by_id(&env.config, id).await.unwrap()
}
diff --git a/crates/rocie-server/tests/products/register.rs b/crates/rocie-server/tests/products/register.rs
index 34f7b5c..15abec4 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 product = request!(env, product_by_id(id.to_string().as_str()));
+ let product = request!(env, product_by_id(id));
assert_eq!(&product.name, "Soy drink");
assert_eq!(