1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
|
// rocie - An enterprise grocery management system
//
// Copyright (C) 2026 Benedikt Peetz <benedikt.peetz@b-peetz.de>
// 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 <https://www.gnu.org/licenses/gpl-3.0.txt>.
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)
}
|