reference a value from other linked table2
This commit is contained in:
@@ -59,10 +59,34 @@ pub fn convert_and_validate_data(
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn accepted_link_value(id: i64, version: i64) -> Result<Value, String> {
|
||||
if id <= 0 || version <= 0 {
|
||||
return Err("Selected link id and version must be positive".into());
|
||||
}
|
||||
Ok(Value {
|
||||
kind: Some(Kind::StructValue(prost_types::Struct {
|
||||
fields: [
|
||||
("id".into(), Value { kind: Some(Kind::StringValue(id.to_string())) }),
|
||||
("version".into(), Value { kind: Some(Kind::StringValue(version.to_string())) }),
|
||||
].into(),
|
||||
})),
|
||||
})
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn accepted_link_selection_keeps_full_precision() {
|
||||
let selected = accepted_link_value(i64::MAX, 3).unwrap();
|
||||
let Some(Kind::StructValue(fields)) = selected.kind else { panic!("Expected a link selection") };
|
||||
assert_eq!(fields.fields["id"].kind, Some(Kind::StringValue(i64::MAX.to_string())));
|
||||
assert_eq!(fields.fields["version"].kind, Some(Kind::StringValue("3".into())));
|
||||
assert!(accepted_link_value(0, 3).is_err());
|
||||
assert!(accepted_link_value(42, -1).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn preserves_large_integers_and_decimals_as_strings() {
|
||||
assert_eq!(
|
||||
|
||||
Reference in New Issue
Block a user