From 5da837528c9c3fedb5afca779621e28a497b19df Mon Sep 17 00:00:00 2001 From: Baek Gi Chan Date: Sun, 28 Jul 2024 23:07:32 +0900 Subject: [PATCH] #97 - Update test authentication settings Add configuration to the test so that Spring Security can accept both existing DB authentication and OAuth authentication. --- .../config/TestSecurityConfig.java | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/laphayen/projectboard/config/TestSecurityConfig.java b/src/test/java/com/laphayen/projectboard/config/TestSecurityConfig.java index c659f21..f04cab8 100644 --- a/src/test/java/com/laphayen/projectboard/config/TestSecurityConfig.java +++ b/src/test/java/com/laphayen/projectboard/config/TestSecurityConfig.java @@ -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; @@ -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", "laphayentest@email.com", "laphayen", "test memo" - ))); + ); } }