Corrected trigger tests.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s

This commit is contained in:
2026-03-08 17:05:47 -04:00
parent c7054e4306
commit b96bbbe21d
2 changed files with 67 additions and 50 deletions

View File

@@ -93,21 +93,28 @@ fn are_session_ids_unique_on_update() {
}
#[test]
fn does_expire_update_on_query() {
let mut mtt = MoreThanText::new();
fn does_expire_updates_on_query() {
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 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()));
let end_time = Utc::now() + Duration::from_secs(3601);
let rec = get_session(&mut mtt, &id).unwrap();
let holder = rec.get(Name::english("expire")).unwrap();
match holder {
Field::DateTime(data) => {
assert!(data > start_time, "expire should be after {:?}", start_time);
assert!(data < end_time, "expire should be before {:?}", end_time);
}
_ => unreachable!("got {:?} should have been date time", holder),
}
let end_time: Field = (Utc::now() + Duration::from_secs(3601)).into();
let result = test_env.get_trigger_records(Action::OnUpdate);
assert_eq!(result.len(), 1);
let rec = result.iter().last().unwrap();
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 < end_time, "expire should be before {:?}", end_time);
}
#[test]

View File

@@ -11,7 +11,8 @@ fn can_a_trigger_cause_an_update() {
let data0 = 0;
let data1 = 0;
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 mut calc = Calculation::new(Operand::Add);
calc.add_value(CalcValue::Existing(FieldType::Integer))
@@ -29,6 +30,12 @@ fn can_a_trigger_cause_an_update() {
docdef.add_route(path, function);
mtt.create_document(docdef);
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();
assert_eq!(first_qry.len(), 1);
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(),
data1.clone().into()
);
let second_qry = mtt.records(Query::new(test_doc.get_doc_name())).unwrap();
assert_eq!(second_qry.len(), 1);
let second_rec = second_qry.iter().last().unwrap();
let result = test_env.get_trigger_records(Action::OnUpdate);
assert_eq!(result.len(), 1);
let rec = result.iter().last().unwrap();
assert_eq!(
second_rec.get(test_doc.get_field_name(0)).unwrap(),
rec.get(test_doc.get_field_name(0)).unwrap(),
data0.clone().into()
);
assert_eq!(
second_rec.get(test_doc.get_field_name(1)).unwrap(),
data1_expected.clone().into(),
"not updated"
rec.get(test_doc.get_field_name(1)).unwrap(),
data1_expected.clone().into()
);
}
@@ -64,7 +70,8 @@ fn can_trigger_update_specific_record() {
for i in 0..count {
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 mut calc = Calculation::new(Operand::Add);
calc.add_value(CalcValue::Existing(FieldType::Integer))
@@ -89,6 +96,12 @@ fn can_trigger_update_specific_record() {
qry_calc.add_value(selected.clone()).unwrap();
let mut qry = Query::new(test_doc.get_doc_name());
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();
assert_eq!(first_result.len(), 1);
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(),
initial_data.clone().into()
);
let second_result = mtt.records(Query::new(test_doc.get_doc_name())).unwrap();
assert_eq!(second_result.len(), count.try_into().unwrap());
for rec in second_result.iter() {
if rec.get(test_doc.get_field_name(0)).unwrap() == selected.clone().into() {
assert_eq!(
rec.get(test_doc.get_field_name(1)).unwrap(),
expected.clone().into()
);
} else {
assert_eq!(
rec.get(test_doc.get_field_name(1)).unwrap(),
initial_data.clone().into()
);
}
}
let result = test_env.get_trigger_records(Action::OnUpdate);
assert_eq!(result.len(), 1);
let rec = result.iter().last().unwrap();
assert_eq!(
rec.get(test_doc.get_field_name(0)).unwrap(),
selected.clone().into()
);
assert_eq!(
rec.get(test_doc.get_field_name(1)).unwrap(),
expected.clone().into()
);
}
#[test]
@@ -125,7 +134,7 @@ fn can_a_trigger_from_another_document_be_used() {
for i in 0..count {
input.push(vec![i]);
}
let test_env = TestMoreThanText::new();
let mut test_env = TestMoreThanText::new();
let mut mtt = test_env.get_morethantext();
let test_doc = TestDocument::new(vec![FieldType::Integer]);
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);
mtt.create_document(docdef);
test_doc.populate_multiple(&mut mtt, input);
test_env.send_time_pulse();
let result = mtt.records(Query::new(test_doc.get_doc_name())).unwrap();
assert_eq!(
result.len(),
(count - 1).try_into().unwrap(),
"wrong number of records"
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();
let result = test_env.get_trigger_records(Action::OnDelete);
assert_eq!(result.len(), 1);
let rec = result.iter().last().unwrap();
assert_eq!(
rec.get(test_doc.get_field_name(0)).unwrap(),
selected.into()
);
for rec in result.iter() {
assert!(
rec.get(test_doc.get_field_name(0)).unwrap() != selected.clone().into(),
"did not remove selected"
);
}
}