aboutsummaryrefslogtreecommitdiffstats
path: root/crates/rocie-server/tests
diff options
context:
space:
mode:
authorBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-12-09 13:07:14 +0100
committerBenedikt Peetz <benedikt.peetz@b-peetz.de>2025-12-09 13:07:14 +0100
commitc91dce4f77ae12453203f0a28b91efb6533cc095 (patch)
tree4f50e755dff7f717d45309b08f9fe2c8c87f88bd /crates/rocie-server/tests
parentchore(rocie-client): Regenerate (diff)
downloadserver-c91dce4f77ae12453203f0a28b91efb6533cc095.zip
feat(rocie-server): Implement basic user handling and authentication
Diffstat (limited to '')
-rw-r--r--crates/rocie-server/tests/_testenv/init.rs27
-rw-r--r--crates/rocie-server/tests/product_parents/query.rs14
-rw-r--r--crates/rocie-server/tests/product_parents/register.rs8
-rw-r--r--crates/rocie-server/tests/products/barcode.rs26
-rw-r--r--crates/rocie-server/tests/products/mod.rs6
-rw-r--r--crates/rocie-server/tests/products/query.rs16
-rw-r--r--crates/rocie-server/tests/products/register.rs6
-rw-r--r--crates/rocie-server/tests/recipies/mod.rs4
-rw-r--r--crates/rocie-server/tests/tests.rs1
-rw-r--r--crates/rocie-server/tests/units/fetch.rs6
-rw-r--r--crates/rocie-server/tests/units/register.rs6
-rw-r--r--crates/rocie-server/tests/users/mod.rs53
12 files changed, 124 insertions, 49 deletions
diff --git a/crates/rocie-server/tests/_testenv/init.rs b/crates/rocie-server/tests/_testenv/init.rs
index 9cb0b91..5318238 100644
--- a/crates/rocie-server/tests/_testenv/init.rs
+++ b/crates/rocie-server/tests/_testenv/init.rs
@@ -19,9 +19,15 @@ use std::{
process::{self, Stdio},
};
-use rocie_client::apis::configuration::Configuration;
+use rocie_client::{
+ apis::{api_set_no_auth_user_api::provision, configuration::Configuration},
+ models::{LoginInfo, UserStub},
+};
-use crate::{_testenv::Paths, testenv::TestEnv};
+use crate::{
+ _testenv::{Paths, log::request},
+ testenv::TestEnv,
+};
macro_rules! function_name {
() => {{
@@ -105,7 +111,22 @@ fn rocie_server_args(paths: &Paths) -> [&OsStr; 4] {
}
impl TestEnv {
- pub(crate) fn new(name: &'static str) -> TestEnv {
+ pub(crate) async fn new(name: &'static str) -> TestEnv {
+ let env = Self::new_no_login(name);
+
+ request!(
+ env,
+ provision(UserStub {
+ description: Some("Test user, used during test runs".to_string()),
+ name: "rocie".to_string(),
+ password: "server".to_string()
+ })
+ );
+
+ env
+ }
+
+ pub(crate) fn new_no_login(name: &'static str) -> TestEnv {
let test_dir = test_dir(name);
let paths = prepare_files_and_dirs(&test_dir)
diff --git a/crates/rocie-server/tests/product_parents/query.rs b/crates/rocie-server/tests/product_parents/query.rs
index 6d16ca3..635a0ba 100644
--- a/crates/rocie-server/tests/product_parents/query.rs
+++ b/crates/rocie-server/tests/product_parents/query.rs
@@ -1,10 +1,10 @@
use rocie_client::{
apis::{
- api_get_product_api::{products_by_product_parent_id_direct, products_by_product_parent_id_indirect},
- api_get_product_parent_api::{product_parents_toplevel, product_parents_under},
- api_set_product_api::register_product,
- api_set_product_parent_api::register_product_parent,
- api_set_unit_property_api::register_unit_property,
+ api_get_auth_product_api::{products_by_product_parent_id_direct, products_by_product_parent_id_indirect},
+ api_get_auth_product_parent_api::{product_parents_toplevel, product_parents_under},
+ api_set_auth_product_api::register_product,
+ api_set_auth_product_parent_api::register_product_parent,
+ api_set_auth_unit_property_api::register_unit_property,
},
models::{ProductParentStub, ProductStub, UnitPropertyStub},
};
@@ -16,7 +16,7 @@ use crate::{
#[tokio::test]
async fn test_product_parent_query() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let parent_dairy = request!(
env,
@@ -63,7 +63,7 @@ async fn test_product_parent_query() {
#[tokio::test]
async fn test_product_parent_query_product() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let parent_dairy = request!(
env,
diff --git a/crates/rocie-server/tests/product_parents/register.rs b/crates/rocie-server/tests/product_parents/register.rs
index c84ffea..c9e48f2 100644
--- a/crates/rocie-server/tests/product_parents/register.rs
+++ b/crates/rocie-server/tests/product_parents/register.rs
@@ -1,8 +1,8 @@
use rocie_client::{
apis::{
- api_get_product_api::product_by_id, api_set_product_api::register_product,
- api_set_product_parent_api::register_product_parent,
- api_set_unit_property_api::register_unit_property,
+ api_get_auth_product_api::product_by_id, api_set_auth_product_api::register_product,
+ api_set_auth_product_parent_api::register_product_parent,
+ api_set_auth_unit_property_api::register_unit_property,
},
models::{ProductParentStub, ProductStub, UnitPropertyStub},
};
@@ -14,7 +14,7 @@ use crate::{
#[tokio::test]
async fn test_product_parent_register_roundtrip() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let parent_dairy = request!(
env,
diff --git a/crates/rocie-server/tests/products/barcode.rs b/crates/rocie-server/tests/products/barcode.rs
index 5335eb7..7b48ab7 100644
--- a/crates/rocie-server/tests/products/barcode.rs
+++ b/crates/rocie-server/tests/products/barcode.rs
@@ -1,10 +1,10 @@
use rocie_client::{
apis::{
- api_get_inventory_api::amount_by_id,
- api_set_barcode_api::{buy_barcode, consume_barcode},
- api_set_product_api::{associate_barcode, register_product},
- api_set_unit_api::register_unit,
- api_set_unit_property_api::register_unit_property,
+ api_get_auth_inventory_api::amount_by_id,
+ api_set_auth_barcode_api::{buy_barcode, consume_barcode},
+ api_set_auth_product_api::{associate_barcode, register_product},
+ api_set_auth_unit_api::register_unit,
+ api_set_auth_unit_property_api::register_unit_property,
},
models::{Barcode, BarcodeId, ProductStub, UnitAmount, UnitPropertyStub, UnitStub},
};
@@ -17,7 +17,7 @@ use crate::{
#[tokio::test]
async fn test_barcode_buy() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let barcode_id = 23;
let unit_value = 1;
@@ -36,7 +36,7 @@ async fn test_barcode_buy() {
#[tokio::test]
async fn test_barcode_buy_multiple() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let barcode_id = 23;
let unit_value = 1;
@@ -55,7 +55,7 @@ async fn test_barcode_buy_multiple() {
#[tokio::test]
async fn test_barcode_consume() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let barcode_id = BarcodeId { value: 23 };
let unit_value = 1;
@@ -92,7 +92,7 @@ async fn test_barcode_consume() {
#[tokio::test]
async fn test_barcode_consume_error() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let barcode_id = BarcodeId { value: 23 };
let unit_value = 1;
@@ -131,7 +131,7 @@ async fn test_barcode_consume_error() {
#[tokio::test]
async fn test_barcode_consume_error_other() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let barcode_id = BarcodeId { value: 23 };
let unit_value = 1;
@@ -181,7 +181,7 @@ async fn test_barcode_consume_error_other() {
#[tokio::test]
async fn test_barcode_multiple_buy_and_consume() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let barcode_id = BarcodeId { value: 23 };
let unit_value = 1;
@@ -237,7 +237,7 @@ async fn test_barcode_multiple_buy_and_consume() {
#[tokio::test]
async fn test_barcode_fill_up() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let milk_id = BarcodeId { value: 23 };
let bread_id = BarcodeId { value: 24 };
@@ -254,7 +254,7 @@ async fn test_barcode_fill_up() {
#[tokio::test]
async fn test_barcode_associate_false_unit() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let unit_property_mass = request!(
env,
diff --git a/crates/rocie-server/tests/products/mod.rs b/crates/rocie-server/tests/products/mod.rs
index ee139f0..e503684 100644
--- a/crates/rocie-server/tests/products/mod.rs
+++ b/crates/rocie-server/tests/products/mod.rs
@@ -1,8 +1,8 @@
use rocie_client::{
apis::{
- api_set_product_api::{associate_barcode, register_product},
- api_set_unit_api::register_unit,
- api_set_unit_property_api::register_unit_property,
+ api_set_auth_product_api::{associate_barcode, register_product},
+ api_set_auth_unit_api::register_unit,
+ api_set_auth_unit_property_api::register_unit_property,
},
models::{
Barcode, BarcodeId, ProductId, ProductStub, UnitAmount, UnitId, UnitPropertyId,
diff --git a/crates/rocie-server/tests/products/query.rs b/crates/rocie-server/tests/products/query.rs
index 8adfbb5..b2095cb 100644
--- a/crates/rocie-server/tests/products/query.rs
+++ b/crates/rocie-server/tests/products/query.rs
@@ -1,7 +1,7 @@
use rocie_client::{
apis::{
- api_get_product_api::{product_by_name, product_suggestion_by_name},
- api_set_unit_property_api::register_unit_property,
+ api_get_auth_product_api::{product_by_name, product_suggestion_by_name},
+ api_set_auth_unit_property_api::register_unit_property,
},
models::UnitPropertyStub,
};
@@ -14,7 +14,7 @@ use crate::{
#[tokio::test]
#[expect(clippy::similar_names)]
async fn test_product_name_suggestions() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let unit_property = request!(
env,
@@ -46,7 +46,7 @@ async fn test_product_name_suggestions() {
#[tokio::test]
async fn test_product_name_suggest_space() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let unit_property = request!(
env,
@@ -68,7 +68,7 @@ async fn test_product_name_suggest_space() {
#[tokio::test]
async fn test_product_name_lookup_space() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let unit_property = request!(
env,
@@ -87,7 +87,7 @@ async fn test_product_name_lookup_space() {
#[tokio::test]
async fn test_product_name_lookup_fancy() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let unit_property = request!(
env,
@@ -106,7 +106,7 @@ async fn test_product_name_lookup_fancy() {
#[tokio::test]
async fn test_product_name_lookup_emoji() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let unit_property = request!(
env,
@@ -125,7 +125,7 @@ async fn test_product_name_lookup_emoji() {
#[tokio::test]
async fn test_product_name_lookup_plus() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let unit_property = request!(
env,
diff --git a/crates/rocie-server/tests/products/register.rs b/crates/rocie-server/tests/products/register.rs
index bae7bc7..2d4bf7e 100644
--- a/crates/rocie-server/tests/products/register.rs
+++ b/crates/rocie-server/tests/products/register.rs
@@ -1,7 +1,7 @@
use rocie_client::{
apis::{
- api_get_product_api::product_by_id, api_set_product_api::register_product,
- api_set_unit_property_api::register_unit_property,
+ api_get_auth_product_api::product_by_id, api_set_auth_product_api::register_product,
+ api_set_auth_unit_property_api::register_unit_property,
},
models::{ProductStub, UnitPropertyStub},
};
@@ -13,7 +13,7 @@ use crate::{
#[tokio::test]
async fn test_product_register_roundtrip() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let unit_property = request!(
env,
diff --git a/crates/rocie-server/tests/recipies/mod.rs b/crates/rocie-server/tests/recipies/mod.rs
index e8aa3c2..dfc8983 100644
--- a/crates/rocie-server/tests/recipies/mod.rs
+++ b/crates/rocie-server/tests/recipies/mod.rs
@@ -1,5 +1,5 @@
use rocie_client::{
- apis::{api_get_recipe_api::recipe_by_id, api_set_recipe_api::add_recipe},
+ apis::{api_get_auth_recipe_api::recipe_by_id, api_set_auth_recipe_api::add_recipe},
models::RecipeStub,
};
@@ -7,7 +7,7 @@ use crate::testenv::{TestEnv, init::function_name, log::request};
#[tokio::test]
async fn test_recipe_roundtrip() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let recipe_id = request!(
env,
diff --git a/crates/rocie-server/tests/tests.rs b/crates/rocie-server/tests/tests.rs
index 3759042..4a218d1 100644
--- a/crates/rocie-server/tests/tests.rs
+++ b/crates/rocie-server/tests/tests.rs
@@ -7,3 +7,4 @@ mod products;
mod product_parents;
mod units;
mod recipies;
+mod users;
diff --git a/crates/rocie-server/tests/units/fetch.rs b/crates/rocie-server/tests/units/fetch.rs
index b0bfffb..a0ffd9b 100644
--- a/crates/rocie-server/tests/units/fetch.rs
+++ b/crates/rocie-server/tests/units/fetch.rs
@@ -1,7 +1,7 @@
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,
+ api_get_auth_unit_api::units_by_property_id, api_set_auth_unit_api::register_unit,
+ api_set_auth_unit_property_api::register_unit_property,
},
models::{UnitPropertyStub, UnitStub},
};
@@ -10,7 +10,7 @@ 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 env = TestEnv::new(function_name!()).await;
let unit_property = request!(
env,
diff --git a/crates/rocie-server/tests/units/register.rs b/crates/rocie-server/tests/units/register.rs
index 8181c25..e725a5c 100644
--- a/crates/rocie-server/tests/units/register.rs
+++ b/crates/rocie-server/tests/units/register.rs
@@ -1,7 +1,7 @@
use rocie_client::{
apis::{
- api_get_unit_api::unit_by_id, api_set_unit_api::register_unit,
- api_set_unit_property_api::register_unit_property,
+ api_get_auth_unit_api::unit_by_id, api_set_auth_unit_api::register_unit,
+ api_set_auth_unit_property_api::register_unit_property,
},
models::{UnitPropertyStub, UnitStub},
};
@@ -13,7 +13,7 @@ use crate::{
#[tokio::test]
async fn test_unit_register_roundtrip() {
- let env = TestEnv::new(function_name!());
+ let env = TestEnv::new(function_name!()).await;
let unit_property = request!(
env,
diff --git a/crates/rocie-server/tests/users/mod.rs b/crates/rocie-server/tests/users/mod.rs
new file mode 100644
index 0000000..eaa387f
--- /dev/null
+++ b/crates/rocie-server/tests/users/mod.rs
@@ -0,0 +1,53 @@
+use rocie_client::{
+ apis::{
+ api_get_no_auth_user_api::user_by_id,
+ api_set_auth_user_api::register_user,
+ api_set_no_auth_user_api::{login, logout},
+ },
+ models::{LoginInfo, UserStub},
+};
+
+use crate::testenv::{TestEnv, init::function_name, log::request};
+
+#[tokio::test]
+async fn test_register_user() {
+ let env = TestEnv::new_no_login(function_name!());
+
+ let user_id = request!(
+ env,
+ register_user(UserStub {
+ description: Some("Myself".to_string()),
+ name: "me".to_string(),
+ password: "hunter14".to_string()
+ })
+ );
+
+ request!(
+ @expect_error "The password is wrong"
+ env,
+ login(LoginInfo {
+ id: user_id,
+ password: "hunter13".to_owned()
+ })
+ );
+
+ request!(
+ env,
+ login(LoginInfo {
+ id: user_id,
+ password: "hunter14".to_owned()
+ })
+ );
+
+ let user = request!(env, user_by_id(user_id));
+
+ assert_eq!(&user.name, "me");
+ assert_eq!(user.description.as_deref(), Some("Myself"));
+
+ request!(env, logout());
+ request!(
+ @expect_error "We are not logged in anymore"
+ env,
+ user_by_id(user_id)
+ );
+}