Moved on_query test to lib testing.
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::{
|
||||
CalcValue, Calculation, DocDef, ErrorID, Field, FieldType, IndexType, MTTError, MoreThanText,
|
||||
Name, Operand, Query,
|
||||
Action, CalcValue, Calculation, DocDef, ErrorID, Field, FieldType, Include, IndexType,
|
||||
MTTError, MoreThanText, Name, Operand, Path, Query, TestMoreThanText,
|
||||
};
|
||||
use std::collections::HashSet;
|
||||
use support::{setup_range, TestDocument};
|
||||
@@ -11,7 +11,8 @@ const COUNT: usize = 5;
|
||||
|
||||
#[test]
|
||||
fn does_empty_query_get_all_documents() {
|
||||
let (mut mtt, test_doc) = setup_range(COUNT);
|
||||
let (test_env, test_doc) = setup_range(COUNT);
|
||||
let mut mtt = test_env.get_morethantext();
|
||||
let mut query = Query::new(test_doc.get_doc_name());
|
||||
let result = mtt.records(query).unwrap();
|
||||
assert_eq!(result.len(), 5, "got {:?}", result);
|
||||
@@ -29,7 +30,8 @@ fn does_empty_query_get_all_documents() {
|
||||
|
||||
#[test]
|
||||
fn does_query_pull_specific_information() {
|
||||
let (mut mtt, test_doc) = setup_range(COUNT);
|
||||
let (test_env, test_doc) = setup_range(COUNT);
|
||||
let mut mtt = test_env.get_morethantext();
|
||||
let expected = 3;
|
||||
let mut calc = Calculation::new(Operand::Equal);
|
||||
calc.add_value(expected.clone()).unwrap();
|
||||
@@ -48,7 +50,8 @@ fn does_query_pull_specific_information() {
|
||||
|
||||
#[test]
|
||||
fn does_query_work_with_less_than() {
|
||||
let (mut mtt, test_doc) = setup_range(COUNT);
|
||||
let (test_env, test_doc) = setup_range(COUNT);
|
||||
let mut mtt = test_env.get_morethantext();
|
||||
let expected = 2;
|
||||
let mut calc = Calculation::new(Operand::LessThan);
|
||||
calc.add_value(expected.clone()).unwrap();
|
||||
@@ -72,7 +75,8 @@ fn does_query_work_with_less_than() {
|
||||
|
||||
#[test]
|
||||
fn does_query_work_with_less_than_equal() {
|
||||
let (mut mtt, test_doc) = setup_range(COUNT);
|
||||
let (test_env, test_doc) = setup_range(COUNT);
|
||||
let mut mtt = test_env.get_morethantext();
|
||||
let expected = 2;
|
||||
let mut calc = Calculation::new(Operand::LessThanEqual);
|
||||
calc.add_value(expected.clone()).unwrap();
|
||||
@@ -96,7 +100,8 @@ fn does_query_work_with_less_than_equal() {
|
||||
|
||||
#[test]
|
||||
fn does_query_work_with_greater_than() {
|
||||
let (mut mtt, test_doc) = setup_range(COUNT);
|
||||
let (test_env, test_doc) = setup_range(COUNT);
|
||||
let mut mtt = test_env.get_morethantext();
|
||||
let expected = 2;
|
||||
let mut calc = Calculation::new(Operand::GreaterThan);
|
||||
calc.add_value(expected.clone()).unwrap();
|
||||
@@ -119,7 +124,8 @@ fn does_query_work_with_greater_than() {
|
||||
|
||||
#[test]
|
||||
fn does_query_work_with_greater_than_equal() {
|
||||
let (mut mtt, test_doc) = setup_range(COUNT);
|
||||
let (test_env, test_doc) = setup_range(COUNT);
|
||||
let mut mtt = test_env.get_morethantext();
|
||||
let expected = 2;
|
||||
let mut calc = Calculation::new(Operand::GreaterThanEqual);
|
||||
calc.add_value(expected.clone()).unwrap();
|
||||
@@ -284,3 +290,38 @@ fn does_it_error_on_bad_field_type() {
|
||||
let result = mtt.records(qry).unwrap_err();
|
||||
assert_eq!(result.to_string(), expected.to_string());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn does_query_send_on_query_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::OnQuery),
|
||||
)]);
|
||||
let mut calc = Calculation::new(Operand::Equal);
|
||||
calc.add_value(selected.clone()).unwrap();
|
||||
calc.add_value(CalcValue::Existing(FieldType::Integer))
|
||||
.unwrap();
|
||||
let mut qry = Query::new(test_doc.get_doc_name());
|
||||
qry.add(test_doc.get_field_name(0), calc);
|
||||
let query_result = mtt.records(qry).unwrap();
|
||||
let trigger_result = test_env.get_trigger_records(Action::OnQuery);
|
||||
assert_eq!(trigger_result.len(), query_result.len());
|
||||
assert_eq!(
|
||||
trigger_result
|
||||
.iter()
|
||||
.last()
|
||||
.unwrap()
|
||||
.get(test_doc.get_field_name(0))
|
||||
.unwrap(),
|
||||
query_result
|
||||
.iter()
|
||||
.last()
|
||||
.unwrap()
|
||||
.get(test_doc.get_field_name(0))
|
||||
.unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user