From ae936d4b180155bafe5c44482a746fa490513df2 Mon Sep 17 00:00:00 2001 From: Steve Manuel Date: Mon, 10 May 2021 12:16:41 -0600 Subject: [PATCH] fix: handle possible missing betas field from user details response --- cloudflare/src/endpoints/user.rs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/cloudflare/src/endpoints/user.rs b/cloudflare/src/endpoints/user.rs index 17da1d7d..8d980510 100644 --- a/cloudflare/src/endpoints/user.rs +++ b/cloudflare/src/endpoints/user.rs @@ -19,6 +19,7 @@ pub struct Organization { #[derive(Deserialize, Serialize, Debug, Clone, PartialEq, Eq)] pub struct UserDetails { pub organizations: Vec, + #[serde(default)] pub betas: Vec, pub telephone: Option, pub zipcode: Option, @@ -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": "user@example.com", + "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 {}