diff --git a/src/backend/src/user_profile.rs b/src/backend/src/user_profile.rs index c91a1b83e1..9f46104902 100644 --- a/src/backend/src/user_profile.rs +++ b/src/backend/src/user_profile.rs @@ -59,15 +59,10 @@ pub fn add_hidden_dapp_id( dapp_id: String, user_profile_model: &mut UserProfileModel, ) -> Result<(), AddDappSettingsError> { - if let Ok(user_profile) = find_profile(principal, user_profile_model) { - let now = time(); - if let Ok(new_profile) = user_profile.add_hidden_dapp_id(profile_version, now, dapp_id) { - user_profile_model.store_new(principal, now, &new_profile); - Ok(()) - } else { - Err(AddDappSettingsError::VersionMismatch) - } - } else { - Err(AddDappSettingsError::UserNotFound) - } + let user_profile = find_profile(principal, user_profile_model) + .map_err(|_| AddDappSettingsError::UserNotFound)?; + let now = time(); + let new_profile = user_profile.add_hidden_dapp_id(profile_version, now, dapp_id)?; + user_profile_model.store_new(principal, now, &new_profile); + Ok(()) } diff --git a/src/backend/tests/it/settings.rs b/src/backend/tests/it/settings.rs index c0e7c89bd0..68bcd2bcd5 100644 --- a/src/backend/tests/it/settings.rs +++ b/src/backend/tests/it/settings.rs @@ -203,53 +203,6 @@ fn test_add_user_hidden_dapp_id_cannot_update_wrong_version() { ); } -#[test] -fn test_add_user_hidden_dapp_id_does_not_update_if_version_is_none() { - let pic_setup = setup(); - - let caller = Principal::from_text(CALLER).unwrap(); - - let create_profile_response = - pic_setup.update::(caller, "create_user_profile", ()); - - let profile = create_profile_response.expect("Create failed"); - assert_eq!(profile.settings.dapp.dapp_carousel.hidden_dapp_ids.len(), 0); - - let add_hidden_dapp_id_arg = AddHiddenDappIdRequest { - dapp_id: "test_dapp_id".to_string(), - current_user_version: None, - }; - - let add_hidden_dapp_id_response = pic_setup.update::>( - caller, - "add_user_hidden_dapp_id", - add_hidden_dapp_id_arg, - ); - - assert_eq!( - add_hidden_dapp_id_response, - Ok(Err(AddDappSettingsError::VersionMismatch)) - ); - - let get_profile_response = pic_setup.update::>( - caller, - "get_user_profile", - (), - ); - - assert_eq!( - get_profile_response - .expect("Call to get profile failed") - .expect("Get profile failed") - .settings - .dapp - .dapp_carousel - .hidden_dapp_ids - .len(), - 0 - ); -} - #[test] fn test_add_user_hidden_dapp_id_does_not_add_duplicate_dapp_id() { let pic_setup = setup();