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
|
use rocie_client::{
apis::{
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},
};
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!()).await;
let unit_property = request!(
env,
register_unit_property(UnitPropertyStub {
description: Some("The total mass of a product".to_owned()),
name: "Mass".to_owned()
})
);
request!(
env,
register_unit(UnitStub {
description: Some("Fancy new unit".to_owned()),
full_name_plural: "Grams".to_owned(),
full_name_singular: "Gram".to_owned(),
short_name: "g".to_owned(),
unit_property,
})
);
request!(
env,
register_unit(UnitStub {
description: Some("Better new unit (we should make it SI)".to_owned()),
full_name_plural: "Kilograms".to_owned(),
full_name_singular: "Kilogram".to_owned(),
short_name: "kg".to_owned(),
unit_property,
})
);
let unit_property2 = request!(
env,
register_unit_property(UnitPropertyStub {
description: Some("The total volume of a product".to_owned()),
name: "Volume".to_owned()
})
);
request!(
env,
register_unit(UnitStub {
description: Some("Fancy new unit".to_owned()),
full_name_plural: "Liter".to_owned(),
full_name_singular: "Liter".to_owned(),
short_name: "l".to_owned(),
unit_property: unit_property2,
})
);
request!(
env,
register_unit(UnitStub {
description: Some("Better new unit (we should make it SI)".to_owned()),
full_name_plural: "Mililiters".to_owned(),
full_name_singular: "Mililiter".to_owned(),
short_name: "ml".to_owned(),
unit_property: unit_property2,
})
);
let units = request!(env, units_by_property_id(unit_property));
let other_units = request!(env, units_by_property_id(unit_property2));
assert_eq!(
units
.iter()
.map(|unit| unit.short_name.clone())
.collect::<Vec<_>>(),
vec!["g".to_owned(), "kg".to_owned(),]
);
assert_eq!(
other_units
.iter()
.map(|unit| unit.short_name.clone())
.collect::<Vec<_>>(),
vec!["l".to_owned(), "ml".to_owned(),]
);
}
|