Moved the rest of the trigger tests to lib.
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:
@@ -958,7 +958,6 @@ mod document_files {
|
|||||||
_ => unreachable!("should never get here"),
|
_ => unreachable!("should never get here"),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn send_on_addition_message() {
|
fn send_on_addition_message() {
|
||||||
@@ -1089,7 +1088,6 @@ mod document_files {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
#[test]
|
#[test]
|
||||||
fn can_document_be_added() {
|
fn can_document_be_added() {
|
||||||
let doc_name = Name::english("document");
|
let doc_name = Name::english("document");
|
||||||
|
|||||||
@@ -3,7 +3,8 @@ mod support;
|
|||||||
use chrono::Utc;
|
use chrono::Utc;
|
||||||
use morethantext::{
|
use morethantext::{
|
||||||
action::{Addition, DocDef, Field, FieldType, Query},
|
action::{Addition, DocDef, Field, FieldType, Query},
|
||||||
Calculation, ErrorID, IndexType, MTTError, MoreThanText, Name, Operand,
|
Action, CalcValue, Calculation, ErrorID, Include, IndexType, MTTError, MoreThanText, Name,
|
||||||
|
Operand, Path, TestMoreThanText,
|
||||||
};
|
};
|
||||||
use std::{collections::HashSet, time::Duration};
|
use std::{collections::HashSet, time::Duration};
|
||||||
use support::{random_name, TestDocument};
|
use support::{random_name, TestDocument};
|
||||||
@@ -186,3 +187,35 @@ fn are_unique_indexes_maintained_with_additions() {
|
|||||||
let result = mtt.records(add).unwrap_err();
|
let result = mtt.records(add).unwrap_err();
|
||||||
assert_eq!(result.to_string(), err.to_string());
|
assert_eq!(result.to_string(), err.to_string());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn does_addition_send_on_query_message() {
|
||||||
|
let mut test_env = TestMoreThanText::new();
|
||||||
|
let mut mtt = test_env.get_morethantext();
|
||||||
|
let test_doc = TestDocument::new(vec![FieldType::Integer]);
|
||||||
|
mtt.create_document(test_doc.get_docdef()).unwrap();
|
||||||
|
test_env.register_channel(vec![Path::new(
|
||||||
|
Include::All,
|
||||||
|
Include::Just(test_doc.get_doc_name().into()),
|
||||||
|
Include::Just(Action::OnAddition),
|
||||||
|
)]);
|
||||||
|
let mut add = Addition::new(test_doc.get_doc_name());
|
||||||
|
add.add_field(test_doc.get_field_name(0), 2);
|
||||||
|
let add_result = mtt.records(add).unwrap();
|
||||||
|
let trigger_result = test_env.get_trigger_records(Action::OnAddition);
|
||||||
|
assert_eq!(trigger_result.len(), add_result.len());
|
||||||
|
assert_eq!(
|
||||||
|
trigger_result
|
||||||
|
.iter()
|
||||||
|
.last()
|
||||||
|
.unwrap()
|
||||||
|
.get(test_doc.get_field_name(0))
|
||||||
|
.unwrap(),
|
||||||
|
add_result
|
||||||
|
.iter()
|
||||||
|
.last()
|
||||||
|
.unwrap()
|
||||||
|
.get(test_doc.get_field_name(0))
|
||||||
|
.unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
mod support;
|
mod support;
|
||||||
|
|
||||||
use morethantext::{
|
use morethantext::{
|
||||||
Addition, CalcValue, Calculation, Delete, ErrorID, Field, FieldType, IndexType, MTTError,
|
Action, Addition, CalcValue, Calculation, Delete, ErrorID, Field, FieldType, Include,
|
||||||
MoreThanText, Name, Operand, Query,
|
IndexType, MTTError, MoreThanText, Name, Operand, Path, Query,
|
||||||
};
|
};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use support::{setup_range, TestDocument};
|
use support::{setup_range, TestDocument};
|
||||||
@@ -142,3 +142,38 @@ fn does_delete_update_indexes() {
|
|||||||
let rec = result.iter().last().unwrap();
|
let rec = result.iter().last().unwrap();
|
||||||
assert_eq!(rec.get(test_doc.get_field_name(0)).unwrap(), id.into());
|
assert_eq!(rec.get(test_doc.get_field_name(0)).unwrap(), id.into());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn does_delete_send_trigger() {
|
||||||
|
let selected = 2;
|
||||||
|
let (mut test_env, test_doc) = setup_range(3);
|
||||||
|
let mut mtt = test_env.get_morethantext();
|
||||||
|
test_env.register_channel(vec![Path::new(
|
||||||
|
Include::All,
|
||||||
|
Include::Just(test_doc.get_doc_name().into()),
|
||||||
|
Include::Just(Action::OnDelete),
|
||||||
|
)]);
|
||||||
|
let mut calc = Calculation::new(Operand::Equal);
|
||||||
|
calc.add_value(selected.clone()).unwrap();
|
||||||
|
calc.add_value(CalcValue::Existing(FieldType::Integer))
|
||||||
|
.unwrap();
|
||||||
|
let mut delete = Delete::new(test_doc.get_doc_name());
|
||||||
|
delete.get_query_mut().add(test_doc.get_field_name(0), calc);
|
||||||
|
let delete_result = mtt.records(delete).unwrap();
|
||||||
|
let trigger_result = test_env.get_trigger_records(Action::OnDelete);
|
||||||
|
assert_eq!(trigger_result.len(), delete_result.len());
|
||||||
|
assert_eq!(
|
||||||
|
trigger_result
|
||||||
|
.iter()
|
||||||
|
.last()
|
||||||
|
.unwrap()
|
||||||
|
.get(test_doc.get_field_name(0))
|
||||||
|
.unwrap(),
|
||||||
|
delete_result
|
||||||
|
.iter()
|
||||||
|
.last()
|
||||||
|
.unwrap()
|
||||||
|
.get(test_doc.get_field_name(0))
|
||||||
|
.unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
mod support;
|
mod support;
|
||||||
|
|
||||||
use morethantext::{
|
use morethantext::{
|
||||||
Addition, CalcValue, Calculation, ErrorID, Field, FieldType, IndexType, MTTError, MoreThanText,
|
Action, Addition, CalcValue, Calculation, ErrorID, Field, FieldType, Include, IndexType,
|
||||||
Name, Operand, Query, Records, Update,
|
MTTError, MoreThanText, Name, Operand, Path, Query, Records, Update,
|
||||||
};
|
};
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use support::{setup_range, TestDocument};
|
use support::{setup_range, TestDocument};
|
||||||
@@ -292,3 +292,39 @@ fn does_update_error_when_it_overrides_unique_index() {
|
|||||||
assert_eq!(rec.get(test_doc.get_field_name(0)).unwrap(), i.into());
|
assert_eq!(rec.get(test_doc.get_field_name(0)).unwrap(), i.into());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn does_update_send_on_update_message() {
|
||||||
|
let selected = 2;
|
||||||
|
let (mut test_env, test_doc) = setup_range(3);
|
||||||
|
let mut mtt = test_env.get_morethantext();
|
||||||
|
test_env.register_channel(vec![Path::new(
|
||||||
|
Include::All,
|
||||||
|
Include::Just(test_doc.get_doc_name().into()),
|
||||||
|
Include::Just(Action::OnUpdate),
|
||||||
|
)]);
|
||||||
|
let mut calc = Calculation::new(Operand::Equal);
|
||||||
|
calc.add_value(selected.clone()).unwrap();
|
||||||
|
calc.add_value(CalcValue::Existing(FieldType::Integer))
|
||||||
|
.unwrap();
|
||||||
|
let mut update = Update::new(test_doc.get_doc_name());
|
||||||
|
update.get_query_mut().add(test_doc.get_field_name(0), calc);
|
||||||
|
update.add_field(test_doc.get_field_name(0), 5);
|
||||||
|
let update_result = mtt.records(update).unwrap();
|
||||||
|
let trigger_result = test_env.get_trigger_records(Action::OnUpdate);
|
||||||
|
assert_eq!(trigger_result.len(), update_result.len());
|
||||||
|
assert_eq!(
|
||||||
|
trigger_result
|
||||||
|
.iter()
|
||||||
|
.last()
|
||||||
|
.unwrap()
|
||||||
|
.get(test_doc.get_field_name(0))
|
||||||
|
.unwrap(),
|
||||||
|
update_result
|
||||||
|
.iter()
|
||||||
|
.last()
|
||||||
|
.unwrap()
|
||||||
|
.get(test_doc.get_field_name(0))
|
||||||
|
.unwrap()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user