diff --git a/src/types/api/user.rs b/src/types/api/user.rs index 27a8094..ac83f12 100644 --- a/src/types/api/user.rs +++ b/src/types/api/user.rs @@ -113,4 +113,36 @@ mod tests { }; assert_eq!(user, expected); } + + #[test] + fn deserialize_works_with_blank_language() { + let data = include_str!("../../../test_data/example_user_blank_language.json"); + let user: User = serde_json::from_str(data).unwrap(); + let expected = User { + active: IsActive::Yes, + avatar_url: OptionalUrl::Some( + Url::from_str("https://codeberg.org/avatars/foo-bar").unwrap(), + ), + created: DateTime::from_str("2022-11-04T14:41:29Z").unwrap(), + description: String::from(""), + email: Email::from_str("example@mail.com").unwrap(), + followers_count: 2, + following_count: 1, + full_name: String::from(""), + id: 12345, + is_admin: IsAdmin::No, + language: Locale::None, + last_login: DateTime::from_str("2023-07-26T19:38:27Z").unwrap(), + location: String::from(""), + login: String::from("ExampleUser"), + login_name: String::from(""), + prohibit_login: ProhibitLogin::No, + restricted: IsRestricted::No, + starred_repos_count: 0, + username: String::from("ExampleUser"), + visibility: Visibility::Public, + website: OptionalUrl::Some(Url::from_str("https://example.com").unwrap()), + }; + assert_eq!(user, expected); + } } diff --git a/test_data/example_user_blank_language.json b/test_data/example_user_blank_language.json new file mode 100644 index 0000000..499043a --- /dev/null +++ b/test_data/example_user_blank_language.json @@ -0,0 +1,23 @@ +{ + "active": true, + "avatar_url": "https://codeberg.org/avatars/foo-bar", + "created": "2022-11-04T14:41:29Z", + "description": "", + "email": "example@mail.com", + "followers_count": 2, + "following_count": 1, + "full_name": "", + "id": 12345, + "is_admin": false, + "language": "", + "last_login": "2023-07-26T19:38:27Z", + "location": "", + "login": "ExampleUser", + "login_name": "", + "prohibit_login": false, + "restricted": false, + "starred_repos_count": 0, + "username": "ExampleUser", + "visibility": "public", + "website": "https://example.com" +}