Skip to content

Commit

Permalink
fix: handle possible missing betas field from user details response
Browse files Browse the repository at this point in the history
  • Loading branch information
Steve Manuel authored and sssilver committed May 10, 2021
1 parent 74cb910 commit ae936d4
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions cloudflare/src/endpoints/user.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pub struct Organization {
#[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
pub struct UserDetails {
pub organizations: Vec<Organization>,
#[serde(default)]
pub betas: Vec<String>,
pub telephone: Option<String>,
pub zipcode: Option<String>,
Expand All @@ -35,6 +36,34 @@ pub struct UserDetails {
}
impl ApiResult for UserDetails {}

#[test]
fn handles_empty_betas_field() {
// note: omitted `betas` field from json data
const JSON_RESPONSE: &str = r#"
{
"id": "1234567890abcdef",
"email": "[email protected]",
"username": "user",
"first_name": null,
"last_name": null,
"telephone": null,
"country": null,
"zipcode": null,
"two_factor_authentication_enabled": false,
"two_factor_authentication_locked": false,
"created_on": "2015-02-24T13:03:05.255956Z",
"modified_on": "2018-06-10T23:50:04.029596Z",
"organizations": [],
"has_pro_zones": false,
"has_business_zones": false,
"has_enterprise_zones": false,
"suspended": false
}"#;

let user_details: UserDetails = serde_json::from_str(JSON_RESPONSE).unwrap();
assert!(user_details.betas.is_empty());
}

#[derive(Debug)]
pub struct GetUserDetails {}

Expand Down

0 comments on commit ae936d4

Please sign in to comment.