diff --git a/src/main/java/biz/nynja/account/validation/Validators.java b/src/main/java/biz/nynja/account/validation/Validators.java index f1f1689cd3946a3b4931a2180b6bb90a13671d61..179d49afcb6aaa776db4806750477d478f4d12b4 100644 --- a/src/main/java/biz/nynja/account/validation/Validators.java +++ b/src/main/java/biz/nynja/account/validation/Validators.java @@ -355,8 +355,8 @@ public class Validators { return validation; } - if (!authenticationType.equals(AuthenticationType.EMAIL.toString()) - && !authenticationType.equals(AuthenticationType.PHONE.toString())) { + if (!authenticationType.equals(AuthenticationType.EMAIL.name()) + && !authenticationType.equals(AuthenticationType.PHONE.name())) { validation.addError( new ValidationError("Invalid authentication provider type", Cause.INVALID_AUTH_PROVIDER_TYPE)); return validation; diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 116a08376a0eafb75287fbb477a30a63abc0a91a..0f0386d6f8bc2cf33c0566b5e814e28418fafc22 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -67,9 +67,11 @@ import biz.nynja.account.grpc.ProfileByProfileIdRequest; import biz.nynja.account.grpc.ProfileResponse; import biz.nynja.account.grpc.Role; import biz.nynja.account.grpc.SearchResponse; +import biz.nynja.account.grpc.SearchableOption; import biz.nynja.account.grpc.StatusResponse; import biz.nynja.account.grpc.UpdateAccountRequest; import biz.nynja.account.grpc.UpdateAuthenticationProviderRequest; +import biz.nynja.account.grpc.UpdateSearchableOptionRequest; import biz.nynja.account.models.Account; import biz.nynja.account.models.AccountByAuthenticationProvider; import biz.nynja.account.models.AccountByProfileId; @@ -2019,4 +2021,118 @@ public class AccountServiceTests extends GrpcServerTestBase { assertNotNull("Reply should not be null", reply); assertEquals(reply.getError().getCause(), Cause.INVALID_EMAIL); } + + @Test + public void testUpdateSearchableOptionPhoneOK() { + final UpdateSearchableOptionRequest request = UpdateSearchableOptionRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()).setAuthenticationIdentifier(Util.PHONE_PROVIDER) + .setAuthenticationType(AuthenticationType.PHONE.name()) + .setSearchOption(SearchableOption.SEARCH_DISABLED).build(); + + given(accountRepositoryAdditional.updateSearchableOption(Mockito.any(UUID.class), Mockito.any(String.class), + Mockito.any(String.class), Mockito.any(SearchableOption.class))).willReturn(true); + + given(profileRepository.findByProfileId(Util.PROFILE_ID)).willReturn(profile2AuthProviders); + + given(profileByAutheticationProviderRepository + .findByAuthenticationProviderAndAuthenticationProviderType(Util.PHONE_PROVIDER, "PHONE")) + .willReturn(profileByAuthenticationProvider); + + final StatusResponse reply = accountServiceBlockingStub.updateSearchableOption(request); + assertNotNull("Reply should not be null", reply); + assertEquals("SUCCESS", reply.getStatus()); + } + + @Test + public void testUpdateSearchableOptionEmailOK() { + final UpdateSearchableOptionRequest request = UpdateSearchableOptionRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()).setAuthenticationIdentifier(Util.EMAIL) + .setAuthenticationType(AuthenticationType.EMAIL.name()) + .setSearchOption(SearchableOption.SEARCH_DISABLED).build(); + + given(accountRepositoryAdditional.updateSearchableOption(Mockito.any(UUID.class), Mockito.any(String.class), + Mockito.any(String.class), Mockito.any(SearchableOption.class))).willReturn(true); + + given(profileRepository.findByProfileId(Util.PROFILE_ID)).willReturn(profile2AuthProviders); + + given(profileByAutheticationProviderRepository + .findByAuthenticationProviderAndAuthenticationProviderType(Util.EMAIL, "EMAIL")) + .willReturn(profileByAuthenticationProvider); + + final StatusResponse reply = accountServiceBlockingStub.updateSearchableOption(request); + assertNotNull("Reply should not be null", reply); + assertEquals("SUCCESS", reply.getStatus()); + } + + @Test + public void testUpdateSearchableOptionErrorUpdatingSearchableOption() { + final UpdateSearchableOptionRequest request = UpdateSearchableOptionRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()).setAuthenticationIdentifier(Util.PHONE_PROVIDER) + .setAuthenticationType(AuthenticationType.PHONE.name()) + .setSearchOption(SearchableOption.SEARCH_DISABLED).build(); + + given(accountRepositoryAdditional.updateSearchableOption(Mockito.any(UUID.class), Mockito.any(String.class), + Mockito.any(String.class), Mockito.any(SearchableOption.class))).willReturn(false); + + final StatusResponse reply = accountServiceBlockingStub.updateSearchableOption(request); + assertNotNull("Reply should not be null", reply); + assertEquals(reply.getError().getCause(), Cause.ERROR_UPDATING_SEARCHABLE_OPTION); + } + + @Test + public void testUpdateSearchableOptionMissingAuthenticationProviderType() { + final UpdateSearchableOptionRequest request = UpdateSearchableOptionRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()).setAuthenticationIdentifier(Util.PHONE_PROVIDER) + .setSearchOption(SearchableOption.SEARCH_DISABLED).build(); + + final StatusResponse reply = accountServiceBlockingStub.updateSearchableOption(request); + assertNotNull("Reply should not be null", reply); + assertEquals(reply.getError().getCause(), Cause.MISSING_AUTH_PROVIDER_TYPE); + } + + @Test + public void testUpdateSearchableOptionMissingAuthenticationProviderIdentifier() { + final UpdateSearchableOptionRequest request = UpdateSearchableOptionRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()).setAuthenticationType(AuthenticationType.PHONE.name()) + .setSearchOption(SearchableOption.SEARCH_DISABLED).build(); + + final StatusResponse reply = accountServiceBlockingStub.updateSearchableOption(request); + assertNotNull("Reply should not be null", reply); + assertEquals(reply.getError().getCause(), Cause.MISSING_AUTH_PROVIDER_ID); + } + + @Test + public void testUpdateSearchableOptionMissingProfileId() { + final UpdateSearchableOptionRequest request = UpdateSearchableOptionRequest.newBuilder() + .setAuthenticationIdentifier(Util.PHONE_PROVIDER).setAuthenticationType(AuthenticationType.PHONE.name()) + .setSearchOption(SearchableOption.SEARCH_DISABLED).build(); + + final StatusResponse reply = accountServiceBlockingStub.updateSearchableOption(request); + assertNotNull("Reply should not be null", reply); + assertEquals(reply.getError().getCause(), Cause.MISSING_PROFILE_ID); + } + + @Test + public void testUpdateSearchableOptionInvalidProfileId() { + final UpdateSearchableOptionRequest request = UpdateSearchableOptionRequest.newBuilder() + .setProfileId(Util.INVALID_PROFILE_ID).setAuthenticationIdentifier(Util.PHONE_PROVIDER) + .setAuthenticationType(AuthenticationType.PHONE.name()) + .setSearchOption(SearchableOption.SEARCH_DISABLED).build(); + + final StatusResponse reply = accountServiceBlockingStub.updateSearchableOption(request); + assertNotNull("Reply should not be null", reply); + assertEquals(reply.getError().getCause(), Cause.INVALID_PROFILE_ID); + } + + @Test + public void testUpdateSearchableOptionInvalidAuthenticationProviderType() { + final UpdateSearchableOptionRequest request = UpdateSearchableOptionRequest.newBuilder() + .setProfileId(Util.PROFILE_ID.toString()).setAuthenticationIdentifier("Facebook_provider") + .setAuthenticationType(AuthenticationType.FACEBOOK.name()) + .setSearchOption(SearchableOption.SEARCH_DISABLED).build(); + + final StatusResponse reply = accountServiceBlockingStub.updateSearchableOption(request); + assertNotNull("Reply should not be null", reply); + assertEquals(reply.getError().getCause(), Cause.INVALID_AUTH_PROVIDER_TYPE); + } }