Skip to content

Commit

Permalink
깃허브 소셜 회원 가입시 계정의 닉네임이 없을 경우 기본값으로 저장 (#589)
Browse files Browse the repository at this point in the history
fix: 사용자 이름 null 로 생성시 기본값 '익명의 사용자'를 사용하도록 수정
  • Loading branch information
hyena0608 authored Sep 21, 2023
1 parent d595790 commit 5173b0b
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,15 @@
@Embeddable
public class MemberName {

private static final String DEFAULT_VALUE = "익명의 사용자";

@Column(name = "name", nullable = false)
private String value;
private String value = DEFAULT_VALUE;

public MemberName(final String value) {
validateNotNull(value);
this.value = value;
}

private void validateNotNull(final String value) {
if (Objects.isNull(value)) {
throw new IllegalArgumentException("MemberName 객체 내부에 name 은 null 일 수 없습니다.");
return;
}
this.value = value;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package touch.baton.infra.auth.oauth.github.response;

import com.fasterxml.jackson.databind.annotation.JsonNaming;
import jakarta.annotation.Nullable;
import touch.baton.domain.member.vo.GithubUrl;
import touch.baton.domain.member.vo.ImageUrl;
import touch.baton.domain.member.vo.MemberName;
Expand All @@ -13,7 +14,7 @@

@JsonNaming(SnakeCaseStrategy.class)
public record GithubMemberResponse(String id,
String name,
@Nullable String name,
String login,
String htmlUrl,
String avatarUrl
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,21 @@ void success() {
).doesNotThrowAnyException();
}

@DisplayName("이름에 null 이 들어갈 경우 예외가 발생한다.")
@DisplayName("이름에 null 이 들어갈 경우 기본값으로 생성한다.")
@Test
void fail_if_name_is_null() {
assertThatThrownBy(() -> Member.builder()
.memberName(null)
void success_if_name_is_null_then_default_value() {
// given
final Member member = Member.builder()
.memberName(new MemberName(null))
.socialId(new SocialId("testSocialId"))
.oauthId(new OauthId("dsigjh98gh230gn2oinv913bcuo23nqovbvu93b12voi3bc31j"))
.githubUrl(new GithubUrl("github.com/hyena0608"))
.company(new Company("우아한형제들"))
.imageUrl(new ImageUrl("imageUrl"))
.build()
).isInstanceOf(MemberDomainException.class)
.hasMessage("Member 의 name 은 null 일 수 없습니다.");
.build();

// when, then
assertThat(member.getMemberName()).isEqualTo(new MemberName("익명의 사용자"));
}

@DisplayName("socialId에 null 이 들어갈 경우 예외가 발생한다.")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package touch.baton.domain.member.vo;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import static org.assertj.core.api.Assertions.assertThat;

class MemberNameTest {

@DisplayName("value 가 null 이면 기본값으로_생성한다")
@Test
void fail_if_value_is_null_then_default_value() {
// given
final MemberName memberName = new MemberName(null);

// when, then
assertThat(memberName.getValue()).isEqualTo("익명의 사용자");
}
}

This file was deleted.

0 comments on commit 5173b0b

Please sign in to comment.