Corrected trigger tests.
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:
@@ -93,22 +93,29 @@ fn are_session_ids_unique_on_update() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn does_expire_update_on_query() {
|
fn does_expire_updates_on_query() {
|
||||||
let mut mtt = MoreThanText::new();
|
let id_name = Name::english("id");
|
||||||
|
let expire_name = Name::english("expire");
|
||||||
|
let mut test_env = TestMoreThanText::new();
|
||||||
|
let mut mtt = test_env.get_morethantext();
|
||||||
let id = mtt.validate_session(None);
|
let id = mtt.validate_session(None);
|
||||||
let start_time = Utc::now() + Duration::from_secs(3600);
|
let path = Path::new(
|
||||||
|
Include::All,
|
||||||
|
Include::Just(doc_name().into()),
|
||||||
|
Include::Just(Action::OnUpdate),
|
||||||
|
);
|
||||||
|
test_env.register_channel(vec![path]);
|
||||||
|
let start_time: Field = (Utc::now() + Duration::from_secs(3600)).into();
|
||||||
mtt.validate_session(Some(id.to_string()));
|
mtt.validate_session(Some(id.to_string()));
|
||||||
let end_time = Utc::now() + Duration::from_secs(3601);
|
let end_time: Field = (Utc::now() + Duration::from_secs(3601)).into();
|
||||||
let rec = get_session(&mut mtt, &id).unwrap();
|
let result = test_env.get_trigger_records(Action::OnUpdate);
|
||||||
let holder = rec.get(Name::english("expire")).unwrap();
|
assert_eq!(result.len(), 1);
|
||||||
match holder {
|
let rec = result.iter().last().unwrap();
|
||||||
Field::DateTime(data) => {
|
assert_eq!(rec.get(&id_name).unwrap(), id.into());
|
||||||
|
let data = rec.get(&expire_name).unwrap();
|
||||||
assert!(data > start_time, "expire should be after {:?}", start_time);
|
assert!(data > start_time, "expire should be after {:?}", start_time);
|
||||||
assert!(data < end_time, "expire should be before {:?}", end_time);
|
assert!(data < end_time, "expire should be before {:?}", end_time);
|
||||||
}
|
}
|
||||||
_ => unreachable!("got {:?} should have been date time", holder),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn are_expired_sessions_removed() {
|
fn are_expired_sessions_removed() {
|
||||||
|
|||||||
@@ -11,7 +11,8 @@ fn can_a_trigger_cause_an_update() {
|
|||||||
let data0 = 0;
|
let data0 = 0;
|
||||||
let data1 = 0;
|
let data1 = 0;
|
||||||
let data1_expected = 1;
|
let data1_expected = 1;
|
||||||
let mut mtt = MoreThanText::new();
|
let mut test_env = TestMoreThanText::new();
|
||||||
|
let mut mtt = test_env.get_morethantext();
|
||||||
let test_doc = TestDocument::new(vec![FieldType::Integer, FieldType::Integer]);
|
let test_doc = TestDocument::new(vec![FieldType::Integer, FieldType::Integer]);
|
||||||
let mut calc = Calculation::new(Operand::Add);
|
let mut calc = Calculation::new(Operand::Add);
|
||||||
calc.add_value(CalcValue::Existing(FieldType::Integer))
|
calc.add_value(CalcValue::Existing(FieldType::Integer))
|
||||||
@@ -29,6 +30,12 @@ fn can_a_trigger_cause_an_update() {
|
|||||||
docdef.add_route(path, function);
|
docdef.add_route(path, function);
|
||||||
mtt.create_document(docdef);
|
mtt.create_document(docdef);
|
||||||
test_doc.populate(&mut mtt, vec![data0.clone(), data1.clone()]);
|
test_doc.populate(&mut mtt, vec![data0.clone(), data1.clone()]);
|
||||||
|
let path = Path::new(
|
||||||
|
Include::All,
|
||||||
|
Include::Just(test_doc.get_doc_name().into()),
|
||||||
|
Include::Just(Action::OnUpdate),
|
||||||
|
);
|
||||||
|
test_env.register_channel(vec![path]);
|
||||||
let first_qry = mtt.records(Query::new(test_doc.get_doc_name())).unwrap();
|
let first_qry = mtt.records(Query::new(test_doc.get_doc_name())).unwrap();
|
||||||
assert_eq!(first_qry.len(), 1);
|
assert_eq!(first_qry.len(), 1);
|
||||||
let first_rec = first_qry.iter().last().unwrap();
|
let first_rec = first_qry.iter().last().unwrap();
|
||||||
@@ -40,17 +47,16 @@ fn can_a_trigger_cause_an_update() {
|
|||||||
first_rec.get(test_doc.get_field_name(1)).unwrap(),
|
first_rec.get(test_doc.get_field_name(1)).unwrap(),
|
||||||
data1.clone().into()
|
data1.clone().into()
|
||||||
);
|
);
|
||||||
let second_qry = mtt.records(Query::new(test_doc.get_doc_name())).unwrap();
|
let result = test_env.get_trigger_records(Action::OnUpdate);
|
||||||
assert_eq!(second_qry.len(), 1);
|
assert_eq!(result.len(), 1);
|
||||||
let second_rec = second_qry.iter().last().unwrap();
|
let rec = result.iter().last().unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
second_rec.get(test_doc.get_field_name(0)).unwrap(),
|
rec.get(test_doc.get_field_name(0)).unwrap(),
|
||||||
data0.clone().into()
|
data0.clone().into()
|
||||||
);
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
second_rec.get(test_doc.get_field_name(1)).unwrap(),
|
rec.get(test_doc.get_field_name(1)).unwrap(),
|
||||||
data1_expected.clone().into(),
|
data1_expected.clone().into()
|
||||||
"not updated"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -64,7 +70,8 @@ fn can_trigger_update_specific_record() {
|
|||||||
for i in 0..count {
|
for i in 0..count {
|
||||||
input.push(vec![i.clone(), initial_data.clone()]);
|
input.push(vec![i.clone(), initial_data.clone()]);
|
||||||
}
|
}
|
||||||
let mut mtt = MoreThanText::new();
|
let mut test_env = TestMoreThanText::new();
|
||||||
|
let mut mtt = test_env.get_morethantext();
|
||||||
let test_doc = TestDocument::new(vec![FieldType::Integer, FieldType::Integer]);
|
let test_doc = TestDocument::new(vec![FieldType::Integer, FieldType::Integer]);
|
||||||
let mut calc = Calculation::new(Operand::Add);
|
let mut calc = Calculation::new(Operand::Add);
|
||||||
calc.add_value(CalcValue::Existing(FieldType::Integer))
|
calc.add_value(CalcValue::Existing(FieldType::Integer))
|
||||||
@@ -89,6 +96,12 @@ fn can_trigger_update_specific_record() {
|
|||||||
qry_calc.add_value(selected.clone()).unwrap();
|
qry_calc.add_value(selected.clone()).unwrap();
|
||||||
let mut qry = Query::new(test_doc.get_doc_name());
|
let mut qry = Query::new(test_doc.get_doc_name());
|
||||||
qry.add(test_doc.get_field_name(0), qry_calc);
|
qry.add(test_doc.get_field_name(0), qry_calc);
|
||||||
|
let path = Path::new(
|
||||||
|
Include::All,
|
||||||
|
Include::Just(test_doc.get_doc_name().into()),
|
||||||
|
Include::Just(Action::OnUpdate),
|
||||||
|
);
|
||||||
|
test_env.register_channel(vec![path]);
|
||||||
let first_result = mtt.records(qry).unwrap();
|
let first_result = mtt.records(qry).unwrap();
|
||||||
assert_eq!(first_result.len(), 1);
|
assert_eq!(first_result.len(), 1);
|
||||||
let first_rec = first_result.iter().last().unwrap();
|
let first_rec = first_result.iter().last().unwrap();
|
||||||
@@ -100,21 +113,17 @@ fn can_trigger_update_specific_record() {
|
|||||||
first_rec.get(test_doc.get_field_name(1)).unwrap(),
|
first_rec.get(test_doc.get_field_name(1)).unwrap(),
|
||||||
initial_data.clone().into()
|
initial_data.clone().into()
|
||||||
);
|
);
|
||||||
let second_result = mtt.records(Query::new(test_doc.get_doc_name())).unwrap();
|
let result = test_env.get_trigger_records(Action::OnUpdate);
|
||||||
assert_eq!(second_result.len(), count.try_into().unwrap());
|
assert_eq!(result.len(), 1);
|
||||||
for rec in second_result.iter() {
|
let rec = result.iter().last().unwrap();
|
||||||
if rec.get(test_doc.get_field_name(0)).unwrap() == selected.clone().into() {
|
assert_eq!(
|
||||||
|
rec.get(test_doc.get_field_name(0)).unwrap(),
|
||||||
|
selected.clone().into()
|
||||||
|
);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
rec.get(test_doc.get_field_name(1)).unwrap(),
|
rec.get(test_doc.get_field_name(1)).unwrap(),
|
||||||
expected.clone().into()
|
expected.clone().into()
|
||||||
);
|
);
|
||||||
} else {
|
|
||||||
assert_eq!(
|
|
||||||
rec.get(test_doc.get_field_name(1)).unwrap(),
|
|
||||||
initial_data.clone().into()
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -125,7 +134,7 @@ fn can_a_trigger_from_another_document_be_used() {
|
|||||||
for i in 0..count {
|
for i in 0..count {
|
||||||
input.push(vec![i]);
|
input.push(vec![i]);
|
||||||
}
|
}
|
||||||
let test_env = TestMoreThanText::new();
|
let mut test_env = TestMoreThanText::new();
|
||||||
let mut mtt = test_env.get_morethantext();
|
let mut mtt = test_env.get_morethantext();
|
||||||
let test_doc = TestDocument::new(vec![FieldType::Integer]);
|
let test_doc = TestDocument::new(vec![FieldType::Integer]);
|
||||||
let mut calc = Calculation::new(Operand::Equal);
|
let mut calc = Calculation::new(Operand::Equal);
|
||||||
@@ -144,17 +153,18 @@ fn can_a_trigger_from_another_document_be_used() {
|
|||||||
docdef.add_route(path, function);
|
docdef.add_route(path, function);
|
||||||
mtt.create_document(docdef);
|
mtt.create_document(docdef);
|
||||||
test_doc.populate_multiple(&mut mtt, input);
|
test_doc.populate_multiple(&mut mtt, input);
|
||||||
|
let path = Path::new(
|
||||||
|
Include::All,
|
||||||
|
Include::Just(test_doc.get_doc_name().into()),
|
||||||
|
Include::Just(Action::OnDelete),
|
||||||
|
);
|
||||||
|
test_env.register_channel(vec![path]);
|
||||||
test_env.send_time_pulse();
|
test_env.send_time_pulse();
|
||||||
let result = mtt.records(Query::new(test_doc.get_doc_name())).unwrap();
|
let result = test_env.get_trigger_records(Action::OnDelete);
|
||||||
|
assert_eq!(result.len(), 1);
|
||||||
|
let rec = result.iter().last().unwrap();
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
result.len(),
|
rec.get(test_doc.get_field_name(0)).unwrap(),
|
||||||
(count - 1).try_into().unwrap(),
|
selected.into()
|
||||||
"wrong number of records"
|
|
||||||
);
|
|
||||||
for rec in result.iter() {
|
|
||||||
assert!(
|
|
||||||
rec.get(test_doc.get_field_name(0)).unwrap() != selected.clone().into(),
|
|
||||||
"did not remove selected"
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|||||||
Reference in New Issue
Block a user