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:
@@ -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