use super::{
MongoExtractionError, MongoQueryError, MongoTypeError, MongoWriteError, SKIP_CEILING, offset,
};
use crate::{
FieldName,
comparison::mongo::{MongoLoweringError, RelationWidthError},
};
#[test]
fn a_skip_is_bounded_by_what_the_stage_binds() {
assert_eq!(offset(0).ok(), Some(0));
assert_eq!(offset(SKIP_CEILING).ok(), Some(i64::MAX));
assert!(matches!(
offset(SKIP_CEILING + 1),
Err(MongoQueryError::Skip(_))
));
}
#[test]
fn a_lowering_refusal_keeps_its_own_sentence() {
let refusal = MongoQueryError::from(MongoLoweringError::RelationWidth(RelationWidthError::new(
FieldName::new("splice"),
2,
)));
assert!(
refusal
.to_string()
.contains("`splice` is addressed by 2 columns"),
"{refusal}"
);
}
#[test]
fn an_extraction_refusal_keeps_its_field_through_the_query_error() {
let refusal = MongoQueryError::from(MongoExtractionError::new(
"_id",
MongoTypeError::wrong_type("long", "string"),
));
assert_eq!(
refusal.to_string(),
"this document is not a row: `_id` did not read: this field holds a string where a long was \
stored"
);
}
#[test]
fn every_refusal_but_the_ceiling_carries_its_cause() {
use core::error::Error;
assert!(
MongoQueryError::from(MongoLoweringError::ElementRelation)
.source()
.is_some()
);
assert!(MongoQueryError::Skip(1).source().is_none());
}
#[test]
fn the_unscoped_delete_names_the_collection_it_would_have_emptied() {
let refusal = MongoWriteError::Unscoped(FieldName::new("shot"));
assert_eq!(
refusal.to_string(),
"this delete names no document, so it would empty `shot` — a filter that lowers to `{}` is \
refused rather than run"
);
}
#[test]
fn the_join_refusal_says_what_the_command_could_not_carry() {
let refusal = MongoWriteError::Joined(3);
assert!(
refusal.to_string().contains("3 `$lookup` stage(s)"),
"{refusal}"
);
assert!(
refusal.to_string().contains("carries no pipeline"),
"{refusal}"
);
}
#[test]
fn a_writes_lowering_refusal_keeps_its_own_sentence() {
let refusal = MongoWriteError::from(MongoLoweringError::RelationWidth(RelationWidthError::new(
FieldName::new("splice"),
2,
)));
assert!(
refusal
.to_string()
.contains("`splice` is addressed by 2 columns"),
"{refusal}"
);
}
#[test]
fn the_writes_own_findings_carry_no_cause() {
use core::error::Error;
assert!(
MongoWriteError::from(MongoLoweringError::ElementRelation)
.source()
.is_some()
);
assert!(
MongoWriteError::Unscoped(FieldName::new("shot"))
.source()
.is_none()
);
assert!(MongoWriteError::Joined(1).source().is_none());
}