Skip to content

Commit

Permalink
Merge pull request #494 from bounswe/bugfix/BE-490-authservice-unit-t…
Browse files Browse the repository at this point in the history
…est-fix

Bugfix/be 490 authservice unit test fix
  • Loading branch information
volcaniqueo authored Nov 27, 2023
2 parents 8bedace + 6cd1dd0 commit e112135
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public class UserProfileService {



public void saveProfile(UserProfile userProfile) {
userProfileRepository.save(userProfile);
public UserProfile saveProfile(UserProfile userProfile) {
return userProfileRepository.save(userProfile);
}

public String updateProfile(Long userId, ProfileDto profileDto)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.groupa1.resq.auth.UserDetailsImpl;
import com.groupa1.resq.entity.User;
import com.groupa1.resq.entity.UserProfile;
import com.groupa1.resq.entity.enums.EUserRole;
import com.groupa1.resq.request.LoginUserRequest;
import com.groupa1.resq.request.RegisterUserRequest;
Expand Down Expand Up @@ -39,6 +40,9 @@ class AuthServiceTest {
@Mock
private AuthenticationManager authenticationManager;

@Mock
private UserProfileService userProfileService;

@Mock
private PasswordEncoder encoder;

Expand Down Expand Up @@ -75,11 +79,17 @@ void testSignup_ifEmailNotAlreadyInUse_success() {
mockUser.setEmail("test-email");
mockUser.setPassword(encodedPassword);

UserProfile mockUserProfile = new UserProfile();
mockUserProfile.setName("test-name");
mockUserProfile.setSurname("test-surname");
mockUserProfile.setUser(mockUser);

mockUser.setRoles(Set.of(EUserRole.VICTIM));

// when
when(userService.existsByEmail("test-email")).thenReturn(false);
when(encoder.encode("test-password")).thenReturn(encodedPassword);
when(userProfileService.saveProfile(mockUserProfile)).thenReturn(mockUserProfile);
when(userService.save(mockUser)).thenReturn(mockUser);

// then
Expand Down

0 comments on commit e112135

Please sign in to comment.