Moved delete with index test.
Some checks failed
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 1s

This commit is contained in:
2026-03-05 08:06:38 -05:00
parent 87e737ff6f
commit bb47a7af31
2 changed files with 41 additions and 3 deletions

View File

@@ -1,7 +1,8 @@
mod support;
use morethantext::{
CalcValue, Calculation, Delete, Field, FieldType, MoreThanText, Operand, Query,
Addition, CalcValue, Calculation, Delete, ErrorID, Field, FieldType, IndexType, MTTError,
MoreThanText, Name, Operand, Query,
};
use std::collections::HashSet;
use support::{setup_range, TestDocument};
@@ -102,3 +103,39 @@ fn can_delete_multiple() {
qexpected
);
}
#[test]
fn does_delete_error_on_a_bad_query() {
let (mut mtt, test_doc) = setup_range(1);
let bad_name = Name::japanese("正しくない");
let mut delete = Delete::new(test_doc.get_doc_name());
let mut qry_calc = Calculation::new(Operand::Equal);
qry_calc.add_value(0).unwrap();
qry_calc
.add_value(CalcValue::Existing(FieldType::Integer))
.unwrap();
delete.get_query_mut().add(bad_name.clone(), qry_calc);
let mut expected = MTTError::new(ErrorID::NameNotFound(bad_name.clone().into()));
expected.add_parent(ErrorID::Field(bad_name.into()));
expected.add_parent(ErrorID::Document(test_doc.get_doc_name().into()));
let result = mtt.records(delete).unwrap_err();
assert_eq!(result.to_string(), expected.to_string());
}
#[test]
fn does_delete_update_indexes() {
let id = "something";
let mut mtt = MoreThanText::new();
let test_doc = TestDocument::new(vec![FieldType::StaticString]);
let mut docdef = test_doc.get_docdef();
docdef.add_index(&test_doc.get_field_name(0), IndexType::Unique);
mtt.create_document(docdef).unwrap();
test_doc.populate(&mut mtt, vec![id]);
mtt.records(Delete::new(test_doc.get_doc_name())).unwrap();
let mut add = Addition::new(test_doc.get_doc_name());
add.add_field(test_doc.get_field_name(0), id);
let result = mtt.records(add).unwrap();
assert_eq!(result.len(), 1);
let rec = result.iter().last().unwrap();
assert_eq!(rec.get(test_doc.get_field_name(0)).unwrap(), id.into());
}