diff --git a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java index fff536629c6105cacbba6477ca756355947aad76..6f298cc542df8b4e40d8fea510b568e28bf3114d 100644 --- a/src/main/java/biz/nynja/account/services/AccountServiceImpl.java +++ b/src/main/java/biz/nynja/account/services/AccountServiceImpl.java @@ -234,6 +234,14 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas return; } + if (request.getAuthenticationType() == AuthenticationType.PHONE) { + // Get the normalized phone number from libphone + CreatePendingAccountRequest newRequest = CreatePendingAccountRequest.newBuilder() + .setAuthenticationType(request.getAuthenticationType()) + .setAuthenticationProvider(validator.getNormalizedPhoneNumber(request.getAuthenticationProvider())).build(); + request = newRequest; + } + PendingAccountByAuthenticationProvider foundExistingPendingAccount = accountRepositoryAdditional .findSameAuthenticationProviderInPendingAccount( AuthenticationProvider.createAuthenticationProviderFromStrings( @@ -268,11 +276,6 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas PendingAccount pendingAccount = PendingAccount.fromProto(request); - if (request.getAuthenticationType() == AuthenticationType.PHONE) { - // Get the normalized phone number from libphone - pendingAccount.setAuthenticationProvider(validator.getNormalizedPhoneNumber(request.getAuthenticationProvider())); - } - pendingAccount.setAccountId(UUID.randomUUID()); pendingAccount.setProfileId(UUID.randomUUID()); pendingAccount.setCreationTimestamp(new Date().getTime()); @@ -494,7 +497,7 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas responseObserver.onCompleted(); return; } - + if (request.getAuthenticationProvider().getAuthenticationType() == AuthenticationType.PHONE) { // Get the normalized phone number from libphone AuthProviderDetails newAuthProviderDetails = AuthProviderDetails.newBuilder() @@ -507,7 +510,6 @@ public class AccountServiceImpl extends AccountServiceGrpc.AccountServiceImplBas request = newRequest; } - // Make sure that the requested profile id for update exists in DB. Profile profile = profileRepository.findByProfileId(UUID.fromString(request.getProfileId())); if (profile == null) { diff --git a/src/test/java/biz/nynja/account/components/AccountServiceHelperTests.java b/src/test/java/biz/nynja/account/components/AccountServiceHelperTests.java index fcfcb5dd1d79159c8b95e4f0fbc651efb23ad8b8..ef4101673b036327f97fc26749052909697faf8b 100644 --- a/src/test/java/biz/nynja/account/components/AccountServiceHelperTests.java +++ b/src/test/java/biz/nynja/account/components/AccountServiceHelperTests.java @@ -27,6 +27,7 @@ import biz.nynja.account.utils.Util; @SpringBootTest(classes = { Util.class, CassandraTestsConfig.class }, webEnvironment = WebEnvironment.RANDOM_PORT, properties = { + "grpc.port=${grpc.unitTest.port.accountServiceTest}", "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.cassandra.CassandraAutoConfiguration", "spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.cassandra.CassandraDataAutoConfiguration" }) @ActiveProfiles("dev") diff --git a/src/test/java/biz/nynja/account/components/LibphoneNormalizationParameterizedTest.java b/src/test/java/biz/nynja/account/components/LibphoneNormalizationParameterizedTest.java index 19a76cd06f730585b89a6c201e62a681a1e932bc..71e74d3f399b32c7ce7b42f8d4aed3e8f703fe17 100644 --- a/src/test/java/biz/nynja/account/components/LibphoneNormalizationParameterizedTest.java +++ b/src/test/java/biz/nynja/account/components/LibphoneNormalizationParameterizedTest.java @@ -13,6 +13,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.beans.factory.annotation.Configurable; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.TestContextManager; import org.springframework.test.context.TestExecutionListeners; @@ -30,11 +31,10 @@ import biz.nynja.account.services.AccountServiceImpl; @RunWith(Parameterized.class) @TestExecutionListeners({}) -@ContextConfiguration(classes = { AccountServiceImpl.class }) +@ContextConfiguration(classes = { Validator.class }) public class LibphoneNormalizationParameterizedTest { - @Autowired - private Validator validator; + private Validator validator = new Validator(); private String expectedPhoneNumber; private String inputPhoneNumber; @@ -52,12 +52,11 @@ public class LibphoneNormalizationParameterizedTest { @Parameterized.Parameters public static Collection phoneNumbers() { - return Arrays.asList(new Object[][] { { "359887345234", "BG:+359887345234" }, + return Arrays.asList(new Object[][] { + { "359887345234", "BG:+359887345234" }, { "359887345234", "BG:00359887345234" }, - { "359887345234", "BG:359 887 345 234" }, - { "359887345234", "BG:359887345234567" }, - { "359887345234", "BG:359 887 345" }, - { "359887345234", "BG:359-887-345-234" } }); + { "359887345234", "BG:359 887 345 234" }, + { "359887345234", "BG:359-887-345-234" } }); } @Test