Add some tests
This commit is contained in:
parent
bc46df634d
commit
c525f63660
6 changed files with 889 additions and 27 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue