Removed warnings from add tests.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Has been cancelled

This commit is contained in:
2026-05-03 10:39:14 -04:00
parent 7004ce4b81
commit 180a2bf94c

View File

@@ -3,8 +3,8 @@ mod support;
use chrono::Utc;
use morethantext::{
action::{Addition, DocDef, Field, FieldType, Query},
Action, CalcValue, Calculation, ErrorID, Include, IndexType, MTTError, MoreThanText, Name,
Operand, Path, TestMoreThanText,
Action, Calculation, ErrorID, Include, IndexType, MTTError, MoreThanText, Name, Operand, Path,
TestMoreThanText,
};
use std::{collections::HashSet, time::Duration};
use support::{random_name, TestDocument};
@@ -13,7 +13,7 @@ use uuid::Uuid;
#[test]
fn can_new_documents_be_added() {
let count = 5;
let mut mtt = MoreThanText::new();
let mtt = MoreThanText::new();
let client = mtt.client();
let doc_name = random_name();
let field_name = random_name();
@@ -23,7 +23,7 @@ fn can_new_documents_be_added() {
}
let mut docdef = DocDef::new(doc_name.clone());
docdef.add_field(vec![field_name.clone()], FieldType::Integer);
client.create_document(docdef);
client.create_document(docdef).unwrap();
for item in data.iter() {
let mut add = Addition::new(doc_name.clone());
add.add_field(field_name.clone(), item.clone());
@@ -47,7 +47,7 @@ fn can_new_documents_be_added() {
#[test]
fn does_it_error_on_a_bad_document_name() {
let mut mtt = MoreThanText::new();
let mtt = MoreThanText::new();
let client = mtt.client();
let doc_name = Name::english("empty");
let mut expected = MTTError::new(ErrorID::NameNotFound(doc_name.clone().into()));
@@ -59,12 +59,12 @@ fn does_it_error_on_a_bad_document_name() {
#[test]
fn does_it_error_on_bad_field_name() {
let mut mtt = MoreThanText::new();
let 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());
client.create_document(docdef);
client.create_document(docdef).unwrap();
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()));
@@ -76,10 +76,10 @@ fn does_it_error_on_bad_field_name() {
#[test]
fn does_it_error_on_bad_field_type() {
let mut mtt = MoreThanText::new();
let mtt = MoreThanText::new();
let client = mtt.client();
let test_doc = TestDocument::new(vec![FieldType::Uuid]);
client.create_document(test_doc.get_docdef());
client.create_document(test_doc.get_docdef()).unwrap();
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));
@@ -92,10 +92,10 @@ fn does_it_error_on_bad_field_type() {
#[test]
#[ignore = "requires session to store language preference"]
fn does_it_error_on_missing_fields() {
let mut mtt = MoreThanText::new();
let mtt = MoreThanText::new();
let client = mtt.client();
let test_doc = TestDocument::new(vec![FieldType::Integer, FieldType::Integer]);
client.create_document(test_doc.get_docdef());
client.create_document(test_doc.get_docdef()).unwrap();
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);
@@ -107,13 +107,15 @@ fn does_it_error_on_missing_fields() {
#[test]
fn can_default_values_be_used() {
let mut mtt = MoreThanText::new();
let 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());
client.create_document(docdef);
docdef
.set_default(&test_doc.get_field_name(0), ftype.clone())
.unwrap();
client.create_document(docdef).unwrap();
let add = Addition::new(test_doc.get_doc_name().clone());
let results = client.records(add).unwrap();
let rec = results.iter().last().unwrap();
@@ -122,14 +124,16 @@ fn can_default_values_be_used() {
#[test]
fn can_default_values_be_set() {
let mut mtt = MoreThanText::new();
let 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());
client.create_document(docdef);
docdef
.set_default(&test_doc.get_field_name(0), fdefault.clone())
.unwrap();
client.create_document(docdef).unwrap();
let add = Addition::new(test_doc.get_doc_name().clone());
let results = client.records(add).unwrap();
let rec = results.iter().last().unwrap();
@@ -141,15 +145,17 @@ fn can_default_values_be_set() {
#[test]
fn can_default_values_be_overwritten() {
let mut mtt = MoreThanText::new();
let 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());
client.create_document(docdef);
docdef
.set_default(&test_doc.get_field_name(0), fdefault.clone())
.unwrap();
client.create_document(docdef).unwrap();
let mut add = Addition::new(test_doc.get_doc_name().clone());
add.add_field(test_doc.get_field_name(0), used);
let results = client.records(add).unwrap();
@@ -160,14 +166,16 @@ fn can_default_values_be_overwritten() {
#[test]
fn can_default_values_be_calculated() {
let duration = Duration::from_secs(300);
let mut mtt = MoreThanText::new();
let 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);
calc.add_value(FieldType::DateTime).unwrap();
calc.add_value(duration.clone()).unwrap();
docdef
.set_default(&test_doc.get_field_name(0), calc)
.unwrap();
client.create_document(docdef).unwrap();
let add = Addition::new(test_doc.get_doc_name());
let start = Utc::now() + duration;
@@ -182,12 +190,14 @@ fn can_default_values_be_calculated() {
#[test]
fn are_unique_indexes_maintained_with_additions() {
let data = 1;
let mut mtt = MoreThanText::new();
let 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);
client.create_document(docdef);
docdef
.add_index(&test_doc.get_field_name(0), IndexType::Unique)
.unwrap();
client.create_document(docdef).unwrap();
let mut add = Addition::new(test_doc.get_doc_name());
add.add_field(test_doc.get_field_name(0), data.clone());
client.records(add.clone()).unwrap();
@@ -201,7 +211,7 @@ fn are_unique_indexes_maintained_with_additions() {
#[test]
fn does_addition_send_on_query_message() {
let mut test_env = TestMoreThanText::new();
let mut mtt = test_env.get_morethantext();
let mtt = test_env.get_morethantext();
let client = mtt.client();
let test_doc = TestDocument::new(vec![FieldType::Integer]);
client.create_document(test_doc.get_docdef()).unwrap();