From 8c0b93a51f94616de10ba99e265ee95ffe2fbd0a Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Tue, 21 Jan 2025 23:07:20 +0300 Subject: [PATCH 01/12] AYS-660 | Error Message and Code for `AysUserNotActiveAuthException` Has Been Changed --- .../AysUserNotActiveAuthException.java | 37 +++++++++++++++++++ .../exception/AysUserNotActiveException.java | 30 +++++---------- .../auth/service/AysUserUpdateService.java | 4 +- .../auth/service/impl/AysAuthServiceImpl.java | 12 +++--- .../impl/AysUserPasswordServiceImpl.java | 6 +-- .../impl/AysUserUpdateServiceImpl.java | 2 +- .../service/impl/AysAuthServiceImplTest.java | 6 +-- .../impl/AysUserPasswordServiceImplTest.java | 4 +- .../impl/AysUserUpdateServiceImplTest.java | 4 +- 9 files changed, 65 insertions(+), 40 deletions(-) create mode 100644 src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java diff --git a/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java b/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java new file mode 100644 index 000000000..bda4cc3cc --- /dev/null +++ b/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java @@ -0,0 +1,37 @@ +package org.ays.auth.exception; + +import org.ays.auth.model.enums.AysUserStatus; +import org.ays.common.exception.AysAuthException; + +import java.io.Serial; + +/** + * Exception thrown when attempting to authenticate a user that is not active. + */ +public final class AysUserNotActiveAuthException extends AysAuthException { + + /** + * Unique identifier for serialization. + */ + @Serial + private static final long serialVersionUID = -5218287176856317070L; + + /** + * Constructs a new AysUserNotActiveAuthException with the specified userId. + * + * @param userId the userId of the user that is not active + */ + public AysUserNotActiveAuthException(String userId) { + super("user is not active! userId:" + userId); + } + + /** + * Constructs a new AysUserNotActiveAuthException with the specified user status. + * + * @param status the status of the user that is not active + */ + public AysUserNotActiveAuthException(AysUserStatus status) { + super("user is not active! currentStatus: " + status.name()); + } + +} diff --git a/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java b/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java index 647b70ac1..7f1078db3 100644 --- a/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java +++ b/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java @@ -1,37 +1,25 @@ package org.ays.auth.exception; -import org.ays.auth.model.enums.AysUserStatus; -import org.ays.common.exception.AysAuthException; +import org.ays.common.exception.AysConflictException; import java.io.Serial; /** - * Exception thrown when attempting to authenticate a user that is not active. + * Exception thrown when a user does not in an active state. + * This exception extends {@link AysConflictException}. */ -public final class AysUserNotActiveException extends AysAuthException { +public final class AysUserNotActiveException extends AysConflictException { /** - * Unique identifier for serialization. + * Unique serial version ID. */ @Serial - private static final long serialVersionUID = -5218287176856317070L; + private static final long serialVersionUID = 3508025652421021710L; /** - * Constructs a new UserNotActiveException with the specified userId. - * - * @param userId the userId of the user that is not active + * Constructs a new {@link AysUserNotActiveException} with the specified detail message. */ - public AysUserNotActiveException(String userId) { - super("user is not active! userId:" + userId); + public AysUserNotActiveException() { + super("user is already passive!"); } - - /** - * Constructs a new UserNotActiveException with the specified user status. - * - * @param status the status of the user that is not active - */ - public AysUserNotActiveException(AysUserStatus status) { - super("user is not active! currentStatus: " + status.name()); - } - } diff --git a/src/main/java/org/ays/auth/service/AysUserUpdateService.java b/src/main/java/org/ays/auth/service/AysUserUpdateService.java index 58189667b..bca58c9a3 100644 --- a/src/main/java/org/ays/auth/service/AysUserUpdateService.java +++ b/src/main/java/org/ays/auth/service/AysUserUpdateService.java @@ -1,6 +1,6 @@ package org.ays.auth.service; -import org.ays.auth.exception.AysUserNotActiveException; +import org.ays.auth.exception.AysUserNotActiveAuthException; import org.ays.auth.exception.AysUserNotExistByIdException; import org.ays.auth.exception.AysUserNotPassiveException; import org.ays.auth.model.request.AysUserUpdateRequest; @@ -31,7 +31,7 @@ public interface AysUserUpdateService { * * @param id The unique identifier of the user to be passivated. * @throws AysUserNotExistByIdException if a user with the given ID does not exist. - * @throws AysUserNotActiveException if the user is not in an active state. + * @throws AysUserNotActiveAuthException if the user is not in an active state. */ void passivate(String id); diff --git a/src/main/java/org/ays/auth/service/impl/AysAuthServiceImpl.java b/src/main/java/org/ays/auth/service/impl/AysAuthServiceImpl.java index 1f6153ac2..9bdcf0795 100644 --- a/src/main/java/org/ays/auth/service/impl/AysAuthServiceImpl.java +++ b/src/main/java/org/ays/auth/service/impl/AysAuthServiceImpl.java @@ -6,7 +6,7 @@ import org.ays.auth.exception.AysPasswordNotValidException; import org.ays.auth.exception.AysUserDoesNotAccessPageException; import org.ays.auth.exception.AysUserIdNotValidException; -import org.ays.auth.exception.AysUserNotActiveException; +import org.ays.auth.exception.AysUserNotActiveAuthException; import org.ays.auth.model.AysIdentity; import org.ays.auth.model.AysRole; import org.ays.auth.model.AysToken; @@ -64,7 +64,7 @@ class AysAuthServiceImpl implements AysAuthService { * @return {@link AysToken} representing the access token generated upon successful authentication. * @throws AysEmailAddressNotValidException If the provided email address is not valid or does not exist. * @throws AysPasswordNotValidException If the provided password is not valid. - * @throws AysUserNotActiveException If the user's status is not active. + * @throws AysUserNotActiveAuthException If the user's status is not active. * @throws AysUserDoesNotAccessPageException If the user does not have permission to access the requested page. */ @Override @@ -125,7 +125,7 @@ private void validateUserSourcePagePermission(final AysUser user, * @param refreshToken The refresh token used to generate a new access token. * @return A new {@link AysToken} containing the refreshed access token. * @throws AysUserIdNotValidException If the user ID extracted from the refresh token is not valid. - * @throws AysUserNotActiveException If the user associated with the refresh token is not active. + * @throws AysUserNotActiveAuthException If the user associated with the refresh token is not active. */ @Override public AysToken refreshAccessToken(final String refreshToken) { @@ -151,15 +151,15 @@ public AysToken refreshAccessToken(final String refreshToken) { /** * Validates the status of the user. - * Throws {@link AysUserNotActiveException} if the user is not active. + * Throws {@link AysUserNotActiveAuthException} if the user is not active. * * @param user The {@link AysUser} object whose status needs to be validated. - * @throws AysUserNotActiveException If the user is not active. + * @throws AysUserNotActiveAuthException If the user is not active. */ private void validateUserStatus(final AysUser user) { if (!user.isActive()) { - throw new AysUserNotActiveException(user.getId()); + throw new AysUserNotActiveAuthException(user.getId()); } } diff --git a/src/main/java/org/ays/auth/service/impl/AysUserPasswordServiceImpl.java b/src/main/java/org/ays/auth/service/impl/AysUserPasswordServiceImpl.java index 86d8489fc..508cd2336 100644 --- a/src/main/java/org/ays/auth/service/impl/AysUserPasswordServiceImpl.java +++ b/src/main/java/org/ays/auth/service/impl/AysUserPasswordServiceImpl.java @@ -2,8 +2,8 @@ import lombok.RequiredArgsConstructor; import org.ays.auth.exception.AysEmailAddressNotValidException; -import org.ays.auth.exception.AysUserNotActiveException; import org.ays.auth.exception.AysUserDoesNotAccessPageException; +import org.ays.auth.exception.AysUserNotActiveAuthException; import org.ays.auth.exception.AysUserPasswordCannotChangedException; import org.ays.auth.exception.AysUserPasswordDoesNotExistException; import org.ays.auth.model.AysRole; @@ -52,7 +52,7 @@ class AysUserPasswordServiceImpl implements AysUserPasswordService { * * @param forgotPasswordRequest the request containing the user's email address. * @throws AysEmailAddressNotValidException if the email address does not correspond to any existing user. - * @throws AysUserNotActiveException if the user status is not active. + * @throws AysUserNotActiveAuthException if the user status is not active. * @throws AysUserDoesNotAccessPageException if the user lacks permission to access the source page. */ @Override @@ -64,7 +64,7 @@ public void forgotPassword(final AysPasswordForgotRequest forgotPasswordRequest) .orElseThrow(() -> new AysEmailAddressNotValidException(emailAddress)); if(!user.isActive()) { - throw new AysUserNotActiveException(user.getStatus()); + throw new AysUserNotActiveAuthException(user.getStatus()); } this.validateUserSourcePagePermission(user); diff --git a/src/main/java/org/ays/auth/service/impl/AysUserUpdateServiceImpl.java b/src/main/java/org/ays/auth/service/impl/AysUserUpdateServiceImpl.java index 77195d970..c42a09d23 100644 --- a/src/main/java/org/ays/auth/service/impl/AysUserUpdateServiceImpl.java +++ b/src/main/java/org/ays/auth/service/impl/AysUserUpdateServiceImpl.java @@ -141,7 +141,7 @@ public void passivate(String id) { .orElseThrow(() -> new AysUserNotExistByIdException(id)); if (!user.isActive()) { - throw new AysUserNotActiveException(id); + throw new AysUserNotActiveException(); } user.passivate(); diff --git a/src/test/java/org/ays/auth/service/impl/AysAuthServiceImplTest.java b/src/test/java/org/ays/auth/service/impl/AysAuthServiceImplTest.java index 42e6c170d..040539f38 100644 --- a/src/test/java/org/ays/auth/service/impl/AysAuthServiceImplTest.java +++ b/src/test/java/org/ays/auth/service/impl/AysAuthServiceImplTest.java @@ -8,7 +8,7 @@ import org.ays.auth.exception.AysTokenNotValidException; import org.ays.auth.exception.AysUserDoesNotAccessPageException; import org.ays.auth.exception.AysUserIdNotValidException; -import org.ays.auth.exception.AysUserNotActiveException; +import org.ays.auth.exception.AysUserNotActiveAuthException; import org.ays.auth.model.AysIdentity; import org.ays.auth.model.AysPermission; import org.ays.auth.model.AysPermissionBuilder; @@ -284,7 +284,7 @@ void givenValidLoginRequest_whenUserNotActive_thenThrowUserNotActiveException() // Then Assertions.assertThrows( - AysUserNotActiveException.class, + AysUserNotActiveAuthException.class, () -> userAuthService.authenticate(mockLoginRequest) ); @@ -606,7 +606,7 @@ void givenValidRefreshToken_whenUserNotActive_thenThrowUserNotActiveException() // Then Assertions.assertThrows( - AysUserNotActiveException.class, + AysUserNotActiveAuthException.class, () -> userAuthService.refreshAccessToken(mockRefreshToken) ); diff --git a/src/test/java/org/ays/auth/service/impl/AysUserPasswordServiceImplTest.java b/src/test/java/org/ays/auth/service/impl/AysUserPasswordServiceImplTest.java index 720394ae6..cee3974d3 100644 --- a/src/test/java/org/ays/auth/service/impl/AysUserPasswordServiceImplTest.java +++ b/src/test/java/org/ays/auth/service/impl/AysUserPasswordServiceImplTest.java @@ -2,8 +2,8 @@ import org.ays.AysUnitTest; import org.ays.auth.exception.AysEmailAddressNotValidException; -import org.ays.auth.exception.AysUserNotActiveException; import org.ays.auth.exception.AysUserDoesNotAccessPageException; +import org.ays.auth.exception.AysUserNotActiveAuthException; import org.ays.auth.exception.AysUserPasswordCannotChangedException; import org.ays.auth.exception.AysUserPasswordDoesNotExistException; import org.ays.auth.model.AysRole; @@ -206,7 +206,7 @@ void givenValidForgotPasswordRequest_whenUserStatusNotActive_thenThrowUserNotAct // Then Assertions.assertThrows( - AysUserNotActiveException.class, + AysUserNotActiveAuthException.class, () -> userPasswordService.forgotPassword(mockForgotPasswordRequest) ); diff --git a/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java b/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java index 6efb70b04..62cad7015 100644 --- a/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java +++ b/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java @@ -6,7 +6,7 @@ import org.ays.auth.exception.AysUserAlreadyExistsByEmailAddressException; import org.ays.auth.exception.AysUserAlreadyExistsByPhoneNumberException; import org.ays.auth.exception.AysUserIsNotActiveOrPassiveException; -import org.ays.auth.exception.AysUserNotActiveException; +import org.ays.auth.exception.AysUserNotActiveAuthException; import org.ays.auth.exception.AysUserNotExistByIdException; import org.ays.auth.exception.AysUserNotPassiveException; import org.ays.auth.model.AysIdentity; @@ -986,7 +986,7 @@ void givenValidId_whenUserIsNotActive_thenThrowAysUserNotActiveException() { // Then Assertions.assertThrows( - AysUserNotActiveException.class, + AysUserNotActiveAuthException.class, () -> userUpdateService.passivate(mockId) ); From 265740298dacdea9f8349bb6231c40f83337b77d Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Thu, 23 Jan 2025 02:51:47 +0300 Subject: [PATCH 02/12] AYS-660 | `AysUserAlreadyPassiveException` and Tests Are Added --- .../AysUserAlreadyPassiveException.java | 26 ++++++++++ .../AysUserNotActiveAuthException.java | 2 +- .../exception/AysUserNotActiveException.java | 7 ++- .../impl/AysUserUpdateServiceImpl.java | 9 +++- .../auth/controller/AysUserEndToEndTest.java | 52 +++++++++++++++++++ .../impl/AysUserUpdateServiceImplTest.java | 47 +++++++++++++++-- 6 files changed, 135 insertions(+), 8 deletions(-) create mode 100644 src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java diff --git a/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java b/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java new file mode 100644 index 000000000..ea7283ab3 --- /dev/null +++ b/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java @@ -0,0 +1,26 @@ +package org.ays.auth.exception; + +import org.ays.common.exception.AysConflictException; + +import java.io.Serial; + +/** + * Exception thrown when a user is in a passive state. + * This exception extends {@link AysConflictException}. + */ +public final class AysUserAlreadyPassiveException extends AysConflictException { + + /** + * Unique serial version ID. + */ + @Serial + private static final long serialVersionUID = 2484662602911824448L; + + /** + * Constructs a new {@link AysUserAlreadyPassiveException} with the specified detail message. + */ + public AysUserAlreadyPassiveException() { + super("user is already passive!"); + } + +} diff --git a/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java b/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java index bda4cc3cc..68c09be53 100644 --- a/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java +++ b/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java @@ -14,7 +14,7 @@ public final class AysUserNotActiveAuthException extends AysAuthException { * Unique identifier for serialization. */ @Serial - private static final long serialVersionUID = -5218287176856317070L; + private static final long serialVersionUID = -3010480609839859754L; /** * Constructs a new AysUserNotActiveAuthException with the specified userId. diff --git a/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java b/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java index 7f1078db3..e83b1ded4 100644 --- a/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java +++ b/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java @@ -18,8 +18,11 @@ public final class AysUserNotActiveException extends AysConflictException { /** * Constructs a new {@link AysUserNotActiveException} with the specified detail message. + * + * @param userId the id of the user that is not active */ - public AysUserNotActiveException() { - super("user is already passive!"); + public AysUserNotActiveException(String userId) { + super("user is not active! userId:" + userId); } + } diff --git a/src/main/java/org/ays/auth/service/impl/AysUserUpdateServiceImpl.java b/src/main/java/org/ays/auth/service/impl/AysUserUpdateServiceImpl.java index c42a09d23..13dcd8f1d 100644 --- a/src/main/java/org/ays/auth/service/impl/AysUserUpdateServiceImpl.java +++ b/src/main/java/org/ays/auth/service/impl/AysUserUpdateServiceImpl.java @@ -5,6 +5,7 @@ import org.ays.auth.exception.AysUserAlreadyDeletedException; import org.ays.auth.exception.AysUserAlreadyExistsByEmailAddressException; import org.ays.auth.exception.AysUserAlreadyExistsByPhoneNumberException; +import org.ays.auth.exception.AysUserAlreadyPassiveException; import org.ays.auth.exception.AysUserIsNotActiveOrPassiveException; import org.ays.auth.exception.AysUserNotActiveException; import org.ays.auth.exception.AysUserNotExistByIdException; @@ -131,7 +132,7 @@ public void activate(String id) { * * @param id The unique identifier of the user to be passivated. * @throws AysUserNotExistByIdException if a user with the given ID does not exist. - * @throws AysUserNotActiveException if the user is not in an active state and cannot be passivated. + * @throws AysUserAlreadyPassiveException if the user is in a passive state. */ @Override public void passivate(String id) { @@ -140,8 +141,12 @@ public void passivate(String id) { .filter(userFromDatabase -> identity.getInstitutionId().equals(userFromDatabase.getInstitution().getId())) .orElseThrow(() -> new AysUserNotExistByIdException(id)); + if (user.isPassive()) { + throw new AysUserAlreadyPassiveException(); + } + if (!user.isActive()) { - throw new AysUserNotActiveException(); + throw new AysUserNotActiveException(id); } user.passivate(); diff --git a/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java b/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java index 2f56f316f..0d5578985 100644 --- a/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java +++ b/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java @@ -19,6 +19,8 @@ import org.ays.auth.port.AysUserSavePort; import org.ays.common.model.AysPhoneNumberBuilder; import org.ays.common.model.request.AysPhoneNumberRequestBuilder; +import org.ays.common.model.response.AysErrorResponse; +import org.ays.common.model.response.AysErrorResponseBuilder; import org.ays.common.model.response.AysPageResponse; import org.ays.common.model.response.AysResponse; import org.ays.common.model.response.AysResponseBuilder; @@ -33,6 +35,7 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; import java.util.List; import java.util.Optional; @@ -596,4 +599,53 @@ void givenValidId_whenPassivateUser_thenReturnSuccess() throws Exception { Assertions.assertTrue(UUIDTestUtil.isValid(userFromDatabase.get().getUpdatedUser())); } + @Test + void givenAlreadyPassiveUserId_whenTryToPassivate_thenReturnUserAlreadyPassiveError() throws Exception { + + // Initialize + Institution institution = new InstitutionBuilder() + .withId(AysValidTestData.Admin.INSTITUTION_ID) + .build(); + + List roles = roleReadPort.findAllActivesByInstitutionId(institution.getId()); + + AysUser user = userSavePort.save( + new AysUserBuilder() + .withValidValues() + .withoutId() + .withRoles(roles) + .withInstitution(institution) + .withStatus(AysUserStatus.PASSIVE) + .build() + ); + + // Given + String userId = user.getId(); + + // Then + String endpoint = BASE_PATH.concat("/user/").concat(userId).concat("/passivate"); + MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders + .patch(endpoint, adminToken.getAccessToken()); + + AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.CONFLICT_ERROR; + + aysMockMvc.perform(mockHttpServletRequestBuilder, mockErrorResponse) + .andExpect(AysMockResultMatchersBuilders.status() + .isConflict()) + .andExpect(MockMvcResultMatchers.jsonPath("$.message") + .value("user is already passive!")) + .andExpect(MockMvcResultMatchers.jsonPath("$.isSuccess") + .value(false)) + .andExpect(MockMvcResultMatchers.jsonPath("$.time").exists()) + .andExpect(MockMvcResultMatchers.jsonPath("$.code").exists()); + + // Verify + Optional userFromDatabase = userReadPort.findById(userId); + + Assertions.assertTrue(userFromDatabase.isPresent()); + Assertions.assertEquals(userFromDatabase.get().getId(), user.getId()); + Assertions.assertEquals(AysUserStatus.PASSIVE, userFromDatabase.get().getStatus()); + Assertions.assertTrue(UUIDTestUtil.isValid(userFromDatabase.get().getUpdatedUser())); + } + } diff --git a/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java b/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java index 62cad7015..2b64976e9 100644 --- a/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java +++ b/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java @@ -5,8 +5,9 @@ import org.ays.auth.exception.AysUserAlreadyDeletedException; import org.ays.auth.exception.AysUserAlreadyExistsByEmailAddressException; import org.ays.auth.exception.AysUserAlreadyExistsByPhoneNumberException; +import org.ays.auth.exception.AysUserAlreadyPassiveException; import org.ays.auth.exception.AysUserIsNotActiveOrPassiveException; -import org.ays.auth.exception.AysUserNotActiveAuthException; +import org.ays.auth.exception.AysUserNotActiveException; import org.ays.auth.exception.AysUserNotExistByIdException; import org.ays.auth.exception.AysUserNotPassiveException; import org.ays.auth.model.AysIdentity; @@ -961,6 +962,46 @@ void givenValidUserId_whenUserNotFound_thenThrowAysUserNotExistByIdException() { .save(Mockito.any(AysUser.class)); } + @Test + void givenValidId_whenUserIsAlreadyPassive_thenThrowAysUserAlreadyPassiveException() { + + // Given + String mockId = "b64ef470-6842-400f-ba23-2379c589095c"; + + // When + Institution mockInstitution = new InstitutionBuilder() + .withValidValues() + .build(); + Mockito.when(identity.getInstitutionId()) + .thenReturn(mockInstitution.getId()); + + AysUser mockUser = new AysUserBuilder() + .withValidValues() + .withId(mockId) + .withInstitution(mockInstitution) + .withStatus(AysUserStatus.PASSIVE) + .build(); + + Mockito.when(userReadPort.findById(Mockito.anyString())) + .thenReturn(Optional.of(mockUser)); + + // Then + Assertions.assertThrows( + AysUserAlreadyPassiveException.class, + () -> userUpdateService.passivate(mockId) + ); + + // Verify + Mockito.verify(identity, Mockito.times(1)) + .getInstitutionId(); + + Mockito.verify(userReadPort, Mockito.times(1)) + .findById(Mockito.anyString()); + + Mockito.verify(userSavePort, Mockito.never()) + .save(Mockito.any(AysUser.class)); + } + @Test void givenValidId_whenUserIsNotActive_thenThrowAysUserNotActiveException() { @@ -978,7 +1019,7 @@ void givenValidId_whenUserIsNotActive_thenThrowAysUserNotActiveException() { .withValidValues() .withId(mockId) .withInstitution(mockInstitution) - .withStatus(AysUserStatus.PASSIVE) // Not active + .withStatus(AysUserStatus.NOT_VERIFIED) .build(); Mockito.when(userReadPort.findById(Mockito.anyString())) @@ -986,7 +1027,7 @@ void givenValidId_whenUserIsNotActive_thenThrowAysUserNotActiveException() { // Then Assertions.assertThrows( - AysUserNotActiveAuthException.class, + AysUserNotActiveException.class, () -> userUpdateService.passivate(mockId) ); From 742a5bbb7328edb6dfbea62421577814dde0c1d8 Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Thu, 23 Jan 2025 03:02:52 +0300 Subject: [PATCH 03/12] AYS-660 | serialVersionUID is fixed --- .../org/ays/auth/exception/AysUserNotActiveAuthException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java b/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java index 68c09be53..bda4cc3cc 100644 --- a/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java +++ b/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java @@ -14,7 +14,7 @@ public final class AysUserNotActiveAuthException extends AysAuthException { * Unique identifier for serialization. */ @Serial - private static final long serialVersionUID = -3010480609839859754L; + private static final long serialVersionUID = -5218287176856317070L; /** * Constructs a new AysUserNotActiveAuthException with the specified userId. From b36e06e6ae3212a3c19e6aff52d7a181cd48fb36 Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Thu, 23 Jan 2025 03:04:54 +0300 Subject: [PATCH 04/12] AYS-660 | Javadocs Have Been Fixed --- .../org/ays/auth/exception/AysUserNotActiveException.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java b/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java index e83b1ded4..71a018be4 100644 --- a/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java +++ b/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java @@ -11,13 +11,13 @@ public final class AysUserNotActiveException extends AysConflictException { /** - * Unique serial version ID. + * Unique identifier for serialization. */ @Serial private static final long serialVersionUID = 3508025652421021710L; /** - * Constructs a new {@link AysUserNotActiveException} with the specified detail message. + * Constructs a new {@link AysUserNotActiveException} with the specified userId. * * @param userId the id of the user that is not active */ From 823853a24ec9bec54a3e43b59bafe4de9bf2d8b3 Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Thu, 23 Jan 2025 03:13:26 +0300 Subject: [PATCH 05/12] AYS-660 | Javadocs Have Been Fixed --- .../java/org/ays/auth/service/AysUserUpdateService.java | 6 ++++-- .../org/ays/auth/service/impl/AysUserUpdateServiceImpl.java | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/ays/auth/service/AysUserUpdateService.java b/src/main/java/org/ays/auth/service/AysUserUpdateService.java index bca58c9a3..d2323b2a4 100644 --- a/src/main/java/org/ays/auth/service/AysUserUpdateService.java +++ b/src/main/java/org/ays/auth/service/AysUserUpdateService.java @@ -1,6 +1,7 @@ package org.ays.auth.service; -import org.ays.auth.exception.AysUserNotActiveAuthException; +import org.ays.auth.exception.AysUserAlreadyPassiveException; +import org.ays.auth.exception.AysUserNotActiveException; import org.ays.auth.exception.AysUserNotExistByIdException; import org.ays.auth.exception.AysUserNotPassiveException; import org.ays.auth.model.request.AysUserUpdateRequest; @@ -31,7 +32,8 @@ public interface AysUserUpdateService { * * @param id The unique identifier of the user to be passivated. * @throws AysUserNotExistByIdException if a user with the given ID does not exist. - * @throws AysUserNotActiveAuthException if the user is not in an active state. + * @throws AysUserAlreadyPassiveException if the user is already in a passive state. + * @throws AysUserNotActiveException if the user is not in an active state. */ void passivate(String id); diff --git a/src/main/java/org/ays/auth/service/impl/AysUserUpdateServiceImpl.java b/src/main/java/org/ays/auth/service/impl/AysUserUpdateServiceImpl.java index 13dcd8f1d..a41492c78 100644 --- a/src/main/java/org/ays/auth/service/impl/AysUserUpdateServiceImpl.java +++ b/src/main/java/org/ays/auth/service/impl/AysUserUpdateServiceImpl.java @@ -132,7 +132,8 @@ public void activate(String id) { * * @param id The unique identifier of the user to be passivated. * @throws AysUserNotExistByIdException if a user with the given ID does not exist. - * @throws AysUserAlreadyPassiveException if the user is in a passive state. + * @throws AysUserAlreadyPassiveException if the user is already in a passive state. + * @throws AysUserNotActiveException if the user is not in an active state. */ @Override public void passivate(String id) { From 43a431f19e65f56c22f30beaab343fe7efdf37b7 Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Thu, 23 Jan 2025 03:14:48 +0300 Subject: [PATCH 06/12] AYS-660 | Javadocs Have Been Fixed for `AysUserAlreadyPassiveException` --- .../org/ays/auth/exception/AysUserAlreadyPassiveException.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java b/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java index ea7283ab3..8185cc573 100644 --- a/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java +++ b/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java @@ -5,7 +5,7 @@ import java.io.Serial; /** - * Exception thrown when a user is in a passive state. + * Exception thrown when a user is already in a passive state. * This exception extends {@link AysConflictException}. */ public final class AysUserAlreadyPassiveException extends AysConflictException { From 24901f7cd0de242c9bfe8e6821079bb9deec5591 Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Thu, 23 Jan 2025 03:50:48 +0300 Subject: [PATCH 07/12] AYS-660 | More more more Javadocs Have Been Fixed --- .../org/ays/auth/exception/AysUserAlreadyPassiveException.java | 2 +- src/main/java/org/ays/auth/service/impl/AysAuthServiceImpl.java | 1 - src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java | 1 - 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java b/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java index 8185cc573..890897950 100644 --- a/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java +++ b/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java @@ -17,7 +17,7 @@ public final class AysUserAlreadyPassiveException extends AysConflictException { private static final long serialVersionUID = 2484662602911824448L; /** - * Constructs a new {@link AysUserAlreadyPassiveException} with the specified detail message. + * Constructs a new AysUserAlreadyPassiveException with the specified detail message. */ public AysUserAlreadyPassiveException() { super("user is already passive!"); diff --git a/src/main/java/org/ays/auth/service/impl/AysAuthServiceImpl.java b/src/main/java/org/ays/auth/service/impl/AysAuthServiceImpl.java index 9bdcf0795..8ba6e3bff 100644 --- a/src/main/java/org/ays/auth/service/impl/AysAuthServiceImpl.java +++ b/src/main/java/org/ays/auth/service/impl/AysAuthServiceImpl.java @@ -151,7 +151,6 @@ public AysToken refreshAccessToken(final String refreshToken) { /** * Validates the status of the user. - * Throws {@link AysUserNotActiveAuthException} if the user is not active. * * @param user The {@link AysUser} object whose status needs to be validated. * @throws AysUserNotActiveAuthException If the user is not active. diff --git a/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java b/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java index 0d5578985..62f5e1948 100644 --- a/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java +++ b/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java @@ -645,7 +645,6 @@ void givenAlreadyPassiveUserId_whenTryToPassivate_thenReturnUserAlreadyPassiveEr Assertions.assertTrue(userFromDatabase.isPresent()); Assertions.assertEquals(userFromDatabase.get().getId(), user.getId()); Assertions.assertEquals(AysUserStatus.PASSIVE, userFromDatabase.get().getStatus()); - Assertions.assertTrue(UUIDTestUtil.isValid(userFromDatabase.get().getUpdatedUser())); } } From f47934844b2a81b6598bbf3b747f12824539b3e6 Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Thu, 23 Jan 2025 04:08:52 +0300 Subject: [PATCH 08/12] AYS-660 | fix. --- .../ays/auth/exception/AysUserAlreadyPassiveException.java | 2 +- .../org/ays/auth/exception/AysUserNotActiveAuthException.java | 4 ++-- .../org/ays/auth/exception/AysUserNotActiveException.java | 4 ++-- .../java/org/ays/auth/controller/AysUserEndToEndTest.java | 1 + 4 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java b/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java index 890897950..9ff0c208a 100644 --- a/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java +++ b/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java @@ -11,7 +11,7 @@ public final class AysUserAlreadyPassiveException extends AysConflictException { /** - * Unique serial version ID. + * Unique identifier for serialization. */ @Serial private static final long serialVersionUID = 2484662602911824448L; diff --git a/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java b/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java index bda4cc3cc..9e0325db5 100644 --- a/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java +++ b/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java @@ -19,7 +19,7 @@ public final class AysUserNotActiveAuthException extends AysAuthException { /** * Constructs a new AysUserNotActiveAuthException with the specified userId. * - * @param userId the userId of the user that is not active + * @param userId the id of the user that is not active. */ public AysUserNotActiveAuthException(String userId) { super("user is not active! userId:" + userId); @@ -28,7 +28,7 @@ public AysUserNotActiveAuthException(String userId) { /** * Constructs a new AysUserNotActiveAuthException with the specified user status. * - * @param status the status of the user that is not active + * @param status the status of the user that is not active. */ public AysUserNotActiveAuthException(AysUserStatus status) { super("user is not active! currentStatus: " + status.name()); diff --git a/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java b/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java index 71a018be4..5019fc9a7 100644 --- a/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java +++ b/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java @@ -17,9 +17,9 @@ public final class AysUserNotActiveException extends AysConflictException { private static final long serialVersionUID = 3508025652421021710L; /** - * Constructs a new {@link AysUserNotActiveException} with the specified userId. + * Constructs a new AysUserNotActiveException with the specified userId. * - * @param userId the id of the user that is not active + * @param userId the id of the user that is not active. */ public AysUserNotActiveException(String userId) { super("user is not active! userId:" + userId); diff --git a/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java b/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java index 62f5e1948..2ab3f968d 100644 --- a/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java +++ b/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java @@ -645,6 +645,7 @@ void givenAlreadyPassiveUserId_whenTryToPassivate_thenReturnUserAlreadyPassiveEr Assertions.assertTrue(userFromDatabase.isPresent()); Assertions.assertEquals(userFromDatabase.get().getId(), user.getId()); Assertions.assertEquals(AysUserStatus.PASSIVE, userFromDatabase.get().getStatus()); + Assertions.assertNull(userFromDatabase.get().getUpdatedUser()); } } From ab6234f5871dd1f7528106169d1e64577b58bd4d Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Thu, 23 Jan 2025 04:14:22 +0300 Subject: [PATCH 09/12] AYS-660 | javadocs have been changed --- .../org/ays/auth/exception/AysUserAlreadyPassiveException.java | 1 - .../java/org/ays/auth/exception/AysUserNotActiveException.java | 1 - 2 files changed, 2 deletions(-) diff --git a/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java b/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java index 9ff0c208a..0fff6a0ec 100644 --- a/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java +++ b/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java @@ -6,7 +6,6 @@ /** * Exception thrown when a user is already in a passive state. - * This exception extends {@link AysConflictException}. */ public final class AysUserAlreadyPassiveException extends AysConflictException { diff --git a/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java b/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java index 5019fc9a7..9a77aa311 100644 --- a/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java +++ b/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java @@ -6,7 +6,6 @@ /** * Exception thrown when a user does not in an active state. - * This exception extends {@link AysConflictException}. */ public final class AysUserNotActiveException extends AysConflictException { From 7a919dd580e1f65ca6dd8769eab9567c7d501162 Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Mon, 27 Jan 2025 16:07:32 +0300 Subject: [PATCH 10/12] AYS-660 | Tests and Javadocs Have Been Fixed --- .../AysUserAlreadyPassiveException.java | 2 +- .../AysUserNotActiveAuthException.java | 4 +- .../exception/AysUserNotActiveException.java | 2 +- .../auth/controller/AysUserEndToEndTest.java | 57 +++++++++++++++++-- .../impl/AysUserUpdateServiceImplTest.java | 14 +++-- 5 files changed, 66 insertions(+), 13 deletions(-) diff --git a/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java b/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java index 0fff6a0ec..b56b34a7f 100644 --- a/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java +++ b/src/main/java/org/ays/auth/exception/AysUserAlreadyPassiveException.java @@ -16,7 +16,7 @@ public final class AysUserAlreadyPassiveException extends AysConflictException { private static final long serialVersionUID = 2484662602911824448L; /** - * Constructs a new AysUserAlreadyPassiveException with the specified detail message. + * Constructs a new {@link AysUserAlreadyPassiveException} with the specified detail message. */ public AysUserAlreadyPassiveException() { super("user is already passive!"); diff --git a/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java b/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java index 9e0325db5..0f6eadd72 100644 --- a/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java +++ b/src/main/java/org/ays/auth/exception/AysUserNotActiveAuthException.java @@ -17,7 +17,7 @@ public final class AysUserNotActiveAuthException extends AysAuthException { private static final long serialVersionUID = -5218287176856317070L; /** - * Constructs a new AysUserNotActiveAuthException with the specified userId. + * Constructs a new {@link AysUserNotActiveAuthException}with the specified userId. * * @param userId the id of the user that is not active. */ @@ -26,7 +26,7 @@ public AysUserNotActiveAuthException(String userId) { } /** - * Constructs a new AysUserNotActiveAuthException with the specified user status. + * Constructs a new {@link AysUserNotActiveAuthException} with the specified user status. * * @param status the status of the user that is not active. */ diff --git a/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java b/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java index 9a77aa311..442f0bccd 100644 --- a/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java +++ b/src/main/java/org/ays/auth/exception/AysUserNotActiveException.java @@ -16,7 +16,7 @@ public final class AysUserNotActiveException extends AysConflictException { private static final long serialVersionUID = 3508025652421021710L; /** - * Constructs a new AysUserNotActiveException with the specified userId. + * Constructs a new {@link AysUserNotActiveException} with the specified userId. * * @param userId the id of the user that is not active. */ diff --git a/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java b/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java index 2ab3f968d..386b83e90 100644 --- a/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java +++ b/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java @@ -33,6 +33,8 @@ import org.ays.util.UUIDTestUtil; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; @@ -633,11 +635,7 @@ void givenAlreadyPassiveUserId_whenTryToPassivate_thenReturnUserAlreadyPassiveEr .andExpect(AysMockResultMatchersBuilders.status() .isConflict()) .andExpect(MockMvcResultMatchers.jsonPath("$.message") - .value("user is already passive!")) - .andExpect(MockMvcResultMatchers.jsonPath("$.isSuccess") - .value(false)) - .andExpect(MockMvcResultMatchers.jsonPath("$.time").exists()) - .andExpect(MockMvcResultMatchers.jsonPath("$.code").exists()); + .value("user is already passive!")); // Verify Optional userFromDatabase = userReadPort.findById(userId); @@ -648,4 +646,53 @@ void givenAlreadyPassiveUserId_whenTryToPassivate_thenReturnUserAlreadyPassiveEr Assertions.assertNull(userFromDatabase.get().getUpdatedUser()); } + @ParameterizedTest + @ValueSource(strings = { + "NOT_VERIFIED", + "DELETED" + }) + void givenInactiveUserId_whenTryToPassivate_thenReturnUserNotActiveError(String inactiveStatus) throws Exception { + + // Initialize + Institution institution = new InstitutionBuilder() + .withId(AysValidTestData.Admin.INSTITUTION_ID) + .build(); + + List roles = roleReadPort.findAllActivesByInstitutionId(institution.getId()); + + AysUser user = userSavePort.save( + new AysUserBuilder() + .withValidValues() + .withoutId() + .withRoles(roles) + .withInstitution(institution) + .withStatus(AysUserStatus.valueOf(inactiveStatus)) + .build() + ); + + // Given + String userId = user.getId(); + + // Then + String endpoint = BASE_PATH.concat("/user/").concat(userId).concat("/passivate"); + MockHttpServletRequestBuilder mockHttpServletRequestBuilder = AysMockMvcRequestBuilders + .patch(endpoint, adminToken.getAccessToken()); + + AysErrorResponse mockErrorResponse = AysErrorResponseBuilder.CONFLICT_ERROR; + + aysMockMvc.perform(mockHttpServletRequestBuilder, mockErrorResponse) + .andExpect(AysMockResultMatchersBuilders.status() + .isConflict()) + .andExpect(MockMvcResultMatchers.jsonPath("$.message") + .value("user is not active! userId:" + userId)); + + // Verify + Optional userFromDatabase = userReadPort.findById(userId); + + Assertions.assertTrue(userFromDatabase.isPresent()); + Assertions.assertEquals(userFromDatabase.get().getId(), user.getId()); + Assertions.assertEquals(AysUserStatus.valueOf(inactiveStatus), userFromDatabase.get().getStatus()); + Assertions.assertNull(userFromDatabase.get().getUpdatedUser()); + } + } diff --git a/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java b/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java index 2b64976e9..f750b58f6 100644 --- a/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java +++ b/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java @@ -28,6 +28,8 @@ import org.ays.institution.model.InstitutionBuilder; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.ValueSource; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; @@ -963,7 +965,7 @@ void givenValidUserId_whenUserNotFound_thenThrowAysUserNotExistByIdException() { } @Test - void givenValidId_whenUserIsAlreadyPassive_thenThrowAysUserAlreadyPassiveException() { + void givenValidId_whenUserIsAlreadyPassive_thenThrowUserAlreadyPassiveException() { // Given String mockId = "b64ef470-6842-400f-ba23-2379c589095c"; @@ -1002,8 +1004,12 @@ void givenValidId_whenUserIsAlreadyPassive_thenThrowAysUserAlreadyPassiveExcepti .save(Mockito.any(AysUser.class)); } - @Test - void givenValidId_whenUserIsNotActive_thenThrowAysUserNotActiveException() { + @ParameterizedTest + @ValueSource(strings = { + "NOT_VERIFIED", + "DELETED" + }) + void givenValidId_whenUserIsNotActive_thenThrowAysUserNotActiveException(String inactiveStatus) { // Given String mockId = "bf7cc8d4-eab7-487d-8564-19be0f439b4a"; @@ -1019,7 +1025,7 @@ void givenValidId_whenUserIsNotActive_thenThrowAysUserNotActiveException() { .withValidValues() .withId(mockId) .withInstitution(mockInstitution) - .withStatus(AysUserStatus.NOT_VERIFIED) + .withStatus(AysUserStatus.valueOf(inactiveStatus)) .build(); Mockito.when(userReadPort.findById(Mockito.anyString())) From 9c901c44616c705c8431fb5f3dfd4e3fbb816300 Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Mon, 27 Jan 2025 16:19:08 +0300 Subject: [PATCH 11/12] AYS-660 | Test Has Been Renamed --- .../org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java b/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java index f750b58f6..09f49a4bd 100644 --- a/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java +++ b/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java @@ -1009,7 +1009,7 @@ void givenValidId_whenUserIsAlreadyPassive_thenThrowUserAlreadyPassiveException( "NOT_VERIFIED", "DELETED" }) - void givenValidId_whenUserIsNotActive_thenThrowAysUserNotActiveException(String inactiveStatus) { + void givenValidId_whenUserIsNotActive_thenThrowUserNotActiveException(String inactiveStatus) { // Given String mockId = "bf7cc8d4-eab7-487d-8564-19be0f439b4a"; From 932a7b3a395cb586e97d5cda8ae80b834f2fb8e4 Mon Sep 17 00:00:00 2001 From: Egehan Asal Date: Tue, 28 Jan 2025 11:33:55 +0300 Subject: [PATCH 12/12] AYS-660 | Test Have Been Fixed --- .../org/ays/auth/controller/AysUserEndToEndTest.java | 12 +++++++----- .../service/impl/AysUserUpdateServiceImplTest.java | 8 ++++---- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java b/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java index 386b83e90..152b4057f 100644 --- a/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java +++ b/src/test/java/org/ays/auth/controller/AysUserEndToEndTest.java @@ -34,7 +34,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; +import org.junit.jupiter.params.provider.EnumSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder; import org.springframework.test.web.servlet.result.MockMvcResultMatchers; @@ -644,14 +644,15 @@ void givenAlreadyPassiveUserId_whenTryToPassivate_thenReturnUserAlreadyPassiveEr Assertions.assertEquals(userFromDatabase.get().getId(), user.getId()); Assertions.assertEquals(AysUserStatus.PASSIVE, userFromDatabase.get().getStatus()); Assertions.assertNull(userFromDatabase.get().getUpdatedUser()); + Assertions.assertNull(userFromDatabase.get().getUpdatedAt()); } @ParameterizedTest - @ValueSource(strings = { + @EnumSource(value = AysUserStatus.class, names = { "NOT_VERIFIED", "DELETED" }) - void givenInactiveUserId_whenTryToPassivate_thenReturnUserNotActiveError(String inactiveStatus) throws Exception { + void givenInactiveUserId_whenTryToPassivate_thenReturnUserNotActiveError(AysUserStatus status) throws Exception { // Initialize Institution institution = new InstitutionBuilder() @@ -666,7 +667,7 @@ void givenInactiveUserId_whenTryToPassivate_thenReturnUserNotActiveError(String .withoutId() .withRoles(roles) .withInstitution(institution) - .withStatus(AysUserStatus.valueOf(inactiveStatus)) + .withStatus(status) .build() ); @@ -691,8 +692,9 @@ void givenInactiveUserId_whenTryToPassivate_thenReturnUserNotActiveError(String Assertions.assertTrue(userFromDatabase.isPresent()); Assertions.assertEquals(userFromDatabase.get().getId(), user.getId()); - Assertions.assertEquals(AysUserStatus.valueOf(inactiveStatus), userFromDatabase.get().getStatus()); + Assertions.assertEquals(status, userFromDatabase.get().getStatus()); Assertions.assertNull(userFromDatabase.get().getUpdatedUser()); + Assertions.assertNull(userFromDatabase.get().getUpdatedAt()); } } diff --git a/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java b/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java index 09f49a4bd..645a33e4c 100644 --- a/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java +++ b/src/test/java/org/ays/auth/service/impl/AysUserUpdateServiceImplTest.java @@ -29,7 +29,7 @@ import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.ValueSource; +import org.junit.jupiter.params.provider.EnumSource; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Mockito; @@ -1005,11 +1005,11 @@ void givenValidId_whenUserIsAlreadyPassive_thenThrowUserAlreadyPassiveException( } @ParameterizedTest - @ValueSource(strings = { + @EnumSource(value = AysUserStatus.class, names = { "NOT_VERIFIED", "DELETED" }) - void givenValidId_whenUserIsNotActive_thenThrowUserNotActiveException(String inactiveStatus) { + void givenValidId_whenUserIsNotActive_thenThrowUserNotActiveException(AysUserStatus mockStatus) { // Given String mockId = "bf7cc8d4-eab7-487d-8564-19be0f439b4a"; @@ -1025,7 +1025,7 @@ void givenValidId_whenUserIsNotActive_thenThrowUserNotActiveException(String ina .withValidValues() .withId(mockId) .withInstitution(mockInstitution) - .withStatus(AysUserStatus.valueOf(inactiveStatus)) + .withStatus(mockStatus) .build(); Mockito.when(userReadPort.findById(Mockito.anyString()))