Skip to content

Commit

Permalink
feat: 사용자의 정보를 수정하는 서비스 로직 추가 및 관련 dto 생성
Browse files Browse the repository at this point in the history
  • Loading branch information
70825 committed Aug 1, 2023
1 parent e706dbb commit c929828
Show file tree
Hide file tree
Showing 3 changed files with 149 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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());
}
}
20 changes: 20 additions & 0 deletions backend/src/main/java/com/funeat/member/dto/MemberRequest.java
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
}
}
}

0 comments on commit c929828

Please sign in to comment.