From c92982818e2998c86c2e65178361da58562b2b52 Mon Sep 17 00:00:00 2001 From: 70825 Date: Tue, 1 Aug 2023 11:55:15 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EC=82=AC=EC=9A=A9=EC=9E=90=EC=9D=98=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EB=A5=BC=20=EC=88=98=EC=A0=95=ED=95=98?= =?UTF-8?q?=EB=8A=94=20=EC=84=9C=EB=B9=84=EC=8A=A4=20=EB=A1=9C=EC=A7=81=20?= =?UTF-8?q?=EC=B6=94=EA=B0=80=20=EB=B0=8F=20=EA=B4=80=EB=A0=A8=20dto=20?= =?UTF-8?q?=EC=83=9D=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../member/application/MemberService.java | 10 ++ .../com/funeat/member/dto/MemberRequest.java | 20 +++ .../member/application/MemberServiceTest.java | 119 ++++++++++++++++++ 3 files changed, 149 insertions(+) create mode 100644 backend/src/main/java/com/funeat/member/dto/MemberRequest.java diff --git a/backend/src/main/java/com/funeat/member/application/MemberService.java b/backend/src/main/java/com/funeat/member/application/MemberService.java index b1d55931a..6ac06698b 100644 --- a/backend/src/main/java/com/funeat/member/application/MemberService.java +++ b/backend/src/main/java/com/funeat/member/application/MemberService.java @@ -3,6 +3,7 @@ import com.funeat.auth.dto.SignUserDto; import com.funeat.auth.dto.UserInfoDto; import com.funeat.member.domain.Member; +import com.funeat.member.dto.MemberRequest; import com.funeat.member.persistence.MemberRepository; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -32,4 +33,13 @@ public SignUserDto save(final UserInfoDto userInfoDto) { return SignUserDto.of(true, member); } + + @Transactional + public void modify(final Long memberId, final MemberRequest request) { + final Member findMember = memberRepository.findById(memberId) + .orElseThrow(IllegalArgumentException::new); + + findMember.modifyNickname(request.getNickname()); + findMember.modifyProfileImage(request.getProfileImage()); + } } diff --git a/backend/src/main/java/com/funeat/member/dto/MemberRequest.java b/backend/src/main/java/com/funeat/member/dto/MemberRequest.java new file mode 100644 index 000000000..a4800c6ed --- /dev/null +++ b/backend/src/main/java/com/funeat/member/dto/MemberRequest.java @@ -0,0 +1,20 @@ +package com.funeat.member.dto; + +public class MemberRequest { + + private final String nickname; + private final String profileImage; + + public MemberRequest(final String nickname, final String profileImage) { + this.nickname = nickname; + this.profileImage = profileImage; + } + + public String getNickname() { + return nickname; + } + + public String getProfileImage() { + return profileImage; + } +} diff --git a/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java b/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java index 65967f853..ddb281c7f 100644 --- a/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java +++ b/backend/src/test/java/com/funeat/member/application/MemberServiceTest.java @@ -5,6 +5,7 @@ import com.funeat.auth.dto.UserInfoDto; import com.funeat.common.DataClearExtension; import com.funeat.member.domain.Member; +import com.funeat.member.dto.MemberRequest; import com.funeat.member.persistence.MemberRepository; import org.assertj.core.api.SoftAssertions; import org.junit.jupiter.api.Assertions; @@ -71,4 +72,122 @@ class findOrCreateMember_테스트 { }); } } + + @Nested + class modify_테스트 { + + @Test + void 닉네임과_프로필_사진이_그대로면_사용자_정보는_바뀌지_않는다() { + // given + final var nickname = "test"; + final var profileImage = "http://www.test.com"; + final MemberRequest request = new MemberRequest(nickname, profileImage); + + final var member = new Member(nickname, profileImage, "1"); + final var memberId = memberRepository.save(member).getId(); + + final var expected = memberRepository.findById(memberId).get(); + final var expectedNickname = expected.getNickname(); + final var expectedProfileImage = expected.getProfileImage(); + + // when + memberService.modify(memberId, request); + final var actual = memberRepository.findById(memberId).get(); + final var actualNickname = actual.getNickname(); + final var actualProfileImage = actual.getProfileImage(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(actualNickname).isEqualTo(expectedNickname); + softAssertions.assertThat(actualProfileImage).isEqualTo(expectedProfileImage); + }); + } + + @Test + void 닉네임만_바뀌고_프로필_사진은_그대로면_닉네임만_바뀐다() { + // given + final var beforeNickname = "before"; + final var profileImage = "http://www.test.com"; + final var afterNickname = "after"; + final MemberRequest request = new MemberRequest(afterNickname, profileImage); + + final var member = new Member(beforeNickname, profileImage, "1"); + final var memberId = memberRepository.save(member).getId(); + + final var expected = memberRepository.findById(memberId).get(); + final var expectedNickname = expected.getNickname(); + final var expectedProfileImage = expected.getProfileImage(); + + // when + memberService.modify(memberId, request); + final var actual = memberRepository.findById(memberId).get(); + final var actualNickname = actual.getNickname(); + final var actualProfileImage = actual.getProfileImage(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(actualNickname).isNotEqualTo(expectedNickname); + softAssertions.assertThat(actualProfileImage).isEqualTo(expectedProfileImage); + }); + } + + @Test + void 닉네임은_그대로이고_프로필_사진이_바뀌면_프로필_사진만_바뀐다() { + // given + final var nickname = "test"; + final var beforeProfileImage = "http://www.before.com"; + final var afterProfileImage = "http://www.after.com"; + + final MemberRequest request = new MemberRequest(nickname, afterProfileImage); + + final var member = new Member(nickname, beforeProfileImage, "1"); + final var memberId = memberRepository.save(member).getId(); + + final var expected = memberRepository.findById(memberId).get(); + final var expectedNickname = expected.getNickname(); + final var expectedProfileImage = expected.getProfileImage(); + + // when + memberService.modify(memberId, request); + final var actual = memberRepository.findById(memberId).get(); + final var actualNickname = actual.getNickname(); + final var actualProfileImage = actual.getProfileImage(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(actualNickname).isEqualTo(expectedNickname); + softAssertions.assertThat(actualProfileImage).isNotEqualTo(expectedProfileImage); + }); + } + + @Test + void 닉네임과_프로필_사진_모두_바뀌면_모두_바뀐다() { + // given + final var beforeNickname = "before"; + final var afterNickname = "after"; + final var beforeProfileImage = "http://www.before.com"; + final var afterProfileImage = "http://www.after.com"; + + final MemberRequest request = new MemberRequest(afterNickname, afterProfileImage); + + final var member = new Member(beforeNickname, beforeProfileImage, "1"); + final var memberId = memberRepository.save(member).getId(); + + final var expected = memberRepository.findById(memberId).get(); + final var expectedNickname = expected.getNickname(); + final var expectedProfileImage = expected.getProfileImage(); + + // when + memberService.modify(memberId, request); + final var actual = memberRepository.findById(memberId).get(); + final var actualNickname = actual.getNickname(); + final var actualProfileImage = actual.getProfileImage(); + + // then + SoftAssertions.assertSoftly(softAssertions -> { + softAssertions.assertThat(actualNickname).isNotEqualTo(expectedNickname); + softAssertions.assertThat(actualProfileImage).isNotEqualTo(expectedProfileImage); + }); + } + } }