From 0cc7cc3fc8a301adfd2d70c7d3675d7361bf0fda Mon Sep 17 00:00:00 2001 From: Stanimir Penkov Date: Thu, 3 Jan 2019 14:22:20 +0200 Subject: [PATCH 1/3] =?UTF-8?q?NY-6216:=20Add=20unit=20tests=20for=20updat?= =?UTF-8?q?ing=20login=20option=E2=80=99s=20searchable=20state?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stanimir Penkov --- .../account/services/AccountServiceTests.java | 115 ++++++++++++++++++ 1 file changed, 115 insertions(+) diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 116a083..7313213 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -2019,4 +2019,119 @@ 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.toString()) + .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.toString()) + .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.toString()) + .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.toString()) + .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.toString()) + .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.toString()) + .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.toString()) + .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); + } } -- GitLab From 2dce7d589f8543a4adb68d318ba37aaad8f0dc66 Mon Sep 17 00:00:00 2001 From: Stanimir Penkov Date: Fri, 4 Jan 2019 18:32:09 +0200 Subject: [PATCH 2/3] NY-6216: Added needed imports Signed-off-by: Stanimir Penkov --- .../java/biz/nynja/account/services/AccountServiceTests.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/biz/nynja/account/services/AccountServiceTests.java b/src/test/java/biz/nynja/account/services/AccountServiceTests.java index 7313213..2a1940d 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; -- GitLab From 1845c77b333e24881c4cf97afee6303bc799fce9 Mon Sep 17 00:00:00 2001 From: Stanimir Penkov Date: Mon, 7 Jan 2019 12:12:49 +0200 Subject: [PATCH 3/3] NY-6216: Code Review Feedback - use .name() Signed-off-by: Stanimir Penkov --- .../biz/nynja/account/validation/Validators.java | 4 ++-- .../account/services/AccountServiceTests.java | 15 +++++++-------- 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/biz/nynja/account/validation/Validators.java b/src/main/java/biz/nynja/account/validation/Validators.java index f1f1689..179d49a 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 2a1940d..0f0386d 100644 --- a/src/test/java/biz/nynja/account/services/AccountServiceTests.java +++ b/src/test/java/biz/nynja/account/services/AccountServiceTests.java @@ -2026,7 +2026,7 @@ public class AccountServiceTests extends GrpcServerTestBase { public void testUpdateSearchableOptionPhoneOK() { final UpdateSearchableOptionRequest request = UpdateSearchableOptionRequest.newBuilder() .setProfileId(Util.PROFILE_ID.toString()).setAuthenticationIdentifier(Util.PHONE_PROVIDER) - .setAuthenticationType(AuthenticationType.PHONE.toString()) + .setAuthenticationType(AuthenticationType.PHONE.name()) .setSearchOption(SearchableOption.SEARCH_DISABLED).build(); given(accountRepositoryAdditional.updateSearchableOption(Mockito.any(UUID.class), Mockito.any(String.class), @@ -2047,7 +2047,7 @@ public class AccountServiceTests extends GrpcServerTestBase { public void testUpdateSearchableOptionEmailOK() { final UpdateSearchableOptionRequest request = UpdateSearchableOptionRequest.newBuilder() .setProfileId(Util.PROFILE_ID.toString()).setAuthenticationIdentifier(Util.EMAIL) - .setAuthenticationType(AuthenticationType.EMAIL.toString()) + .setAuthenticationType(AuthenticationType.EMAIL.name()) .setSearchOption(SearchableOption.SEARCH_DISABLED).build(); given(accountRepositoryAdditional.updateSearchableOption(Mockito.any(UUID.class), Mockito.any(String.class), @@ -2068,7 +2068,7 @@ public class AccountServiceTests extends GrpcServerTestBase { public void testUpdateSearchableOptionErrorUpdatingSearchableOption() { final UpdateSearchableOptionRequest request = UpdateSearchableOptionRequest.newBuilder() .setProfileId(Util.PROFILE_ID.toString()).setAuthenticationIdentifier(Util.PHONE_PROVIDER) - .setAuthenticationType(AuthenticationType.PHONE.toString()) + .setAuthenticationType(AuthenticationType.PHONE.name()) .setSearchOption(SearchableOption.SEARCH_DISABLED).build(); given(accountRepositoryAdditional.updateSearchableOption(Mockito.any(UUID.class), Mockito.any(String.class), @@ -2093,7 +2093,7 @@ public class AccountServiceTests extends GrpcServerTestBase { @Test public void testUpdateSearchableOptionMissingAuthenticationProviderIdentifier() { final UpdateSearchableOptionRequest request = UpdateSearchableOptionRequest.newBuilder() - .setProfileId(Util.PROFILE_ID.toString()).setAuthenticationType(AuthenticationType.PHONE.toString()) + .setProfileId(Util.PROFILE_ID.toString()).setAuthenticationType(AuthenticationType.PHONE.name()) .setSearchOption(SearchableOption.SEARCH_DISABLED).build(); final StatusResponse reply = accountServiceBlockingStub.updateSearchableOption(request); @@ -2104,8 +2104,7 @@ public class AccountServiceTests extends GrpcServerTestBase { @Test public void testUpdateSearchableOptionMissingProfileId() { final UpdateSearchableOptionRequest request = UpdateSearchableOptionRequest.newBuilder() - .setAuthenticationIdentifier(Util.PHONE_PROVIDER) - .setAuthenticationType(AuthenticationType.PHONE.toString()) + .setAuthenticationIdentifier(Util.PHONE_PROVIDER).setAuthenticationType(AuthenticationType.PHONE.name()) .setSearchOption(SearchableOption.SEARCH_DISABLED).build(); final StatusResponse reply = accountServiceBlockingStub.updateSearchableOption(request); @@ -2117,7 +2116,7 @@ public class AccountServiceTests extends GrpcServerTestBase { public void testUpdateSearchableOptionInvalidProfileId() { final UpdateSearchableOptionRequest request = UpdateSearchableOptionRequest.newBuilder() .setProfileId(Util.INVALID_PROFILE_ID).setAuthenticationIdentifier(Util.PHONE_PROVIDER) - .setAuthenticationType(AuthenticationType.PHONE.toString()) + .setAuthenticationType(AuthenticationType.PHONE.name()) .setSearchOption(SearchableOption.SEARCH_DISABLED).build(); final StatusResponse reply = accountServiceBlockingStub.updateSearchableOption(request); @@ -2129,7 +2128,7 @@ public class AccountServiceTests extends GrpcServerTestBase { public void testUpdateSearchableOptionInvalidAuthenticationProviderType() { final UpdateSearchableOptionRequest request = UpdateSearchableOptionRequest.newBuilder() .setProfileId(Util.PROFILE_ID.toString()).setAuthenticationIdentifier("Facebook_provider") - .setAuthenticationType(AuthenticationType.FACEBOOK.toString()) + .setAuthenticationType(AuthenticationType.FACEBOOK.name()) .setSearchOption(SearchableOption.SEARCH_DISABLED).build(); final StatusResponse reply = accountServiceBlockingStub.updateSearchableOption(request); -- GitLab