Added multilingual test to triggers.
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:
@@ -295,8 +295,8 @@ impl DocDef {
|
||||
&mut self.field_names
|
||||
}
|
||||
|
||||
pub fn add_field(&mut self, name: Name, ftype: FieldType) {
|
||||
let id = self.field_names.add_names([name].to_vec()).unwrap();
|
||||
pub fn add_field(&mut self, names: Vec<Name>, ftype: FieldType) {
|
||||
let id = self.field_names.add_names(names).unwrap();
|
||||
self.fields.insert(id, FieldSetting::new(ftype));
|
||||
}
|
||||
|
||||
@@ -418,7 +418,7 @@ mod docdefs {
|
||||
let mut docdef = DocDef::new(docname);
|
||||
let name = Name::english(Uuid::new_v4().to_string().as_str());
|
||||
let field_type = FieldType::Uuid;
|
||||
docdef.add_field(name.clone(), field_type.clone());
|
||||
docdef.add_field(vec![name.clone()], field_type.clone());
|
||||
let result = docdef.get_field(name).unwrap();
|
||||
match result.validate(&Uuid::new_v4().into()) {
|
||||
Ok(_) => {}
|
||||
@@ -434,8 +434,8 @@ mod docdefs {
|
||||
let field2 = Name::english("field2");
|
||||
let ftype1 = FieldType::Uuid;
|
||||
let ftype2 = FieldType::StaticString;
|
||||
docdef.add_field(field1.clone(), ftype1.clone());
|
||||
docdef.add_field(field2.clone(), ftype2.clone());
|
||||
docdef.add_field(vec![field1.clone()], ftype1.clone());
|
||||
docdef.add_field(vec![field2.clone()], ftype2.clone());
|
||||
assert_eq!(docdef.get_field_type(&field1).unwrap(), &ftype1);
|
||||
assert_eq!(docdef.get_field_type(&field2).unwrap(), &ftype2);
|
||||
}
|
||||
@@ -461,7 +461,7 @@ mod docdefs {
|
||||
let names = ["one", "two", "three"];
|
||||
let field_type = FieldType::StaticString;
|
||||
for name in names.iter() {
|
||||
docdef.add_field(Name::english(name), field_type.clone());
|
||||
docdef.add_field(vec![Name::english(name)], field_type.clone());
|
||||
}
|
||||
for name in names.iter() {
|
||||
let result = docdef.get_field(Name::english(name)).unwrap();
|
||||
@@ -477,7 +477,7 @@ mod docdefs {
|
||||
let docname = Name::english("something");
|
||||
let mut docdef = DocDef::new(docname);
|
||||
let name = Name::english("defaultfunction");
|
||||
docdef.add_field(name.clone(), FieldType::StaticString);
|
||||
docdef.add_field(vec![name.clone()], FieldType::StaticString);
|
||||
docdef.set_default(&name, FieldType::StaticString).unwrap();
|
||||
match docdef.get_field(name).unwrap().validate(&Field::None) {
|
||||
Ok(data) => match data {
|
||||
@@ -507,7 +507,7 @@ mod docdefs {
|
||||
let docname = Name::english("something");
|
||||
let mut docdef = DocDef::new(docname);
|
||||
let name = Name::english("defaultvalue");
|
||||
docdef.add_field(name.clone(), FieldType::Uuid);
|
||||
docdef.add_field(vec![name.clone()], FieldType::Uuid);
|
||||
match docdef.set_default(&name, "fred") {
|
||||
Ok(data) => unreachable!("got {:?}, should be an error", data),
|
||||
Err(err) => match err.get_error_ids().back().unwrap() {
|
||||
|
||||
@@ -20,30 +20,46 @@ impl Session {
|
||||
pub fn doc_names() -> Vec<Name> {
|
||||
let mut names = Vec::new();
|
||||
names.push(Name::english("session"));
|
||||
names.push(Name::japanese("セッション"));
|
||||
names
|
||||
}
|
||||
|
||||
pub fn id_field_names() -> Vec<Name> {
|
||||
let mut names = Vec::new();
|
||||
names.push(Name::english("id"));
|
||||
names.push(Name::japanese("身元"));
|
||||
names
|
||||
}
|
||||
|
||||
pub fn expire_field_names() -> Vec<Name> {
|
||||
let mut names = Vec::new();
|
||||
names.push(Name::english("expire"));
|
||||
names.push(Name::japanese("期限切れ"));
|
||||
names
|
||||
}
|
||||
|
||||
pub fn document_definition() -> DocDef {
|
||||
let name_id = Self::id_field_names()[0].clone();
|
||||
let name_expire = Self::expire_field_names()[0].clone();
|
||||
|
||||
let mut docdef = DocDef::with_names(Self::doc_names());
|
||||
|
||||
let mut calc = Calculation::new(Operand::Add);
|
||||
calc.add_value(FieldType::DateTime).unwrap();
|
||||
calc.add_value(Duration::from_hours(1)).unwrap();
|
||||
|
||||
let name_id = Name::english("id");
|
||||
docdef.add_field(name_id.clone(), FieldType::Uuid);
|
||||
docdef.add_field(Self::id_field_names(), FieldType::Uuid);
|
||||
docdef.set_default(&name_id, FieldType::Uuid).unwrap();
|
||||
docdef.add_index(&name_id, IndexType::Unique).unwrap();
|
||||
|
||||
let name_expire = Name::english("expire");
|
||||
docdef.add_field(name_expire.clone(), FieldType::DateTime);
|
||||
docdef.add_field(Self::expire_field_names(), FieldType::DateTime);
|
||||
docdef.set_default(&name_expire, calc.clone()).unwrap();
|
||||
docdef.add_index(&name_expire, IndexType::Index).unwrap();
|
||||
|
||||
let mut update = Update::new(Session::doc_names()[0].clone());
|
||||
update
|
||||
.get_values_mut()
|
||||
.add_field(name_expire.clone(), calc.clone());
|
||||
.add_field(Self::expire_field_names()[0].clone(), calc.clone());
|
||||
let path = Path::new(
|
||||
Include::All,
|
||||
Include::Just(Session::doc_names()[0].clone().into()),
|
||||
@@ -59,7 +75,7 @@ impl Session {
|
||||
.add_value(CalcValue::Existing(FieldType::DateTime))
|
||||
.unwrap();
|
||||
delete_calc.add_value(FieldType::DateTime).unwrap();
|
||||
delete_qry.add(name_expire.clone(), delete_calc);
|
||||
delete_qry.add(Self::expire_field_names()[0].clone(), delete_calc);
|
||||
let delete_func = DocFuncType::Trigger(delete.into());
|
||||
docdef.add_route(Clock::get_path(), delete_func);
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ fn can_new_documents_be_added() {
|
||||
data.insert(i.into());
|
||||
}
|
||||
let mut docdef = DocDef::new(doc_name.clone());
|
||||
docdef.add_field(field_name.clone(), FieldType::Integer);
|
||||
docdef.add_field(vec![field_name.clone()], FieldType::Integer);
|
||||
mtt.create_document(docdef);
|
||||
for item in data.iter() {
|
||||
let mut add = Addition::new(doc_name.clone());
|
||||
|
||||
@@ -32,7 +32,7 @@ impl TestDocument {
|
||||
let mut fnames = Vec::new();
|
||||
for i in 0..fields.len() {
|
||||
let name = Name::english(format!("field{}", i).as_str());
|
||||
docdef.add_field(name.clone(), fields[i].clone());
|
||||
docdef.add_field(vec![name.clone()], fields[i].clone());
|
||||
fnames.push(name);
|
||||
}
|
||||
Self {
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
mod support;
|
||||
|
||||
use morethantext::{
|
||||
Action, CalcValue, Calculation, Delete, DocFuncType, FieldType, Include, MoreThanText, Name,
|
||||
Operand, Path, Query, TestMoreThanText, Update,
|
||||
Action, Addition, CalcValue, Calculation, Delete, DocDef, DocFuncType, FieldType, Include,
|
||||
MoreThanText, Name, Operand, Path, Query, TestMoreThanText, Update,
|
||||
};
|
||||
use support::TestDocument;
|
||||
|
||||
@@ -168,3 +168,61 @@ fn can_a_trigger_from_another_document_be_used() {
|
||||
selected.into()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_triggers_work_with_multiple_languages() {
|
||||
let initial_data = 1;
|
||||
let doc_names = vec![Name::english("test"), Name::japanese("テスト")];
|
||||
let field_names = vec![Name::english("something"), Name::japanese("何か")];
|
||||
let mut docdef = DocDef::with_names(doc_names.clone());
|
||||
docdef.add_field(field_names.clone(), FieldType::Integer);
|
||||
let mut calc = Calculation::new(Operand::Add);
|
||||
calc.add_value(CalcValue::Existing(FieldType::Integer))
|
||||
.unwrap();
|
||||
calc.add_value(1).unwrap();
|
||||
let mut update = Update::new(doc_names[0].clone());
|
||||
update.add_field(field_names[0].clone(), calc);
|
||||
let path = Path::new(
|
||||
Include::All,
|
||||
Include::Just(doc_names[0].clone().into()),
|
||||
Include::Just(Action::OnQuery),
|
||||
);
|
||||
let function = DocFuncType::ExistingQuery(update.into());
|
||||
docdef.add_route(path, function);
|
||||
let mut test_env = TestMoreThanText::new();
|
||||
let mut mtt = test_env.get_morethantext();
|
||||
mtt.create_document(docdef).unwrap();
|
||||
let mut data = Addition::new(doc_names[0].clone());
|
||||
data.add_field(field_names[0].clone(), initial_data.clone());
|
||||
mtt.records(data).unwrap();
|
||||
let mut qry_calc = Calculation::new(Operand::LessThan);
|
||||
qry_calc.add_value(0).unwrap();
|
||||
qry_calc
|
||||
.add_value(CalcValue::Existing(FieldType::Integer))
|
||||
.unwrap();
|
||||
let path = Path::new(
|
||||
Include::All,
|
||||
Include::Just(doc_names[0].clone().into()),
|
||||
Include::Just(Action::OnUpdate),
|
||||
);
|
||||
test_env.register_channel(vec![path]);
|
||||
for i in 0..doc_names.len() {
|
||||
let holder: i128 = i.clone().try_into().unwrap();
|
||||
let mut query = Query::new(doc_names[i].clone());
|
||||
query.add(field_names[i].clone(), qry_calc.clone());
|
||||
let qry_result = mtt.records(query.clone()).unwrap();
|
||||
assert_eq!(qry_result.len(), 1, "got {:?} from {:?}", qry_result, query);
|
||||
let qry_rec = qry_result.iter().last().unwrap();
|
||||
assert_eq!(
|
||||
qry_rec.get(field_names[i].clone()).unwrap(),
|
||||
(initial_data + holder).into()
|
||||
);
|
||||
let onupdate = test_env.get_trigger_records(Action::OnUpdate);
|
||||
assert_eq!(onupdate.len(), 1, "got {:?}", onupdate);
|
||||
let on_rec = onupdate.iter().last().unwrap();
|
||||
assert_eq!(
|
||||
on_rec.get(field_names[i].clone()).unwrap(),
|
||||
(initial_data + holder + 1).into()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user