Skip to content

Commit

Permalink
[refactor/InhaBas#179] test build error로 인한 전반적인 수정,
Browse files Browse the repository at this point in the history
  • Loading branch information
whitem4rk committed Dec 16, 2023
1 parent 0b00d7a commit 7992912
Show file tree
Hide file tree
Showing 6 changed files with 126 additions and 182 deletions.
Original file line number Diff line number Diff line change
@@ -1,59 +1,20 @@
package com.inhabas.api.auth.domain.oauth2.member.domain.entity;


import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.IbasInformation;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.SchoolInformation;
import com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.StudentId;
import com.inhabas.api.auth.domain.oauth2.userInfo.GoogleOAuth2UserInfo;
import com.inhabas.api.auth.domain.oauth2.userInfo.OAuth2UserInfo;

import java.util.HashMap;
import java.util.Map;

import static com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.MemberType.UNDERGRADUATE;
import static com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role.*;

public class MemberTest {

public static Member chiefMember() {
return new Member(
new StudentId("12171707"), "김회장", "010-1111-1111", "[email protected]", ""
, SchoolInformation.ofUnderGraduate("컴퓨터공학과", 2)
, new IbasInformation(CHIEF));
}

public static Member executivesMember() {
return new Member(
new StudentId("12201122"), "박임원", "010-2222-2222", "[email protected]", ""
, SchoolInformation.ofUnderGraduate("컴퓨터공학과", 2)
, new IbasInformation(EXECUTIVES));
}

public static Member secretaryMember() {
return new Member(
new StudentId("12219882"), "이총무", "010-3333-3333", "[email protected]", ""
, SchoolInformation.ofUnderGraduate("컴퓨터공학과", 2)
, new IbasInformation(SECRETARY));
}

public static Member signingUpMember1() {

Map<String, Object> attributes = new HashMap<>() {{
put("provider", "GOOGLE");
put("sub", "1249846925629348");
put("picture", "/static/image.jpg");
put("email", "[email protected]");
put("name", "유동현");
put("locale", "ko");
}};
OAuth2UserInfo user = new GoogleOAuth2UserInfo(attributes);
Member member = new Member(user);
member.setRole(SIGNING_UP);

return member;
}


public static Member signingUpMember2() {
private static Member afterSignUpMember(Role role) {

Map<String, Object> attributes = new HashMap<>() {{
put("provider", "GOOGLE");
Expand All @@ -65,34 +26,46 @@ public static Member signingUpMember2() {
}};
OAuth2UserInfo user = new GoogleOAuth2UserInfo(attributes);
Member member = new Member(user);
member.setRole(SIGNING_UP);
member.setRole(role);

// 회원정보 저장
member.setStudentId("12171707");
member.setPhone("010-1111-1111");
member.setName("유동현");
member.setSchoolInformation(new SchoolInformation("컴퓨터공학과", 1, 1, UNDERGRADUATE));
return member;

}

public static Member chiefMember() {
return afterSignUpMember(CHIEF);
}

public static Member basicMember1() {
return new Member(
new StudentId("12171234"), "유동현", "010-1111-1111", "[email protected]", ""
, SchoolInformation.ofUnderGraduate("건축공학과", 3)
, new IbasInformation(BASIC));
public static Member executivesMember() {
return afterSignUpMember(EXECUTIVES);
}

public static Member secretaryMember() {
return afterSignUpMember(SECRETARY);
}

public static Member basicMember2() {
return new Member(
new StudentId("12114321"), "김민겸", "010-2222-2222", "[email protected]", ""
, SchoolInformation.ofUnderGraduate("경영학과", 2)
, new IbasInformation(BASIC));
public static Member basicMember() {
return afterSignUpMember(BASIC);
}

public static Member deactivatedMember() {
return new Member(
new StudentId("12171707"), "최비활", "010-1111-1111", "[email protected]", ""
, SchoolInformation.ofUnderGraduate("컴퓨터공학과", 2)
, new IbasInformation(DEACTIVATED));
return afterSignUpMember(DEACTIVATED);
}

public static Member notapprovedMember() {
return afterSignUpMember(NOT_APPROVED);
}

public static Member signingUpMemberAfterProfile() {
return afterSignUpMember(SIGNING_UP);
}

public static Member signingUpMember1() {

Map<String, Object> attributes = new HashMap<>() {{
put("provider", "GOOGLE");
Expand All @@ -104,30 +77,26 @@ public static Member notapprovedMember() {
}};
OAuth2UserInfo user = new GoogleOAuth2UserInfo(attributes);
Member member = new Member(user);
member.setEmail("[email protected]");
member.setName("유동현");

member.setRole(SIGNING_UP);

return new Member(
new StudentId("12171707"), "김미승인", "010-1111-1111", "[email protected]", ""
, SchoolInformation.ofUnderGraduate("컴퓨터공학과", 2)
, new IbasInformation(NOT_APPROVED));
return member;
}

public static Member signingUpMember2() {

public static Member getTestBasicMember(String id) {
return new Member(
new StudentId(id), "유동현", "010-1111-1111", "[email protected]", ""
, SchoolInformation.ofUnderGraduate("건축공학과", 3)
, new IbasInformation(BASIC));
}
Map<String, Object> attributes = new HashMap<>() {{
put("provider", "GOOGLE");
put("sub", "3232322332323223");
put("picture", "/static/image.jpg");
put("email", "[email protected]");
put("name", "조승현");
put("locale", "ko");
}};
OAuth2UserInfo user = new GoogleOAuth2UserInfo(attributes);
Member member = new Member(user);
member.setRole(SIGNING_UP);

public static Member getTestBasicMember(String id, String phoneNumber) {
return new Member(
new StudentId(id), "유동현", phoneNumber, "[email protected]", ""
, SchoolInformation.ofUnderGraduate("건축공학과", 3)
, new IbasInformation(BASIC));
return member;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,12 @@
import com.inhabas.api.auth.domain.oauth2.userInfo.GoogleOAuth2UserInfo;
import com.inhabas.api.auth.domain.oauth2.userInfo.OAuth2UserInfo;
import com.inhabas.api.auth.testAnnotation.DefaultDataJpaTest;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
import org.springframework.dao.DataIntegrityViolationException;
import org.springframework.dao.InvalidDataAccessApiUsageException;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
Expand All @@ -22,8 +20,9 @@
import java.util.stream.Collectors;

import static com.inhabas.api.auth.domain.oauth2.OAuth2Provider.GOOGLE;
import static com.inhabas.api.auth.domain.oauth2.member.domain.entity.MemberTest.*;
import static com.inhabas.api.auth.domain.oauth2.member.domain.entity.MemberTest.signingUpMember1;
import static com.inhabas.api.auth.domain.oauth2.member.domain.entity.MemberTest.signingUpMember2;
import static com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role.NOT_APPROVED;
import static com.inhabas.api.auth.domain.oauth2.member.domain.valueObject.Role.SIGNING_UP;
import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.*;
Expand All @@ -37,13 +36,9 @@ public class MemberRepositoryTest {
TestEntityManager em;


@BeforeEach
public void setUp() {
memberRepository.deleteAll();
}

@DisplayName("저장 후 반환 값은 처음과 같다.")
@Test
@Transactional
public void save() {

//when
Expand All @@ -59,6 +54,7 @@ public void save() {

@DisplayName("idList 로 사용자를 찾을 수 있다.")
@Test
@Transactional
public void find_all_by_id() {

//given
Expand All @@ -78,6 +74,7 @@ public void find_all_by_id() {

@DisplayName("Role로 하나의 사용자를 조회한다.")
@Test
@Transactional
public void findAll() {

//given
Expand All @@ -93,30 +90,19 @@ public void findAll() {

@DisplayName("같은 provider_uid 저장 시 DataIntegrityViolationException 예외")
@Test
@Transactional
public void 같은_provider_uid_저장_예외() {
//given
memberRepository.save(signingUpMember1());

//when
Map<String, Object> attributes = new HashMap<>() {{
put("provider", "GOOGLE");
put("uid", "123321123321123");
put("sub", "1249846925629348");
put("picture", "/static/image.jpg");
put("email", "[email protected]");
put("name", "유동현");
put("locale", "ko");
}};
OAuth2UserInfo user = new GoogleOAuth2UserInfo(attributes);
Member sameProviderAndUid = new Member(user);

//then
assertThrows(DataIntegrityViolationException.class,
() -> memberRepository.saveAndFlush(sameProviderAndUid));
() -> memberRepository.saveAndFlush(signingUpMember1()));
}

@DisplayName("provider_uid 중복검사 시 true 를 반환")
@Test
@Transactional
public void provider_uid_존재한다() {

//given
Expand All @@ -142,6 +128,7 @@ public void findAll() {

@DisplayName("provider_uid 중복검사 시 false 를 반환")
@Test
@Transactional
public void provider_uid_존재하지_않는다() {

//when
Expand All @@ -154,6 +141,7 @@ public void findAll() {

@DisplayName("provider_uid 로 사용자를 찾는다")
@Test
@Transactional
public void find_by_provider_uid() {

//given
Expand All @@ -174,6 +162,7 @@ public void find_by_provider_uid() {
// Custom
@DisplayName("중복 검사 쿼리 provider 없는 경우")
@Test
@Transactional
public void validateNoneFields() {

//given
Expand All @@ -188,6 +177,7 @@ public void validateNoneFields() {

@DisplayName("모든 필드 중복되는 경우")
@Test
@Transactional
public void validateAllFields() {

//given
Expand All @@ -204,15 +194,13 @@ public void validateAllFields() {
// 회원가입 이후 구현
@DisplayName("Role, StudentId 로 회원 검색")
@Test
@Disabled
@Transactional
public void search_by_role_studentId() {

//given
memberRepository.save(signingUpMember1());
memberRepository.save(signingUpMember2());
memberRepository.save(notapprovedMember());

//when
List<Member> members = memberRepository.findAllByRoleAndStudentIdLike(SIGNING_UP, "12171707");
List<Member> members = memberRepository.findAllByRoleAndStudentIdLike(NOT_APPROVED, "12171707");

//then
assertThat(members.size()).isEqualTo(1);
Expand Down
Loading

0 comments on commit 7992912

Please sign in to comment.