Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BE] feature/nickname 랜덤 닉네임에 고정 문자열 대신 카카오 닉네임 사용 #342

Merged
merged 4 commits into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public class Member extends BaseTimeEntity {

private static final String DEFAULT_NICKNAME_PREFIX = "모험가";
private static final int DEFAULT_NICKNAME_SUFFIX_LENGTH = 7;
private static final int NICKNAME_MAX_LENGTH = 20;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand Down Expand Up @@ -76,16 +77,24 @@ public static Member of(
}

public static Member ofRandomNickname(
String nickname,
String email,
String imageUrl,
Role role,
OauthId oauthId
) {
String nickName = DEFAULT_NICKNAME_PREFIX + createNicknameSuffix();
String nickName = createNickname(nickname);

return Member.of(nickName, email, imageUrl, role, oauthId);
}

private static String createNickname(String nickname) {
if (nickname.length() > NICKNAME_MAX_LENGTH - DEFAULT_NICKNAME_SUFFIX_LENGTH) {
return DEFAULT_NICKNAME_PREFIX + createNicknameSuffix();
}
return nickname + createNicknameSuffix();
}

private static String createNicknameSuffix() {
return randomUUID()
.toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,41 @@
@Getter
public class OauthMember {

private String nickname;
private String email;
private String profileImageUrl;
private OauthId oauthId;

private OauthMember(
String nickname,
String email,
String profileImageUrl,
OauthId oauthId
) {
this.nickname = nickname;
this.email = email;
this.profileImageUrl = profileImageUrl;
this.oauthId = oauthId;
}

public static OauthMember of(
String nickname,
String email,
String profileImageUrl,
Long oauthServerId,
OauthServerType oauthServerType
) {
return new OauthMember(email, profileImageUrl, new OauthId(oauthServerId, oauthServerType));
return new OauthMember(
nickname,
email,
profileImageUrl,
new OauthId(oauthServerId, oauthServerType)
);
}

public Member toRegisterMember() {
return Member.ofRandomNickname(
nickname,
email,
profileImageUrl,
Role.USER,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public record KakaoMemberResponse(

public OauthMember extract() {
return OauthMember.of(
kakaoAccount().profile.nickname,
kakaoAccount().email,
kakaoAccount().profile.profileImageUrl,
id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
class OauthServiceTest {

private static final OauthMember oauthMember = OauthMember.of(
"12345678901234567890",
"[email protected]",
"https://map-befine-official.github.io/favicon.png",
Long.MAX_VALUE,
Expand Down Expand Up @@ -82,6 +83,7 @@ void tearDown() {
void getAuthCodeRequestUrl_success() {
// when
String url = oauthService.getAuthCodeRequestUrl(OauthServerType.KAKAO);
System.out.println(oauthMember.toRegisterMember().getMemberInfo().getNickName());

// then
assertThat(url).isEqualTo("https://kauth.kakao.com/oauth/authorize?"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.mapbefine.mapbefine.oauth.domain;

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

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

class OauthMemberTest {

@Test
@DisplayName("소셜 로그인 닉네임의 길이가 13자 초과이면 기본 랜덤 닉네임을 부여한다.")
void toRegisterMember() {
OauthMember oauthMember = OauthMember.of(
"일이삼사오육칠팔구십일이삼사",
"[email protected]",
"https://image.url",
1L,
OauthServerType.KAKAO
);

String expected = oauthMember.toRegisterMember()
.getMemberInfo()
.getNickName();

System.out.println(expected);
assertThat(expected).contains("모험가");
}
}
Loading