Skip to content

Commit

Permalink
초기 닉네임 생성 정책 변경 (#264)
Browse files Browse the repository at this point in the history
* feat: (#164) 초기 닉네임 생성 정책 변경

* test: (#263) 닉네임 유효성 검증 추가

* refactor: (#263) 초기 닉네임 prefix 변경
  • Loading branch information
jeomxon authored and tjdtls690 committed Sep 12, 2023
1 parent de60b16 commit 11667f4
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@
import lombok.EqualsAndHashCode;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.RandomStringUtils;

@NoArgsConstructor(access = AccessLevel.PROTECTED)
@EqualsAndHashCode(of = {"id"})
@Getter
@Entity
public class Member extends BaseEntity {

private static final String INITIAL_NICKNAME_PREFIX = "익명의손님";

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
Expand Down Expand Up @@ -69,9 +72,8 @@ private Member(
}

public static Member from(final KakaoMemberResponse response) {
final NicknameNumberGenerator nicknameNumberGenerator = new NicknameNumberGenerator();
return Member.builder()
.nickname("익명의손님" + nicknameNumberGenerator.generate())
.nickname(INITIAL_NICKNAME_PREFIX + RandomStringUtils.random(10, true, true))
.gender(Gender.valueOf(response.kakaoAccount().gender().toUpperCase()))
.ageRange(response.kakaoAccount().ageRange())
.birthday(response.kakaoAccount().birthday())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
public class Nickname {

private static final int MINIMUM_NICKNAME_LENGTH = 2;
private static final int MAXIMUM_NICKNAME_LENGTH = 16;
private static final int MAXIMUM_NICKNAME_LENGTH = 15;

@Column(name = "nickname", length = 15, unique = true, nullable = false)
private String value;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.votogether.domain.member.entity;

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

import com.votogether.exception.BadRequestException;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;

class NicknameTest {

@Test
@DisplayName("닉네임이 정상적으로 만들어진다.")
void create() {
// given
String value = "안녕";

// when
Nickname nickname = new Nickname(value);

// then
assertThat(nickname.getValue()).isEqualTo(value);
}

@ParameterizedTest
@ValueSource(strings = {"안", "", " ", "가나다라마바사아자차카타파하기니"})
@DisplayName("닉네임의 길이가 맞지 않으면 예외가 발생한다.")
void validateLength(String value) {
// when, then
assertThatThrownBy(() -> new Nickname(value))
.isInstanceOf(BadRequestException.class)
.hasMessage("닉네임의 길이가 올바르지 않습니다.");
}

@ParameterizedTest
@ValueSource(strings = {"저문@", "다%즐", ".루쿠", "아 벨"})
@DisplayName("한글, 영어, 숫자가 이외의 글자가 포함되어 있으면 예외를 던진다.")
void validateInvalidLetter(String value) {
// when, then
assertThatThrownBy(() -> new Nickname(value))
.isInstanceOf(BadRequestException.class)
.hasMessage("닉네임에 들어갈 수 없는 문자가 포함되어 있습니다.");
}

}

0 comments on commit 11667f4

Please sign in to comment.