moved final addition testing into lib testing.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s

This commit is contained in:
2026-03-04 11:07:38 -05:00
parent 43aa53fc49
commit ff9aef6d44
2 changed files with 43 additions and 3 deletions

View File

@@ -2045,7 +2045,6 @@ mod document_files {
} }
assert!(ids.is_empty(), "did not find {:?}", ids); assert!(ids.is_empty(), "did not find {:?}", ids);
} }
*/
#[test] #[test]
fn can_calculate_field_values() { fn can_calculate_field_values() {
@@ -2076,6 +2075,7 @@ mod document_files {
_ => unreachable!("got {:?}: should have gotten reply", action), _ => unreachable!("got {:?}: should have gotten reply", action),
} }
} }
*/
#[test] #[test]
fn can_delete() { fn can_delete() {

View File

@@ -1,10 +1,11 @@
mod support; mod support;
use chrono::Utc;
use morethantext::{ use morethantext::{
action::{Addition, DocDef, Field, FieldType, Query}, action::{Addition, DocDef, Field, FieldType, Query},
ErrorID, MTTError, MoreThanText, Name, Calculation, ErrorID, IndexType, MTTError, MoreThanText, Name, Operand,
}; };
use std::collections::HashSet; use std::{collections::HashSet, time::Duration};
use support::{random_name, TestDocument}; use support::{random_name, TestDocument};
use uuid::Uuid; use uuid::Uuid;
@@ -146,3 +147,42 @@ fn can_default_values_be_overwritten() {
let rec = results.iter().last().unwrap(); let rec = results.iter().last().unwrap();
assert_eq!(rec.get(test_doc.get_field_name(0)).unwrap(), used.into()); assert_eq!(rec.get(test_doc.get_field_name(0)).unwrap(), used.into());
} }
#[test]
fn can_default_values_be_calculated() {
let duration = Duration::from_secs(300);
let mut mtt = MoreThanText::new();
let test_doc = TestDocument::new(vec![FieldType::DateTime]);
let mut docdef = test_doc.get_docdef();
let mut calc = Calculation::new(Operand::Add);
calc.add_value(FieldType::DateTime);
calc.add_value(duration.clone());
docdef.set_default(&test_doc.get_field_name(0), calc);
mtt.create_document(docdef).unwrap();
let add = Addition::new(test_doc.get_doc_name());
let start = Utc::now() + duration;
let results = mtt.records(add).unwrap();
let end = Utc::now() + duration;
let rec = results.iter().last().unwrap();
let field = rec.get(&test_doc.get_field_name(0)).unwrap();
assert!(field > start.into());
assert!(field < end.into());
}
#[test]
fn are_unique_indexes_maintained_with_additions() {
let data = 1;
let mut mtt = MoreThanText::new();
let test_doc = TestDocument::new(vec![FieldType::Integer]);
let mut docdef = test_doc.get_docdef();
docdef.add_index(&test_doc.get_field_name(0), IndexType::Unique);
mtt.create_document(docdef);
let mut add = Addition::new(test_doc.get_doc_name());
add.add_field(test_doc.get_field_name(0), data.clone());
mtt.records(add.clone()).unwrap();
let mut err = MTTError::new(ErrorID::IndexEntryAlreadyExists(data.into()));
err.add_parent(ErrorID::Field(test_doc.get_field_name(0).into()));
err.add_parent(ErrorID::Document(test_doc.get_doc_name().into()));
let result = mtt.records(add).unwrap_err();
assert_eq!(result.to_string(), err.to_string());
}