// rocie - An enterprise grocery management system // // Copyright (C) 2026 Benedikt Peetz // SPDX-License-Identifier: GPL-3.0-or-later // // This file is part of Rocie. // // You should have received a copy of the License along with this program. // If not, see . use rocie_client::{ apis::{ 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, UnitPropertyStub, UnitStub, }, }; use crate::testenv::{TestEnv, log::request}; mod barcode; mod query; mod register; async fn create_product(env: &TestEnv, unit_property: UnitPropertyId, name: &str) -> ProductId { request!( env, register_product(ProductStub { description: None, name: name.to_owned(), parent: None, unit_property }) ) } async fn create_unit(env: &TestEnv, name: &str, unit_property: UnitPropertyId) -> UnitId { request!( env, register_unit(UnitStub { description: None, full_name_plural: name.to_owned(), full_name_singular: name.to_owned(), short_name: name.to_owned(), unit_property }) ) } async fn create_associated_barcode( env: &TestEnv, unit_name: &str, product_name: &str, unit_property_name: &str, barcode_value: u32, barcode_id: u32, ) -> (UnitId, ProductId) { let unit_property = request!( env, register_unit_property(UnitPropertyStub { description: None, name: unit_property_name.to_owned() }) ); 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 }; request!( env, associate_barcode( product_id, Barcode { amount: UnitAmount { unit: unit_id, value: barcode_value, }, id: barcode_id, }, ) ); (unit_id, product_id) }