Moved addition tests to client.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
2026-03-26 07:58:24 -04:00
parent 3a608967ef
commit 24edca6415

View File

@@ -14,6 +14,7 @@ use uuid::Uuid;
fn can_new_documents_be_added() {
let count = 5;
let mut mtt = MoreThanText::new();
let client = mtt.client();
let doc_name = random_name();
let field_name = random_name();
let mut data: HashSet<Field> = HashSet::new();
@@ -22,14 +23,14 @@ fn can_new_documents_be_added() {
}
let mut docdef = DocDef::new(doc_name.clone());
docdef.add_field(vec![field_name.clone()], FieldType::Integer);
mtt.create_document(docdef);
client.create_document(docdef);
for item in data.iter() {
let mut add = Addition::new(doc_name.clone());
add.add_field(field_name.clone(), item.clone());
mtt.records(add).unwrap();
client.records(add).unwrap();
}
let qry = Query::new(doc_name.clone());
let recs = mtt.records(qry).unwrap();
let recs = client.records(qry).unwrap();
assert_eq!(recs.len(), data.len());
for rec in recs.iter() {
let result = rec.get(&field_name).unwrap();
@@ -47,41 +48,44 @@ fn can_new_documents_be_added() {
#[test]
fn does_it_error_on_a_bad_document_name() {
let mut mtt = MoreThanText::new();
let client = mtt.client();
let doc_name = Name::english("empty");
let mut expected = MTTError::new(ErrorID::NameNotFound(doc_name.clone().into()));
expected.add_parent(ErrorID::Document(doc_name.clone().into()));
let add = Addition::new(doc_name.clone());
let result = mtt.records(add).unwrap_err();
let result = client.records(add).unwrap_err();
assert_eq!(result.to_string(), expected.to_string());
}
#[test]
fn does_it_error_on_bad_field_name() {
let mut mtt = MoreThanText::new();
let client = mtt.client();
let doc_name = Name::english("holder");
let field_name = Name::english("missing");
let docdef = DocDef::new(doc_name.clone());
mtt.create_document(docdef);
client.create_document(docdef);
let mut add = Addition::new(doc_name.clone());
add.add_field(field_name.clone(), "something");
let mut expected = MTTError::new(ErrorID::NameNotFound(field_name.clone().into()));
expected.add_parent(ErrorID::Field(field_name.clone().into()));
expected.add_parent(ErrorID::Document(doc_name.clone().into()));
let result = mtt.records(add).unwrap_err();
let result = client.records(add).unwrap_err();
assert_eq!(result.to_string(), expected.to_string());
}
#[test]
fn does_it_error_on_bad_field_type() {
let mut mtt = MoreThanText::new();
let client = mtt.client();
let test_doc = TestDocument::new(vec![FieldType::Uuid]);
mtt.create_document(test_doc.get_docdef());
client.create_document(test_doc.get_docdef());
let mut add = Addition::new(test_doc.get_doc_name().clone());
add.add_field(test_doc.get_field_name(0), "something");
let mut expected = MTTError::new(ErrorID::FieldTypeExpected(FieldType::Uuid));
expected.add_parent(ErrorID::Field(test_doc.get_field_name(0).into()));
expected.add_parent(ErrorID::Document(test_doc.get_doc_name().clone().into()));
let result = mtt.records(add).unwrap_err();
let result = client.records(add).unwrap_err();
assert_eq!(result.to_string(), expected.to_string());
}
@@ -89,27 +93,29 @@ fn does_it_error_on_bad_field_type() {
#[ignore = "requires session to store language preference"]
fn does_it_error_on_missing_fields() {
let mut mtt = MoreThanText::new();
let client = mtt.client();
let test_doc = TestDocument::new(vec![FieldType::Integer, FieldType::Integer]);
mtt.create_document(test_doc.get_docdef());
client.create_document(test_doc.get_docdef());
let mut add = Addition::new(test_doc.get_doc_name().clone());
add.add_field(test_doc.get_field_name(0), 1);
let mut expected = MTTError::new(ErrorID::FieldInvalidNone);
expected.add_parent(ErrorID::Field(test_doc.get_field_name(0).into()));
expected.add_parent(ErrorID::Document(test_doc.get_doc_name().clone().into()));
let result = mtt.records(add).unwrap_err();
let result = client.records(add).unwrap_err();
assert_eq!(result.to_string(), expected.to_string());
}
#[test]
fn can_default_values_be_used() {
let mut mtt = MoreThanText::new();
let client = mtt.client();
let ftype = FieldType::StaticString;
let test_doc = TestDocument::new(vec![ftype.clone()]);
let mut docdef = test_doc.get_docdef();
docdef.set_default(&test_doc.get_field_name(0), ftype.clone());
mtt.create_document(docdef);
client.create_document(docdef);
let add = Addition::new(test_doc.get_doc_name().clone());
let results = mtt.records(add).unwrap();
let results = client.records(add).unwrap();
let rec = results.iter().last().unwrap();
assert_eq!(rec.get(test_doc.get_field_name(0)).unwrap(), "".into());
}
@@ -117,14 +123,15 @@ fn can_default_values_be_used() {
#[test]
fn can_default_values_be_set() {
let mut mtt = MoreThanText::new();
let client = mtt.client();
let ftype = FieldType::StaticString;
let fdefault = Uuid::new_v4().to_string();
let test_doc = TestDocument::new(vec![ftype.clone()]);
let mut docdef = test_doc.get_docdef();
docdef.set_default(&test_doc.get_field_name(0), fdefault.clone());
mtt.create_document(docdef);
client.create_document(docdef);
let add = Addition::new(test_doc.get_doc_name().clone());
let results = mtt.records(add).unwrap();
let results = client.records(add).unwrap();
let rec = results.iter().last().unwrap();
assert_eq!(
rec.get(test_doc.get_field_name(0)).unwrap(),
@@ -135,16 +142,17 @@ fn can_default_values_be_set() {
#[test]
fn can_default_values_be_overwritten() {
let mut mtt = MoreThanText::new();
let client = mtt.client();
let ftype = FieldType::StaticString;
let fdefault = Uuid::new_v4().to_string();
let used = "something";
let test_doc = TestDocument::new(vec![ftype.clone()]);
let mut docdef = test_doc.get_docdef();
docdef.set_default(&test_doc.get_field_name(0), fdefault.clone());
mtt.create_document(docdef);
client.create_document(docdef);
let mut add = Addition::new(test_doc.get_doc_name().clone());
add.add_field(test_doc.get_field_name(0), used);
let results = mtt.records(add).unwrap();
let results = client.records(add).unwrap();
let rec = results.iter().last().unwrap();
assert_eq!(rec.get(test_doc.get_field_name(0)).unwrap(), used.into());
}
@@ -153,16 +161,17 @@ fn can_default_values_be_overwritten() {
fn can_default_values_be_calculated() {
let duration = Duration::from_secs(300);
let mut mtt = MoreThanText::new();
let client = mtt.client();
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();
client.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 results = client.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();
@@ -174,17 +183,18 @@ fn can_default_values_be_calculated() {
fn are_unique_indexes_maintained_with_additions() {
let data = 1;
let mut mtt = MoreThanText::new();
let client = mtt.client();
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);
client.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();
client.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();
let result = client.records(add).unwrap_err();
assert_eq!(result.to_string(), err.to_string());
}
@@ -192,8 +202,9 @@ fn are_unique_indexes_maintained_with_additions() {
fn does_addition_send_on_query_message() {
let mut test_env = TestMoreThanText::new();
let mut mtt = test_env.get_morethantext();
let client = mtt.client();
let test_doc = TestDocument::new(vec![FieldType::Integer]);
mtt.create_document(test_doc.get_docdef()).unwrap();
client.create_document(test_doc.get_docdef()).unwrap();
test_env.register_channel(vec![Path::new(
Include::All,
Include::Just(test_doc.get_doc_name().into()),
@@ -201,7 +212,7 @@ fn does_addition_send_on_query_message() {
)]);
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 add_result = client.records(add).unwrap();
let trigger_result = test_env.get_trigger_records(Action::OnAddition);
assert_eq!(trigger_result.len(), add_result.len());
assert_eq!(