38
crates/domain/tests/attachment/content_type_test.rs
Normal file
38
crates/domain/tests/attachment/content_type_test.rs
Normal file
@@ -0,0 +1,38 @@
|
||||
use domain::attachment::ContentType;
|
||||
use domain::errors::DomainError;
|
||||
|
||||
#[test]
|
||||
fn valid_content_type_is_created() {
|
||||
let ct = ContentType::new("image/jpeg").unwrap();
|
||||
assert_eq!(ct.value(), "image/jpeg");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn content_type_is_lowercased() {
|
||||
let ct = ContentType::new("Image/JPEG").unwrap();
|
||||
assert_eq!(ct.value(), "image/jpeg");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn content_type_trims_whitespace() {
|
||||
let ct = ContentType::new(" audio/webm ").unwrap();
|
||||
assert_eq!(ct.value(), "audio/webm");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_content_type_is_rejected() {
|
||||
let result = ContentType::new("");
|
||||
assert!(matches!(result, Err(DomainError::InvalidInput(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn content_type_without_slash_is_rejected() {
|
||||
let result = ContentType::new("jpeg");
|
||||
assert!(matches!(result, Err(DomainError::InvalidInput(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn from_persistence_bypasses_validation() {
|
||||
let ct = ContentType::from_persistence(String::new());
|
||||
assert_eq!(ct.value(), "");
|
||||
}
|
||||
19
crates/domain/tests/attachment/media_upload_test.rs
Normal file
19
crates/domain/tests/attachment/media_upload_test.rs
Normal file
@@ -0,0 +1,19 @@
|
||||
use domain::attachment::{ContentType, MediaUpload};
|
||||
use domain::errors::DomainError;
|
||||
|
||||
#[test]
|
||||
fn valid_upload_is_created() {
|
||||
let ct = ContentType::new("image/png").unwrap();
|
||||
let upload = MediaUpload::new(vec![1, 2, 3], ct).unwrap();
|
||||
|
||||
assert_eq!(upload.data(), &[1, 2, 3]);
|
||||
assert_eq!(upload.content_type().value(), "image/png");
|
||||
assert_eq!(upload.size(), 3);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn empty_data_is_rejected() {
|
||||
let ct = ContentType::new("image/png").unwrap();
|
||||
let result = MediaUpload::new(vec![], ct);
|
||||
assert!(matches!(result, Err(DomainError::InvalidInput(_))));
|
||||
}
|
||||
Reference in New Issue
Block a user