From b9809e37203caacc81b3fbb743acf517b918a23d Mon Sep 17 00:00:00 2001 From: "aj4941@naver.com" Date: Thu, 21 Sep 2023 12:18:39 +0900 Subject: [PATCH 1/4] =?UTF-8?q?:white=5Fcheck=5Fmark:=20[TEST]=20MemberIni?= =?UTF-8?q?tServiceTest=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/service/MemberInitService.java | 8 ++-- .../member/service/MemberInitServiceTest.java | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+), 3 deletions(-) create mode 100644 src/test/java/swm_nm/morandi/domain/member/service/MemberInitServiceTest.java diff --git a/src/main/java/swm_nm/morandi/domain/member/service/MemberInitService.java b/src/main/java/swm_nm/morandi/domain/member/service/MemberInitService.java index 91f8e6b5..960aaa58 100644 --- a/src/main/java/swm_nm/morandi/domain/member/service/MemberInitService.java +++ b/src/main/java/swm_nm/morandi/domain/member/service/MemberInitService.java @@ -10,6 +10,8 @@ import swm_nm.morandi.global.exception.errorcode.AuthErrorCode; import swm_nm.morandi.global.utils.SecurityUtils; +import javax.transaction.Transactional; + @Service @RequiredArgsConstructor @Slf4j @@ -17,11 +19,11 @@ public class MemberInitService { private final MemberRepository memberRepository; + @Transactional public RegisterInfoDto memberInitialize(RegisterInfoDto registerInfoDto) { - Long userId = SecurityUtils.getCurrentMemberId(); - Member member = memberRepository.findById(userId).orElseThrow(()-> new MorandiException(AuthErrorCode.MEMBER_NOT_FOUND)); + Long memberId = SecurityUtils.getCurrentMemberId(); + Member member = memberRepository.findById(memberId).orElseThrow(()-> new MorandiException(AuthErrorCode.MEMBER_NOT_FOUND)); member.setBojId(registerInfoDto.getBojId()); - memberRepository.save(member); return registerInfoDto; } } diff --git a/src/test/java/swm_nm/morandi/domain/member/service/MemberInitServiceTest.java b/src/test/java/swm_nm/morandi/domain/member/service/MemberInitServiceTest.java new file mode 100644 index 00000000..4398f7ab --- /dev/null +++ b/src/test/java/swm_nm/morandi/domain/member/service/MemberInitServiceTest.java @@ -0,0 +1,39 @@ +package swm_nm.morandi.domain.member.service; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.transaction.annotation.Transactional; +import swm_nm.morandi.domain.member.dto.RegisterInfoDto; +import swm_nm.morandi.domain.member.entity.Member; +import swm_nm.morandi.domain.member.repository.MemberRepository; + +import java.util.List; +import java.util.Optional; +import static org.assertj.core.api.Assertions.assertThat; +@SpringBootTest +@WithMockUser(username = "1", roles = "USER") +class MemberInitServiceTest { + + @Autowired + private MemberRepository memberRepository; + + @Autowired + private MemberInitService memberInitService; + @Test + void memberInitialize() { + // given + RegisterInfoDto registerInfoDto = RegisterInfoDto.builder() + .bojId("aj4941") + .build(); + + // when + memberInitService.memberInitialize(registerInfoDto); + + // then + Optional result = memberRepository.findById(1L); + Member findMember = result.get(); + assertThat(findMember.getBojId()).isEqualTo("aj4941"); + } +} From 9d05c090cb3ef2cac344a2eda3d1be6d46582c6f Mon Sep 17 00:00:00 2001 From: "aj4941@naver.com" Date: Thu, 21 Sep 2023 12:23:23 +0900 Subject: [PATCH 2/4] =?UTF-8?q?:white=5Fcheck=5Fmark:=20[TEST]=20MemberInf?= =?UTF-8?q?oServiceTest=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/service/MemberInfoServiceTest.java | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 src/test/java/swm_nm/morandi/domain/member/service/MemberInfoServiceTest.java diff --git a/src/test/java/swm_nm/morandi/domain/member/service/MemberInfoServiceTest.java b/src/test/java/swm_nm/morandi/domain/member/service/MemberInfoServiceTest.java new file mode 100644 index 00000000..81c9f679 --- /dev/null +++ b/src/test/java/swm_nm/morandi/domain/member/service/MemberInfoServiceTest.java @@ -0,0 +1,38 @@ +package swm_nm.morandi.domain.member.service; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.transaction.annotation.Transactional; +import swm_nm.morandi.domain.member.dto.MemberInfoDto; +import swm_nm.morandi.domain.member.entity.Member; +import swm_nm.morandi.domain.member.repository.MemberRepository; + +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; + +@SpringBootTest +@WithMockUser(username = "1", roles = "USER") +class MemberInfoServiceTest { + + @Autowired + private MemberInfoService memberInfoService; + + @Autowired + private MemberRepository memberRepository; + @Test + @Transactional + void getMemberInfo() { + // given + Optional result = memberRepository.findById(1L); + Member member = result.get(); + + // when + MemberInfoDto memberInfo = memberInfoService.getMemberInfo(); + + // then + assertThat(memberInfo.getBojId()).isEqualTo("aj4941"); + } +} \ No newline at end of file From 8921bfb1474c0028858ad5f25986e183ded418c5 Mon Sep 17 00:00:00 2001 From: "aj4941@naver.com" Date: Thu, 21 Sep 2023 12:24:18 +0900 Subject: [PATCH 3/4] =?UTF-8?q?:white=5Fcheck=5Fmark:=20[TEST]=20MemberInf?= =?UTF-8?q?oServiceTest=20=EC=9E=91=EC=84=B1=20(2)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../morandi/domain/member/service/MemberInfoServiceTest.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/swm_nm/morandi/domain/member/service/MemberInfoServiceTest.java b/src/test/java/swm_nm/morandi/domain/member/service/MemberInfoServiceTest.java index 81c9f679..64d1b261 100644 --- a/src/test/java/swm_nm/morandi/domain/member/service/MemberInfoServiceTest.java +++ b/src/test/java/swm_nm/morandi/domain/member/service/MemberInfoServiceTest.java @@ -33,6 +33,6 @@ void getMemberInfo() { MemberInfoDto memberInfo = memberInfoService.getMemberInfo(); // then - assertThat(memberInfo.getBojId()).isEqualTo("aj4941"); + assertThat(memberInfo.getBojId()).isEqualTo(member.getBojId()); } } \ No newline at end of file From c3a2d8030112f727693acd515a0cbd3cc373a48d Mon Sep 17 00:00:00 2001 From: "aj4941@naver.com" Date: Thu, 21 Sep 2023 12:35:49 +0900 Subject: [PATCH 4/4] =?UTF-8?q?:white=5Fcheck=5Fmark:=20[TEST]=20MemberEdi?= =?UTF-8?q?tServiceTest=20=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/service/MemberEditService.java | 6 +-- .../member/service/MemberEditServiceTest.java | 45 +++++++++++++++++++ 2 files changed, 47 insertions(+), 4 deletions(-) create mode 100644 src/test/java/swm_nm/morandi/domain/member/service/MemberEditServiceTest.java diff --git a/src/main/java/swm_nm/morandi/domain/member/service/MemberEditService.java b/src/main/java/swm_nm/morandi/domain/member/service/MemberEditService.java index 50fd62a2..3996c4ca 100644 --- a/src/main/java/swm_nm/morandi/domain/member/service/MemberEditService.java +++ b/src/main/java/swm_nm/morandi/domain/member/service/MemberEditService.java @@ -1,5 +1,4 @@ package swm_nm.morandi.domain.member.service; - import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; @@ -8,7 +7,6 @@ import swm_nm.morandi.global.exception.MorandiException; import swm_nm.morandi.global.exception.errorcode.MemberErrorCode; import swm_nm.morandi.global.utils.SecurityUtils; - import javax.transaction.Transactional; @Service @@ -18,10 +16,10 @@ public class MemberEditService { private final MemberRepository memberRepository; @Transactional - public void editProfile(String nickname, String bojId) { + public void editProfile(String introduceInfo, String bojId) { Long memberId = SecurityUtils.getCurrentMemberId(); Member member = memberRepository.findById(memberId).orElseThrow( () -> new MorandiException(MemberErrorCode.MEMBER_NOT_FOUND)); - member.editProfile(nickname, bojId); + member.editProfile(introduceInfo, bojId); } } diff --git a/src/test/java/swm_nm/morandi/domain/member/service/MemberEditServiceTest.java b/src/test/java/swm_nm/morandi/domain/member/service/MemberEditServiceTest.java new file mode 100644 index 00000000..881c1826 --- /dev/null +++ b/src/test/java/swm_nm/morandi/domain/member/service/MemberEditServiceTest.java @@ -0,0 +1,45 @@ +package swm_nm.morandi.domain.member.service; + +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.security.test.context.support.WithMockUser; +import org.springframework.transaction.annotation.Transactional; +import swm_nm.morandi.domain.member.dto.MemberInfoDto; +import swm_nm.morandi.domain.member.entity.Member; +import swm_nm.morandi.domain.member.repository.MemberRepository; + +import java.util.Optional; + +import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +@WithMockUser(username = "1", roles = "USER") +class MemberEditServiceTest { + + @Autowired + private MemberEditService memberEditService; + + @Autowired + private MemberRepository memberRepository; + @Test + @Transactional + void editProfile() { + // given + MemberInfoDto memberInfoDto = new MemberInfoDto(); + memberInfoDto.setIntroduceInfo("hello world"); + memberInfoDto.setBojId("aj4941"); + + // when + memberEditService.editProfile(memberInfoDto.getIntroduceInfo(), memberInfoDto.getBojId()); + + // then + Optional result = memberRepository.findById(1L); + Member findMember = result.get(); + + assertThat(findMember.getIntroduceInfo()).isEqualTo("hello world"); + assertThat(findMember.getBojId()).isEqualTo("aj4941"); + } +} \ No newline at end of file