Allowed optional entry checks.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s
This commit is contained in:
parent
eb73a31014
commit
ad3ad3295f
@ -1109,16 +1109,20 @@ impl FieldSetting {
|
|||||||
&self.default_setting
|
&self.default_setting
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check(&self, value: &Field) -> Result<Field, MTTError> {
|
fn check(&self, value: Option<Field>) -> Result<Field, MTTError> {
|
||||||
let output = value.clone();
|
match value {
|
||||||
let vft: FieldType = value.into();
|
Some(data) => {
|
||||||
if vft != self.fieldtype {
|
let vft: FieldType = (&data).into();
|
||||||
return Err(MTTError::DocumentFieldWrongDataType(
|
if vft != self.fieldtype {
|
||||||
self.fieldtype.clone(),
|
return Err(MTTError::DocumentFieldWrongDataType(
|
||||||
vft,
|
self.fieldtype.clone(),
|
||||||
));
|
vft,
|
||||||
|
));
|
||||||
|
}
|
||||||
|
Ok(data.clone())
|
||||||
|
}
|
||||||
|
None => Err(MTTError::DocumentFieldMissing("".to_string())),
|
||||||
}
|
}
|
||||||
Ok(output)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1130,7 +1134,7 @@ mod fieldsettings {
|
|||||||
fn checks_field_type() {
|
fn checks_field_type() {
|
||||||
let fset = FieldSetting::new(FieldType::Uuid);
|
let fset = FieldSetting::new(FieldType::Uuid);
|
||||||
let value: Field = Uuid::new_v4().into();
|
let value: Field = Uuid::new_v4().into();
|
||||||
match fset.check(&value) {
|
match fset.check(Some(value.clone())) {
|
||||||
Ok(data) => assert_eq!(data, value),
|
Ok(data) => assert_eq!(data, value),
|
||||||
Err(err) => unreachable!("got {:?}: should have gotten a value", err),
|
Err(err) => unreachable!("got {:?}: should have gotten a value", err),
|
||||||
}
|
}
|
||||||
@ -1140,7 +1144,7 @@ mod fieldsettings {
|
|||||||
fn checks_for_bad_field_type() {
|
fn checks_for_bad_field_type() {
|
||||||
let fset = FieldSetting::new(FieldType::Uuid);
|
let fset = FieldSetting::new(FieldType::Uuid);
|
||||||
let value: Field = "text".into();
|
let value: Field = "text".into();
|
||||||
match fset.check(&value) {
|
match fset.check(Some(value)) {
|
||||||
Ok(data) => unreachable!("got {:?}: should have gotten an error", data),
|
Ok(data) => unreachable!("got {:?}: should have gotten an error", data),
|
||||||
Err(err) => match err {
|
Err(err) => match err {
|
||||||
MTTError::DocumentFieldWrongDataType(expected, got) => {
|
MTTError::DocumentFieldWrongDataType(expected, got) => {
|
||||||
@ -1152,6 +1156,18 @@ mod fieldsettings {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn no_default_returns_error() {
|
||||||
|
let fset = FieldSetting::new(FieldType::Uuid);
|
||||||
|
match fset.check(None) {
|
||||||
|
Ok(data) => unreachable!("got {:?}: should have gotten an error", data),
|
||||||
|
Err(err) => match err {
|
||||||
|
MTTError::DocumentFieldMissing(data) => assert_eq!(data, ""),
|
||||||
|
_ => unreachable!("got {:?}: should have gotten a value", err),
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_field_type_be_assigned() {
|
fn can_field_type_be_assigned() {
|
||||||
let ftypes = [FieldType::StaticString, FieldType::Uuid];
|
let ftypes = [FieldType::StaticString, FieldType::Uuid];
|
||||||
@ -1820,7 +1836,7 @@ impl DocumentFile {
|
|||||||
let doc = self.docs.get_mut(oid).unwrap();
|
let doc = self.docs.get_mut(oid).unwrap();
|
||||||
for (key, value) in update.get_values().iter() {
|
for (key, value) in update.get_values().iter() {
|
||||||
match self.docdef.get_field(key) {
|
match self.docdef.get_field(key) {
|
||||||
Ok(fset) => match fset.check(value) {
|
Ok(fset) => match fset.check(Some(value.clone())) {
|
||||||
Ok(field) => doc.add_field(key.clone(), field.clone()),
|
Ok(field) => doc.add_field(key.clone(), field.clone()),
|
||||||
Err(err) => return err.into(),
|
Err(err) => return err.into(),
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user