Add some tests

This commit is contained in:
Marc Plano-Lesay 2024-11-06 14:36:46 +11:00
parent bc46df634d
commit c525f63660
Signed by: kernald
GPG key ID: 66A41B08CC62A6CF
6 changed files with 889 additions and 27 deletions

View file

@ -19,3 +19,47 @@ impl From<PersonResponseDto> for Person {
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn from_person_response_dto_success() {
let dto = PersonResponseDto {
id: String::from("123e4567-e89b-12d3-a456-426655440000"),
name: String::from("John Doe"),
birth_date: Some(NaiveDate::from_ymd_opt(2000, 1, 1).unwrap()),
is_hidden: false,
thumbnail_path: String::from("/foo/bar.jpg"),
updated_at: None,
};
let person = Person::from(dto);
assert_eq!(
person.id,
Uuid::parse_str("123e4567-e89b-12d3-a456-426655440000").unwrap()
);
assert_eq!(person.name, "John Doe".to_string());
assert_eq!(
person.date_of_birth,
Some(NaiveDate::from_ymd_opt(2000, 1, 1).unwrap())
);
}
#[test]
#[should_panic]
fn from_person_response_dto_invalid_uuid_panics() {
let dto = PersonResponseDto {
id: String::from("invalid_uuid"),
name: String::from("John Doe"),
birth_date: Some(NaiveDate::from_ymd_opt(2000, 1, 1).unwrap()),
is_hidden: false,
thumbnail_path: String::from("/foo/bar.jpg"),
updated_at: None,
};
let _ = Person::from(dto);
}
}