forked from InhaBas/Inhabas.com-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[refactor/InhaBas#179] test build error로 인한 전반적인 수정,
- Loading branch information
Showing
6 changed files
with
126 additions
and
182 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
|
@@ -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"); | ||
|
@@ -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; | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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.*; | ||
|
@@ -37,13 +36,9 @@ public class MemberRepositoryTest { | |
TestEntityManager em; | ||
|
||
|
||
@BeforeEach | ||
public void setUp() { | ||
memberRepository.deleteAll(); | ||
} | ||
|
||
@DisplayName("저장 후 반환 값은 처음과 같다.") | ||
@Test | ||
@Transactional | ||
public void save() { | ||
|
||
//when | ||
|
@@ -59,6 +54,7 @@ public void save() { | |
|
||
@DisplayName("idList 로 사용자를 찾을 수 있다.") | ||
@Test | ||
@Transactional | ||
public void find_all_by_id() { | ||
|
||
//given | ||
|
@@ -78,6 +74,7 @@ public void find_all_by_id() { | |
|
||
@DisplayName("Role로 하나의 사용자를 조회한다.") | ||
@Test | ||
@Transactional | ||
public void findAll() { | ||
|
||
//given | ||
|
@@ -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 | ||
|
@@ -142,6 +128,7 @@ public void findAll() { | |
|
||
@DisplayName("provider_uid 중복검사 시 false 를 반환") | ||
@Test | ||
@Transactional | ||
public void provider_uid_존재하지_않는다() { | ||
|
||
//when | ||
|
@@ -154,6 +141,7 @@ public void findAll() { | |
|
||
@DisplayName("provider_uid 로 사용자를 찾는다") | ||
@Test | ||
@Transactional | ||
public void find_by_provider_uid() { | ||
|
||
//given | ||
|
@@ -174,6 +162,7 @@ public void find_by_provider_uid() { | |
// Custom | ||
@DisplayName("중복 검사 쿼리 provider 없는 경우") | ||
@Test | ||
@Transactional | ||
public void validateNoneFields() { | ||
|
||
//given | ||
|
@@ -188,6 +177,7 @@ public void validateNoneFields() { | |
|
||
@DisplayName("모든 필드 중복되는 경우") | ||
@Test | ||
@Transactional | ||
public void validateAllFields() { | ||
|
||
//given | ||
|
@@ -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); | ||
|
Oops, something went wrong.