Skip to content

Commit

Permalink
#97 - Update test authentication settings
Browse files Browse the repository at this point in the history
Add configuration to the test so that Spring Security can accept both existing DB authentication and OAuth authentication.
  • Loading branch information
laphayen committed Jul 28, 2024
1 parent ab96eaa commit 5da8375
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.laphayen.projectboard.config;

import com.laphayen.projectboard.domain.UserAccount;
import com.laphayen.projectboard.repository.UserAccountRepository;
import com.laphayen.projectboard.dto.UserAccountDto;
import com.laphayen.projectboard.service.UserAccountService;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.test.context.event.annotation.BeforeTestMethod;
Expand All @@ -14,17 +14,25 @@
@Import(SecurityConfig.class)
public class TestSecurityConfig {

@MockBean private UserAccountRepository userAccountRepository;
@MockBean private UserAccountService userAccountService;

@BeforeTestMethod
public void securitySetUp() {
given(userAccountRepository.findById(anyString())).willReturn(Optional.of(UserAccount.of(
given(userAccountService.searchUser(anyString()))
.willReturn(Optional.of(createUserAccountDto()));
given(userAccountService.saveUser(anyString(), anyString(), anyString(), anyString(), anyString()))
.willReturn(createUserAccountDto());
}


private UserAccountDto createUserAccountDto() {
return UserAccountDto.of(
"laphayenTest",
"qwer1234",
"[email protected]",
"laphayen",
"test memo"
)));
);
}

}

0 comments on commit 5da8375

Please sign in to comment.