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

Feature/#81 로그인 사용자 프로필 이미지 추가 기능 구현 #87

Merged
Show file tree
Hide file tree
Changes from 3 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 @@ -3,6 +3,7 @@
import com.emmsale.login.application.dto.GithubProfileResponse;
import com.emmsale.login.application.dto.MemberQueryResponse;
import com.emmsale.login.application.dto.TokenResponse;
import com.emmsale.login.utils.GithubClient;
import com.emmsale.login.utils.JwtTokenProvider;
import com.emmsale.member.application.MemberQueryService;
import org.springframework.stereotype.Service;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public Long getGithubId() {
public Member toMember() {
return new Member(
getGithubId(),
getImageUrl(),
getUsername()
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.emmsale.login.application;
package com.emmsale.login.utils;

import com.emmsale.login.application.dto.GithubAccessTokenRequest;
import com.emmsale.login.application.dto.GithubAccessTokenResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@
import javax.persistence.GenerationType;
import javax.persistence.Id;
import lombok.AccessLevel;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@AllArgsConstructor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

혹시 필요없는 생성자면 지워주시면 감사하겠습니다.

@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Member extends BaseEntity {

Expand All @@ -29,8 +31,9 @@ public class Member extends BaseEntity {
@Column(nullable = false)
private String imageUrl;

public Member(final Long githubId, final String name) {
public Member(final Long githubId, final String imageUrl, final String name) {
this.githubId = githubId;
this.imageUrl = imageUrl;
this.name = name;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.emmsale.login.application.dto.TokenResponse;
import com.emmsale.login.exception.LoginException;
import com.emmsale.login.exception.LoginExceptionType;
import com.emmsale.login.utils.GithubClient;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.emmsale.member.application;

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

import com.emmsale.helper.ServiceIntegrationTestHelper;
import com.emmsale.login.application.dto.GithubProfileResponse;
import com.emmsale.login.application.dto.MemberQueryResponse;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;

class MemberQueryServiceTest extends ServiceIntegrationTestHelper {

@Autowired
private MemberQueryService memberQueryService;

@Test
@DisplayName("사용자를 조회하고 조회 결과를 반환한다.")
void findOrCreateMemberTest() {
//given
final MemberQueryResponse expectResponse = new MemberQueryResponse(1L, false);

final GithubProfileResponse githubProfileFromGithub = new GithubProfileResponse("1", "name",
"username", "https://imageUrl.com");

//when
final MemberQueryResponse actualResponse = memberQueryService.findOrCreateMember(
githubProfileFromGithub);

//then
assertThat(expectResponse)
.usingRecursiveComparison()
.ignoringCollectionOrder()
.isEqualTo(actualResponse);
}

@Test
@DisplayName("사용자를 조회하고 존재하지 않으므로 새로 생성하고 생성한 결과를 반환한다.")
void findOrCreateMemberTestWithNewMember() {
//given
final MemberQueryResponse expectResponse = new MemberQueryResponse(3L, true);

final GithubProfileResponse githubProfileFromGithub = new GithubProfileResponse("0", "name",
"username", "https://imageUrl.com");

//when
final MemberQueryResponse actualResponse = memberQueryService.findOrCreateMember(
githubProfileFromGithub);

//then
assertThat(expectResponse)
.usingRecursiveComparison()
.ignoringCollectionOrder()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

요건 굳이 필요 없는 친구인것 같아요.

.isEqualTo(actualResponse);
}
}
Loading