diff --git a/src/main/java/com/ssafy/ssafsound/domain/auth/controller/AuthController.java b/src/main/java/com/ssafy/ssafsound/domain/auth/controller/AuthController.java index 387d0fea6..e47cd79c1 100644 --- a/src/main/java/com/ssafy/ssafsound/domain/auth/controller/AuthController.java +++ b/src/main/java/com/ssafy/ssafsound/domain/auth/controller/AuthController.java @@ -81,10 +81,7 @@ public EnvelopeResponse login( AuthenticatedMember authenticatedMember = memberService.createMemberByOauthIdentifier(postMemberReqDto); CreateMemberTokensResDto createMemberTokensResDto = authService.createToken(authenticatedMember); - Member member = memberService.saveTokenByMember( - authenticatedMember, - createMemberTokensResDto.getAccessToken(), - createMemberTokensResDto.getRefreshToken()); + Member member = memberService.saveTokenByMember(authenticatedMember, createMemberTokensResDto); cookieProvider.setResponseWithCookies( response, diff --git a/src/main/java/com/ssafy/ssafsound/domain/member/dto/SSAFYInfo.java b/src/main/java/com/ssafy/ssafsound/domain/member/dto/SSAFYInfo.java index 0f26c43b4..c997b7845 100644 --- a/src/main/java/com/ssafy/ssafsound/domain/member/dto/SSAFYInfo.java +++ b/src/main/java/com/ssafy/ssafsound/domain/member/dto/SSAFYInfo.java @@ -1,6 +1,8 @@ package com.ssafy.ssafsound.domain.member.dto; import com.ssafy.ssafsound.domain.member.domain.Member; +import com.ssafy.ssafsound.domain.member.exception.MemberErrorInfo; +import com.ssafy.ssafsound.domain.member.exception.MemberException; import com.ssafy.ssafsound.domain.meta.domain.MetaData; import lombok.Getter; @@ -24,7 +26,14 @@ private SSAFYInfo(int semester, String campus, String certificationState, String } public static SSAFYInfo from(Member member) { - return new SSAFYInfo(member.getSemester(), member.getCampus().getName(), member.getCertificationState().name(), member.getMajorTrack() == null ? null : member.getMajorTrack().getName()); + if(member.getSemester() == null) throw new MemberException(MemberErrorInfo.MEMBER_INFORMATION_ERROR); + if(member.getCampus().getName() == null) throw new MemberException(MemberErrorInfo.MEMBER_INFORMATION_ERROR); + + return new SSAFYInfo( + member.getSemester(), + member.getCampus().getName(), + member.getCertificationState().name(), + member.getMajorTrack() == null ? null : member.getMajorTrack().getName()); } public static SSAFYInfo of(int semester, String campus, String certificationState, MetaData majorTrack) { if (majorTrack == null) return new SSAFYInfo(semester, campus, certificationState); diff --git a/src/main/java/com/ssafy/ssafsound/domain/member/service/MemberService.java b/src/main/java/com/ssafy/ssafsound/domain/member/service/MemberService.java index ce476c44d..9a2fa219a 100644 --- a/src/main/java/com/ssafy/ssafsound/domain/member/service/MemberService.java +++ b/src/main/java/com/ssafy/ssafsound/domain/member/service/MemberService.java @@ -1,8 +1,7 @@ package com.ssafy.ssafsound.domain.member.service; import com.ssafy.ssafsound.domain.auth.dto.AuthenticatedMember; -import com.ssafy.ssafsound.domain.auth.service.AuthService; -import com.ssafy.ssafsound.domain.auth.util.ClientUtils; +import com.ssafy.ssafsound.domain.auth.dto.CreateMemberTokensResDto; import com.ssafy.ssafsound.domain.member.domain.*; import com.ssafy.ssafsound.domain.member.dto.*; import com.ssafy.ssafsound.domain.member.exception.MemberErrorInfo; @@ -50,14 +49,18 @@ public AuthenticatedMember createMemberByOauthIdentifier(PostMemberReqDto postMe } @Transactional - public Member saveTokenByMember(AuthenticatedMember authenticatedMember, String accessToken, String refreshToken) { + public Member saveTokenByMember( + AuthenticatedMember authenticatedMember, + CreateMemberTokensResDto createMemberTokensResDto) { Member member = memberRepository.findById(authenticatedMember.getMemberId()) .orElseThrow(() -> new MemberException(MemberErrorInfo.MEMBER_NOT_FOUND_BY_ID)); - Optional memberTokenOptional = memberTokenRepository.findById(authenticatedMember.getMemberId()); + Optional memberTokenOptional = memberTokenRepository + .findById(authenticatedMember.getMemberId()); - memberTokenOptional.ifPresentOrElse(memberToken -> changeMemberTokens(memberToken, accessToken, refreshToken), - () -> createMemberToken(member, accessToken, refreshToken)); + memberTokenOptional.ifPresentOrElse( + memberToken -> changeMemberTokens(memberToken, createMemberTokensResDto), + () -> createMemberToken(member, createMemberTokensResDto)); return member; } @@ -287,7 +290,8 @@ private boolean isGeneralMemberInformation(Member member) { } private boolean isSSAFYMemberInformation(Member member) { - return member.getSsafyMember() && member.getNickname() != null && member.getMajor() != null; + return member.getSsafyMember() && member.getNickname() != null && member.getMajor() != null + && member.getSemester() != null && member.getCampus() != null && member.getCertificationState() != null; } private Member getMemberByMemberIdOrThrowException(Long memberId) { @@ -295,15 +299,19 @@ private Member getMemberByMemberIdOrThrowException(Long memberId) { .orElseThrow(() -> new MemberException(MemberErrorInfo.MEMBER_NOT_FOUND_BY_ID)); } - private void changeMemberTokens(MemberToken memberToken, String accessToken, String refreshToken) { - memberToken.changeAccessTokenByLogin(accessToken); - memberToken.changeRefreshTokenByLogin(refreshToken); + private void changeMemberTokens( + MemberToken memberToken, + CreateMemberTokensResDto createMemberTokensResDto) { + memberToken.changeAccessTokenByLogin(createMemberTokensResDto.getAccessToken()); + memberToken.changeRefreshTokenByLogin(createMemberTokensResDto.getRefreshToken()); } - private void createMemberToken(Member member, String accessToken, String refreshToken) { + private void createMemberToken( + Member member, + CreateMemberTokensResDto createMemberTokensResDto) { MemberToken memberToken = MemberToken.builder() - .accessToken(accessToken) - .refreshToken(refreshToken) + .accessToken(createMemberTokensResDto.getAccessToken()) + .refreshToken(createMemberTokensResDto.getRefreshToken()) .member(member) .build(); memberTokenRepository.save(memberToken); diff --git a/src/test/java/com/ssafy/ssafsound/domain/auth/controller/AuthControllerTest.java b/src/test/java/com/ssafy/ssafsound/domain/auth/controller/AuthControllerTest.java index a1243b269..cad443f49 100644 --- a/src/test/java/com/ssafy/ssafsound/domain/auth/controller/AuthControllerTest.java +++ b/src/test/java/com/ssafy/ssafsound/domain/auth/controller/AuthControllerTest.java @@ -1,6 +1,6 @@ package com.ssafy.ssafsound.domain.auth.controller; -import com.ssafy.ssafsound.domain.auth.fixture.AuthFixture; +import com.ssafy.ssafsound.global.util.fixture.AuthFixture; import com.ssafy.ssafsound.global.docs.ControllerTest; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; diff --git a/src/test/java/com/ssafy/ssafsound/domain/member/controller/MemberControllerTest.java b/src/test/java/com/ssafy/ssafsound/domain/member/controller/MemberControllerTest.java index 5e3eb663c..e375474bd 100644 --- a/src/test/java/com/ssafy/ssafsound/domain/member/controller/MemberControllerTest.java +++ b/src/test/java/com/ssafy/ssafsound/domain/member/controller/MemberControllerTest.java @@ -1,5 +1,6 @@ package com.ssafy.ssafsound.domain.member.controller; +import com.ssafy.ssafsound.domain.member.dto.GetMemberDefaultInfoResDto; import com.ssafy.ssafsound.domain.member.dto.GetMemberResDto; import com.ssafy.ssafsound.domain.member.dto.PostMemberInfoReqDto; import com.ssafy.ssafsound.global.docs.ControllerTest; @@ -25,6 +26,8 @@ class MemberControllerTest extends ControllerTest { + private final MemberFixture memberFixture = new MemberFixture(); + public ResponseFieldsSnippet getPortfolioSnippet() { return getEnvelopPatternWithData() .andWithPrefix("data.portfolioElement.", @@ -78,7 +81,7 @@ public ResponseFieldsSnippet getMemberSnippet() { void getMemberInformationByFirstTry() { given(memberService.getMemberInformation(any())) - .willReturn(GetMemberResDto.fromGeneralUser(MemberFixture.INITIALIZER_MEMBER)); + .willReturn(GetMemberResDto.fromGeneralUser(memberFixture.createInitializerMember())); restDocs .cookie(ACCESS_TOKEN) @@ -102,7 +105,7 @@ void getMemberInformationByFirstTry() { void getGeneralMemberInformation() { given(memberService.getMemberInformation(any())) - .willReturn(GetMemberResDto.fromGeneralUser(MemberFixture.GENERAL_MEMBER)); + .willReturn(GetMemberResDto.fromGeneralUser(memberFixture.createGeneralMember())); restDocs .cookie(ACCESS_TOKEN) @@ -132,7 +135,7 @@ void getGeneralMemberInformation() { void getSSAFYMemberInformation() { given(memberService.getMemberInformation(any())) - .willReturn(MemberFixture.CERTIFIED_SSAFY_MEMBER); + .willReturn(memberFixture.createCertifiedSSAFYMemberResDto()); restDocs .cookie(ACCESS_TOKEN) @@ -150,7 +153,7 @@ void getSSAFYMemberInformation() { void putMemberInformation() { given(memberService.registerMemberInformation(any(), any())) - .willReturn(GetMemberResDto.fromGeneralUser(MemberFixture.GENERAL_MEMBER)); + .willReturn(GetMemberResDto.fromGeneralUser(memberFixture.createGeneralMember())); given(semesterValidator.isValid(any(), any())).willReturn(true); PostMemberInfoReqDto postMemberInfoReqDto = PostMemberInfoReqDto.builder() @@ -178,7 +181,7 @@ void putMemberInformation() { void putMemberSSAFYInformation() { given(memberService.registerMemberInformation(any(), any())) - .willReturn(MemberFixture.UNCERTIFIED_SSAFY_MEMBER); + .willReturn(memberFixture.createUncertifiedSSAFYMemberResDto()); given(semesterValidator.isValid(any(), any())).willReturn(true); given(semesterConstantProvider.getMAX_SEMESTER()).willReturn(10); given(semesterConstantProvider.getMIN_SEMESTER()).willReturn(1); @@ -210,7 +213,7 @@ void putMemberSSAFYInformation() { void certificationSSAFY() { given(memberService.certifySSAFYInformation(any(), any())) - .willReturn(MemberFixture.POST_CERTIFICATION_INFO_RESPONSE); + .willReturn(memberFixture.createPostCertificationInfoResDto()); given(semesterValidator.isValid(any(), any())).willReturn(true); given(semesterConstantProvider.getMAX_SEMESTER()).willReturn(10); given(semesterConstantProvider.getMIN_SEMESTER()).willReturn(1); @@ -218,7 +221,7 @@ void certificationSSAFY() { restDocs .contentType(MediaType.APPLICATION_JSON_VALUE) .cookie(ACCESS_TOKEN) - .body(MemberFixture.POST_CERTIFICATION_INFO_REQUEST) + .body(memberFixture.createPostCertificationInfoReqDto()) .when().post("/members/ssafy-certification") .then().log().all() .assertThat() @@ -241,7 +244,7 @@ void certificationSSAFY() { void getMyPortfolio() { given(memberService.getMyPortfolio(any())) - .willReturn(MemberFixture.MY_PORTFOLIO); + .willReturn(memberFixture.createGetMemberPortfolioResDto()); restDocs .cookie(ACCESS_TOKEN) @@ -259,7 +262,7 @@ void getMyPortfolio() { void getOtherPortfolio() { given(memberService.getMemberPortfolioById(any())) - .willReturn(MemberFixture.MY_PORTFOLIO); + .willReturn(memberFixture.createGetMemberPortfolioResDto()); restDocs .when().get("members/{memberId}/portfolio", 99) @@ -279,7 +282,7 @@ void putMemberPortfolio() { restDocs .cookie(ACCESS_TOKEN) .contentType(MediaType.APPLICATION_JSON_VALUE) - .body(MemberFixture.PUT_MEMBER_PORTFOLIO_REQUEST) + .body(memberFixture.createPutMemberPortfolioReqDto()) .when().put("members/portfolio") .then().log().all() .assertThat() @@ -300,7 +303,7 @@ void putMemberPortfolio() { void getMemberDefaultInformation() { given(memberService.getMemberDefaultInfoByMemberId(any())) - .willReturn(MemberFixture.GET_MEMBER_DEFAULT_INFO); + .willReturn(GetMemberDefaultInfoResDto.from(memberFixture.createMember())); restDocs .when().get("members/{memberId}/default-information", 99) @@ -334,7 +337,7 @@ void patchMemberDefaultInformation() { restDocs .cookie(ACCESS_TOKEN) .contentType(MediaType.APPLICATION_JSON_VALUE) - .body(MemberFixture.PATCH_MEMBER_DEFAULT_INFO_REQUEST) + .body(memberFixture.createPatchMemberDefaultInfoReqDto()) .when().patch("members/default-information") .then().log().all() .assertThat() @@ -353,7 +356,7 @@ void patchMemberDefaultInformation() { void getStatusOfPublicProfile() { given(memberService.getMemberPublicProfileByMemberId(any())) - .willReturn(MemberFixture.GET_MEMBER_PUBLIC_PROFILE); + .willReturn(memberFixture.createGetMemberPublicProfileResDto()); restDocs .cookie(ACCESS_TOKEN) @@ -374,7 +377,7 @@ void getStatusOfPublicProfile() { void getOtherStatusOfPublicProfile() { given(memberService.getMemberPublicProfileByMemberId(any())) - .willReturn(MemberFixture.GET_MEMBER_PUBLIC_PROFILE); + .willReturn(memberFixture.createGetMemberPublicProfileResDto()); restDocs .cookie(ACCESS_TOKEN) @@ -398,7 +401,7 @@ void changePublicProfile() { restDocs .cookie(ACCESS_TOKEN) .contentType(MediaType.APPLICATION_JSON_VALUE) - .body(MemberFixture.PATCH_MEMBER_PUBLIC_PROFILE_REQUEST) + .body(memberFixture.createPatchMemberPublicProfileReqDto()) .when().patch("members/public-profile") .then().log().all() .assertThat() @@ -415,11 +418,11 @@ void changePublicProfile() { void checkNicknamePossible() { given(memberService.checkNicknamePossible(any())) - .willReturn(MemberFixture.POST_NICKNAME_RESPONSE); + .willReturn(memberFixture.createPostNicknameResDto()); restDocs .contentType(MediaType.APPLICATION_JSON_VALUE) - .body(MemberFixture.POST_NICKNAME_REQUEST) + .body(memberFixture.createPostNicknameReqDto()) .when().post("members/nickname") .then().log().all() .assertThat() @@ -442,7 +445,7 @@ void changeNickname() { restDocs .cookie(ACCESS_TOKEN) .contentType(MediaType.APPLICATION_JSON_VALUE) - .body(MemberFixture.POST_NICKNAME_REQUEST) + .body(memberFixture.createPostNicknameReqDto()) .when().patch("members/nickname") .then().log().all() .assertThat() @@ -461,7 +464,7 @@ void changeMemberMajor() { restDocs .cookie(ACCESS_TOKEN) .contentType(MediaType.APPLICATION_JSON_VALUE) - .body(MemberFixture.PATCH_IS_MAJOR_REQUEST) + .body(memberFixture.createPatchMemberMajorReqDto()) .when().patch("members/major") .then().log().all() .assertThat() @@ -480,7 +483,7 @@ void changeMemberMajorTrack() { restDocs .cookie(ACCESS_TOKEN) .contentType(MediaType.APPLICATION_JSON_VALUE) - .body(MemberFixture.PATCH_MEMBER_MAJOR_TRACK) + .body(memberFixture.createPatchMemberMajorTrackReqDto()) .when().patch("members/major-track") .then().log().all() .assertThat() diff --git a/src/test/java/com/ssafy/ssafsound/domain/member/service/MemberServiceTest.java b/src/test/java/com/ssafy/ssafsound/domain/member/service/MemberServiceTest.java index 7391fb4f1..56a58a60f 100644 --- a/src/test/java/com/ssafy/ssafsound/domain/member/service/MemberServiceTest.java +++ b/src/test/java/com/ssafy/ssafsound/domain/member/service/MemberServiceTest.java @@ -1,23 +1,18 @@ package com.ssafy.ssafsound.domain.member.service; import com.ssafy.ssafsound.domain.auth.dto.AuthenticatedMember; -import com.ssafy.ssafsound.domain.auth.service.token.JwtTokenProvider; -import com.ssafy.ssafsound.domain.member.domain.*; +import com.ssafy.ssafsound.domain.member.domain.Member; +import com.ssafy.ssafsound.domain.member.domain.MemberProfile; +import com.ssafy.ssafsound.domain.member.domain.MemberToken; import com.ssafy.ssafsound.domain.member.dto.*; import com.ssafy.ssafsound.domain.member.exception.MemberException; import com.ssafy.ssafsound.domain.member.repository.*; import com.ssafy.ssafsound.domain.meta.domain.*; import com.ssafy.ssafsound.domain.meta.service.MetaDataConsumer; -import com.ssafy.ssafsound.global.common.exception.GlobalErrorInfo; -import com.ssafy.ssafsound.global.common.exception.ResourceNotFoundException; -import org.junit.jupiter.api.BeforeEach; +import com.ssafy.ssafsound.global.util.fixture.MemberFixture; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.CsvSource; -import org.mockito.ArgumentCaptor; -import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; @@ -47,115 +42,53 @@ class MemberServiceTest { @Mock private MetaDataConsumer metaDataConsumer; @Mock - private JwtTokenProvider jwtTokenProvider; - @Mock private MemberConstantProvider memberConstantProvider; @InjectMocks private MemberService memberService; - @Captor - ArgumentCaptor memberTokenArgumentCaptor; - PostMemberReqDto postMemberReqDto; - Member member, ssafyMember, notSSAFYMember; - MemberRole memberRole; - PostMemberInfoReqDto generalMemberInfoReqDto; - PostMemberInfoReqDto SSAFYMemberInfoReqDto; - PostNicknameReqDto postNicknameReqDto; - AuthenticatedMember authenticatedMember; - - @BeforeEach - void setUp() { - postMemberReqDto = PostMemberReqDto.builder() - .oauthName("github") - .oauthIdentifier("1232312312312") - .build(); - - memberRole = MemberRole.builder() - .id(1) - .roleType("user") - .build(); - - member = Member.builder() - .oauthType(OAuthType.valueOf(postMemberReqDto.getOauthName().toUpperCase())) - .oauthIdentifier(postMemberReqDto.getOauthIdentifier()) - .id(1L) - .role(memberRole) - .build(); - - ssafyMember = Member.builder() - .oauthType(OAuthType.valueOf(postMemberReqDto.getOauthName().toUpperCase())) - .oauthIdentifier(postMemberReqDto.getOauthIdentifier()) - .id(2L) - .role(memberRole) - .ssafyMember(true) - .build(); - notSSAFYMember = Member.builder() - .id(3L) - .role(memberRole) - .ssafyMember(false) - .build(); - - generalMemberInfoReqDto = PostMemberInfoReqDto.builder() - .ssafyMember(false) - .nickname("taeyong") - .isMajor(true) - .build(); - - SSAFYMemberInfoReqDto = PostMemberInfoReqDto.builder() - .ssafyMember(true) - .nickname("taeyong") - .campus("서울") - .isMajor(true) - .semester(9) - .build(); - - postNicknameReqDto = new PostNicknameReqDto("taeyong"); - authenticatedMember = AuthenticatedMember.from(member); - } + MemberFixture memberFixture = new MemberFixture(); @Test @DisplayName("새로운 Oauth Identifier가 주어졌다면 멤버를 저장하는데 성공합니다.") void Given_OauthIdentifier_When_SaveMember_Then_Success() { - AuthenticatedMember authenticatedMemberReq = AuthenticatedMember.builder() - .memberId(member.getId()) - .memberRole(member.getRole().getRoleType()) - .build(); - - //given Mock Stub - given(memberRepository.findByOauthIdentifier(postMemberReqDto.getOauthIdentifier())).willReturn(Optional.empty()); - given(memberRoleRepository.findByRoleType("user")).willReturn(Optional.of(memberRole)); - given(memberRepository.save(argThat(member -> member.getOauthIdentifier().equals("1232312312312")))).willReturn(member); + //given + Member member = memberFixture.createGeneralMember(); + PostMemberReqDto postMemberReqDto = memberFixture.createPostMemberReqDto(); + given(memberRepository.findByOauthIdentifier(postMemberReqDto.getOauthIdentifier())) + .willReturn(Optional.empty()); + given(memberRoleRepository.findByRoleType("user")).willReturn(Optional.of(member.getRole())); + given(memberRepository.save(any())).willReturn(member); //when - AuthenticatedMember authenticatedMemberRes = memberService.createMemberByOauthIdentifier(postMemberReqDto); + AuthenticatedMember response = memberService.createMemberByOauthIdentifier(postMemberReqDto); //then assertAll( - () -> assertThat(authenticatedMemberRes.getMemberId()).isEqualTo(authenticatedMemberReq.getMemberId()), - () -> assertThat(authenticatedMemberRes.getMemberRole()).isEqualTo(authenticatedMemberReq.getMemberRole()) + () -> assertEquals(response.getMemberId(), member.getId()), + () -> assertEquals(response.getMemberRole(), member.getRole().getRoleType()) ); //verify - verify(memberRepository).findByOauthIdentifier(eq(postMemberReqDto.getOauthIdentifier())); - verify(memberRoleRepository).findByRoleType(eq("user")); - verify(memberRepository).save(any()); + verify(memberRepository, times(1)) + .findByOauthIdentifier(eq(postMemberReqDto.getOauthIdentifier())); + verify(memberRoleRepository, times(1)).findByRoleType(eq("user")); + verify(memberRepository, times(1)).save(any()); } @Test @DisplayName("존재하는 Oauth Identifier와 일치한다면 해당 멤버를 가져옵니다.") void Given_ExistOauthIdentifier_When_FindMember_Then_Success() { - AuthenticatedMember authenticatedMemberReq = AuthenticatedMember.builder() - .memberId(member.getId()) - .memberRole(member.getRole().getRoleType()) - .build(); - + //given + Member member = memberFixture.createGeneralMember(); + PostMemberReqDto postMemberReqDto = memberFixture.createPostMemberReqDto(); + given(memberRepository.findByOauthIdentifier(postMemberReqDto.getOauthIdentifier())) + .willReturn(Optional.of(member)); //when - given(memberRepository.findByOauthIdentifier(postMemberReqDto.getOauthIdentifier())).willReturn(Optional.of(member)); - AuthenticatedMember authenticatedMemberRes = memberService.createMemberByOauthIdentifier(postMemberReqDto); + AuthenticatedMember response = memberService.createMemberByOauthIdentifier(postMemberReqDto); //then assertAll( - () -> assertThat(authenticatedMemberRes.getMemberId()).isEqualTo(authenticatedMemberReq.getMemberId()), - () -> assertThat(authenticatedMemberRes.getMemberRole()).isEqualTo(authenticatedMemberReq.getMemberRole()) + () -> assertEquals(response.getMemberId(), member.getId()), + () -> assertEquals(response.getMemberRole(), member.getRole().getRoleType()) ); verify(memberRepository).findByOauthIdentifier(eq(postMemberReqDto.getOauthIdentifier())); @@ -164,302 +97,344 @@ void Given_ExistOauthIdentifier_When_FindMember_Then_Success() { @Test @DisplayName("존재하는 Oauth Identifier를 가져왔지만 요청된 정보와 일치하지 않다면 예외를 던진다.") void Given_OauthIdentifier_When_CompareIncorrectRequest_Then_ThrowException() { - PostMemberReqDto testPostMemberReqDto = PostMemberReqDto.builder() - .oauthName("kakao") - .oauthIdentifier(postMemberReqDto.getOauthIdentifier()) - .build(); + //given + PostMemberReqDto postMemberReqDto = memberFixture.createPostMemberReqDto(); + Member member = memberFixture.createInitializerMember(); + given(memberRepository.findByOauthIdentifier(postMemberReqDto.getOauthIdentifier())) + .willReturn(Optional.of(member)); - given(memberRepository.findByOauthIdentifier(postMemberReqDto.getOauthIdentifier())).willReturn(Optional.of(member)); + //when, then + assertThrows(MemberException.class, + () -> memberService.createMemberByOauthIdentifier(postMemberReqDto)); - assertThrows(MemberException.class, () -> memberService.createMemberByOauthIdentifier(testPostMemberReqDto)); + //verify + verify(memberRepository, times(1)) + .findByOauthIdentifier(postMemberReqDto.getOauthIdentifier()); } @Test @DisplayName("Member가 토큰을 발급한 적이 없다면 토큰을 발급하고 저장한다.") void Given_Tokens_When_InitializeMember_Then_Success() { - String accessToken = jwtTokenProvider.createAccessToken(authenticatedMember); - String refreshToken = jwtTokenProvider.createRefreshToken(authenticatedMember); - given(memberTokenRepository.findById(authenticatedMember.getMemberId())).willReturn(Optional.empty()); - given(memberRepository.findById(authenticatedMember.getMemberId())).willReturn(Optional.of(member)); - - memberService.saveTokenByMember(authenticatedMember, accessToken, refreshToken); + //given + Member member = memberFixture.createInitializerMember(); + AuthenticatedMember authenticatedMember = AuthenticatedMember.from(member); + given(memberTokenRepository.findById(authenticatedMember.getMemberId())) + .willReturn(Optional.empty()); + given(memberRepository.findById(authenticatedMember.getMemberId())) + .willReturn(Optional.of(member)); - verify(memberTokenRepository).save(memberTokenArgumentCaptor.capture()); - MemberToken memberTokenRes = memberTokenArgumentCaptor.getValue(); + //when + Member response = memberService + .saveTokenByMember(authenticatedMember, memberFixture.createMemberTokensResDto()); + //then assertAll( - () -> assertThat(memberTokenRes.getAccessToken()).isEqualTo(accessToken), - () -> assertThat(memberTokenRes.getRefreshToken()).isEqualTo(refreshToken) + () -> assertEquals(response.getId(), authenticatedMember.getMemberId()), + () -> assertEquals(response.getRole().getRoleType(), authenticatedMember.getMemberRole()) ); - verify(memberTokenRepository).findById(authenticatedMember.getMemberId()); - verify(memberRepository).findById(authenticatedMember.getMemberId()); + + //verify + verify(memberTokenRepository, times(1)) + .findById(authenticatedMember.getMemberId()); + verify(memberRepository, times(1)) + .findById(authenticatedMember.getMemberId()); } @Test @DisplayName("Member가 토큰을 발급한 적이 있다면 새로운 토큰들로 저장한다.") void Given_Tokens_When_JoinedMember_Then_SuccessExchangeTokens() { - String accessToken = jwtTokenProvider.createAccessToken(authenticatedMember); - String refreshToken = jwtTokenProvider.createRefreshToken(authenticatedMember); - MemberToken memberToken = MemberToken.builder() - .member(member) - .build(); + //given + MemberToken memberToken = memberFixture.createMemberToken(); + AuthenticatedMember authenticatedMember = AuthenticatedMember.from(memberToken.getMember()); + given(memberRepository.findById(authenticatedMember.getMemberId())) + .willReturn(Optional.of(memberToken.getMember())); + given(memberTokenRepository.findById(authenticatedMember.getMemberId())) + .willReturn(Optional.of(memberToken)); - given(memberRepository.findById(authenticatedMember.getMemberId())).willReturn(Optional.of(member)); - given(memberTokenRepository.findById(authenticatedMember.getMemberId())).willReturn(Optional.of(memberToken)); + //when + Member response = memberService.saveTokenByMember(authenticatedMember, memberFixture.createMemberTokensResDto()); - memberService.saveTokenByMember(authenticatedMember, accessToken, refreshToken); + //then + assertAll( + () -> assertEquals(response.getId(), authenticatedMember.getMemberId()), + () -> assertEquals(response.getRole().getRoleType(), authenticatedMember.getMemberRole()) + ); - verify(memberRepository).findById(authenticatedMember.getMemberId()); - verify(memberTokenRepository).findById(authenticatedMember.getMemberId()); + //verify + verify(memberRepository, times(1)).findById(authenticatedMember.getMemberId()); + verify(memberTokenRepository, times(1)).findById(authenticatedMember.getMemberId()); } @Test @DisplayName("가입이 안된 Member라면 토큰 발급을 시도하면 예외가 발생한다.") void Given_Member_When_NotJoinedMember_Then_ThrowMemberException() { - String accessToken = jwtTokenProvider.createAccessToken(authenticatedMember); - String refreshToken = jwtTokenProvider.createRefreshToken(authenticatedMember); - - given(memberRepository.findById(authenticatedMember.getMemberId())).willReturn(Optional.empty()); + //given + AuthenticatedMember authenticatedMember = AuthenticatedMember.from(memberFixture.createInitializerMember()); + given(memberRepository.findById(any())).willReturn(Optional.empty()); + //when, then assertThrows(MemberException.class, - () -> memberService.saveTokenByMember(authenticatedMember, accessToken, refreshToken)); + () -> memberService.saveTokenByMember(authenticatedMember, memberFixture.createMemberTokensResDto())); - verify(memberRepository).findById(authenticatedMember.getMemberId()); + //verify + verify(memberRepository, times(1)).findById(authenticatedMember.getMemberId()); } @Test @DisplayName("이미 존재하는 닉네임이라면 닉네임 중복이라는 예외가 발생한다.") void Given_Nickname_When_ExistNickname_Then_ThrowMemberException() { + //given + PostNicknameReqDto postNicknameReqDto = memberFixture.createPostNicknameReqDto(); given(memberRepository.existsByNickname(postNicknameReqDto.getNickname())).willReturn(true); + //when, then assertThrows(MemberException.class, () -> memberService.checkNicknamePossible(postNicknameReqDto)); - verify(memberRepository).existsByNickname(eq("taeyong")); + //verify + verify(memberRepository, times(1)).existsByNickname(eq("james")); } @Test @DisplayName("존재하지 않는 닉네임이라면 닉네임 사용을 할 수 있는 dto를 반환한다.") void Given_Nickname_When_NotExistNickname_Then_ReturnTrue() { - PostNicknameResDto postNicknameResDto = PostNicknameResDto.builder() - .possible(true) - .build(); - + //given + PostNicknameReqDto postNicknameReqDto = memberFixture.createPostNicknameReqDto(); given(memberRepository.existsByNickname(postNicknameReqDto.getNickname())).willReturn(false); + //when PostNicknameResDto result = memberService.checkNicknamePossible(postNicknameReqDto); - assertThat(result.isPossible()).isEqualTo(postNicknameResDto.isPossible()); + //then + assertThat(result.isPossible()).isTrue(); - verify(memberRepository).existsByNickname(eq("taeyong")); + //verify + verify(memberRepository, times(1)) + .existsByNickname(eq(postNicknameReqDto.getNickname())); } @Test @DisplayName("회원가입 이후 정보 입력을 하지 않았다면 닉네임과 싸피멤버여부에 대해 null을 가진 dto를 반환한다.") void Given_Member_When_GetMemberInfo_Then_Success() { - GetMemberResDto getMemberResDto = GetMemberResDto.fromGeneralUser(member); - given(memberRepository.findById(authenticatedMember.getMemberId())).willReturn(Optional.of(member)); + //given + Member member = memberFixture.createInitializerMember(); + given(memberRepository.findById(member.getId())).willReturn(Optional.of(member)); - GetMemberResDto result = memberService.getMemberInformation(authenticatedMember.getMemberId()); + //when + GetMemberResDto response = memberService.getMemberInformation(member.getId()); - assertAll( - () -> assertThat(result.getMemberId()).isEqualTo(getMemberResDto.getMemberId()), - () -> assertThat(result.getMemberRole()).isEqualTo(getMemberResDto.getMemberRole()), - () -> assertThat(result.getSsafyMember()).isEqualTo(getMemberResDto.getSsafyMember()), - () -> assertThat(result.getNickname()).isEqualTo(getMemberResDto.getNickname()) - ); + //then + assertThat(response).usingRecursiveComparison().isEqualTo(GetMemberResDto.fromGeneralUser(member)); - verify(memberRepository).findById(authenticatedMember.getMemberId()); + //verify + verify(memberRepository, times(1)).findById(member.getId()); } @Test @DisplayName("회원가입 이후 싸피유저가 아닌 일반 유저에 대해 정보 입력을 했다면 일반 유저 dto를 반환한다.") void Given_Member_When_GetGeneralMemberInfo_Then_Success() { - member.setGeneralMemberInformation(generalMemberInfoReqDto); - GetMemberResDto getMemberResDto = GetMemberResDto.fromGeneralUser(member); - given(memberRepository.findById(authenticatedMember.getMemberId())).willReturn(Optional.of(member)); + //given + Member member = memberFixture.createGeneralMember(); + given(memberRepository.findById(member.getId())).willReturn(Optional.of(member)); - GetMemberResDto result = memberService.getMemberInformation(authenticatedMember.getMemberId()); + //when + GetMemberResDto response = memberService.getMemberInformation(member.getId()); - assertAll( - () -> assertThat(result.getMemberId()).isEqualTo(getMemberResDto.getMemberId()), - () -> assertThat(result.getMemberRole()).isEqualTo(getMemberResDto.getMemberRole()), - () -> assertThat(result.getSsafyMember()).isEqualTo(getMemberResDto.getSsafyMember()), - () -> assertThat(result.getNickname()).isEqualTo(getMemberResDto.getNickname()), - () -> assertThat(result.getIsMajor()).isEqualTo(getMemberResDto.getIsMajor()) - ); - verify(memberRepository).findById(authenticatedMember.getMemberId()); + //then + assertThat(response).usingRecursiveComparison().isEqualTo(GetMemberResDto.fromGeneralUser(member)); + + //verify + verify(memberRepository, times(1)).findById(member.getId()); } @Test @DisplayName("회원가입 이후 싸피유저에 대한 정보 입력을 했다면 싸피 유저 dto를 반환한다.") void Given_Member_When_GetSSAFYMemberInfo_Then_Success() { - given(metaDataConsumer.getMetaData(MetaDataType.CAMPUS.name(), SSAFYMemberInfoReqDto.getCampus())).willReturn(new MetaData(Campus.SEOUL)); - member.setSSAFYMemberInformation(SSAFYMemberInfoReqDto, metaDataConsumer); - GetMemberResDto getMemberResDto = GetMemberResDto.fromSSAFYUser(member); - given(memberRepository.findById(authenticatedMember.getMemberId())).willReturn(Optional.of(member)); - - GetMemberResDto result = memberService.getMemberInformation(authenticatedMember.getMemberId()); + //given + GetMemberResDto getMemberResDto = memberFixture.createCertifiedSSAFYMemberResDto(); + given(memberRepository.findById(getMemberResDto.getMemberId())) + .willReturn(Optional.of(memberFixture.createCertifiedSSAFYMember())); + //when + GetMemberResDto response = memberService.getMemberInformation(getMemberResDto.getMemberId()); - assertAll( - () -> assertThat(result.getMemberId()).isEqualTo(getMemberResDto.getMemberId()), - () -> assertThat(result.getMemberRole()).isEqualTo(getMemberResDto.getMemberRole()), - () -> assertThat(result.getSsafyMember()).isEqualTo(getMemberResDto.getSsafyMember()), - () -> assertThat(result.getNickname()).isEqualTo(getMemberResDto.getNickname()), - () -> assertThat(result.getIsMajor()).isEqualTo(getMemberResDto.getIsMajor()), - () -> assertThat(result.getSsafyInfo().getCampus()).isEqualTo(getMemberResDto.getSsafyInfo().getCampus()), - () -> assertThat(result.getSsafyInfo().getSemester()).isEqualTo(getMemberResDto.getSsafyInfo().getSemester()) - ); + //then + assertThat(response).usingRecursiveComparison().isEqualTo(getMemberResDto); - verify(metaDataConsumer).getMetaData(MetaDataType.CAMPUS.name(), "서울"); - verify(memberRepository).findById(authenticatedMember.getMemberId()); + //verify + verify(memberRepository, times(1)).findById(getMemberResDto.getMemberId()); } @Test @DisplayName("소셜 로그인 이후, 회원정보 입력에서 닉네임이 중복됐다면 예외가 발생한다.") void Given_ExistNickname_When_Register_MemberInfo_Then_ThrowMemberException() { - given(memberRepository.existsByNickname(generalMemberInfoReqDto.getNickname())).willReturn(true); + //given + AuthenticatedMember authenticatedMember = AuthenticatedMember.from(memberFixture.createGeneralMember()); + PostMemberInfoReqDto postMemberInfoReqDto = memberFixture.createPostGeneralMemberInfoReqDto(); + given(memberRepository.existsByNickname(postMemberInfoReqDto.getNickname())).willReturn(true); - assertThrows(MemberException.class, () -> memberService.registerMemberInformation(authenticatedMember, generalMemberInfoReqDto)); + //when, then + assertThrows(MemberException.class, + () -> memberService.registerMemberInformation(authenticatedMember, postMemberInfoReqDto)); - verify(memberRepository).existsByNickname(generalMemberInfoReqDto.getNickname()); + //verify + verify(memberRepository, times(1)).existsByNickname(postMemberInfoReqDto.getNickname()); } @Test @DisplayName("소셜 로그인 이후, 회원정보 입력에서 회원을 찾을 수 없다면 예외가 발생한다.") void Given_NotExistMember_When_Register_MemberInfo_Then_ThrowMemberException() { - given(memberRepository.existsByNickname(generalMemberInfoReqDto.getNickname())).willReturn(false); + //given + AuthenticatedMember authenticatedMember = AuthenticatedMember.from(memberFixture.createGeneralMember()); + PostMemberInfoReqDto postMemberInfoReqDto = memberFixture.createPostGeneralMemberInfoReqDto(); + given(memberRepository.existsByNickname(postMemberInfoReqDto.getNickname())).willReturn(false); given(memberRepository.findById(authenticatedMember.getMemberId())).willReturn(Optional.empty()); - assertThrows(MemberException.class, () -> memberService.registerMemberInformation(authenticatedMember, generalMemberInfoReqDto)); + //when, then + assertThrows(MemberException.class, + () -> memberService.registerMemberInformation(authenticatedMember, postMemberInfoReqDto)); - verify(memberRepository).existsByNickname(generalMemberInfoReqDto.getNickname()); - verify(memberRepository).findById(authenticatedMember.getMemberId()); + //verify + verify(memberRepository, times(1)).existsByNickname(postMemberInfoReqDto.getNickname()); + verify(memberRepository, times(1)).findById(authenticatedMember.getMemberId()); } @Test @DisplayName("소셜 로그인 이후, 일반 회원 정보에 대해 입력했다면 일반 회원정보 dto를 return 받는다.") void Given_PostGeneralMemberInfo_When_Register_MemberInfo_Then_ReturnGeneralMemberResDto() { - member.setGeneralMemberInformation(generalMemberInfoReqDto); - GetMemberResDto getMemberResDto = GetMemberResDto.fromGeneralUser(member); - given(memberRepository.existsByNickname(generalMemberInfoReqDto.getNickname())).willReturn(false); + //given + Member member = memberFixture.createGeneralMember(); + AuthenticatedMember authenticatedMember = AuthenticatedMember.from(member); + PostMemberInfoReqDto postMemberInfoReqDto = memberFixture.createPostGeneralMemberInfoReqDto(); + given(memberRepository.existsByNickname(postMemberInfoReqDto.getNickname())).willReturn(false); given(memberRepository.findById(authenticatedMember.getMemberId())).willReturn(Optional.of(member)); - GetMemberResDto result = memberService.registerMemberInformation(authenticatedMember, generalMemberInfoReqDto); + //when + GetMemberResDto response = memberService.registerMemberInformation(authenticatedMember, postMemberInfoReqDto); - assertThat(result).extracting(GetMemberResDto::getMemberId).isEqualTo(getMemberResDto.getMemberId()); - assertThat(result).extracting(GetMemberResDto::getSsafyMember).isEqualTo(getMemberResDto.getSsafyMember()); - assertThat(result).extracting(GetMemberResDto::getNickname).isEqualTo(getMemberResDto.getNickname()); - assertThat(result).extracting(GetMemberResDto::getIsMajor).isEqualTo(getMemberResDto.getIsMajor()); + //then + assertThat(response).usingRecursiveComparison().isEqualTo(GetMemberResDto.fromGeneralUser(member)); - verify(memberRepository).existsByNickname(generalMemberInfoReqDto.getNickname()); - verify(memberRepository).findById(authenticatedMember.getMemberId()); + //verify + verify(memberRepository, times(1)).existsByNickname(postMemberInfoReqDto.getNickname()); + verify(memberRepository, times(1)).findById(authenticatedMember.getMemberId()); } @Test @DisplayName("소셜 로그인 이후, 싸피 회원 정보에 대해 입력했다면 싸피 회원정보 dto를 return 받는다.") void Given_PostSSAFYMemberInfo_When_Register_MemberInfo_Then_ReturnSSAFYMemberResDto() { - given(metaDataConsumer.getMetaData(MetaDataType.CAMPUS.name(), SSAFYMemberInfoReqDto.getCampus())).willReturn(new MetaData(Campus.SEOUL)); - member.setSSAFYMemberInformation(SSAFYMemberInfoReqDto, metaDataConsumer); - GetMemberResDto getMemberResDto = GetMemberResDto.fromSSAFYUser(member); - given(memberRepository.existsByNickname(SSAFYMemberInfoReqDto.getNickname())).willReturn(false); + //given + Member member = memberFixture.createCertifiedSSAFYMember(); + AuthenticatedMember authenticatedMember = AuthenticatedMember.from(member); + PostMemberInfoReqDto postMemberInfoReqDto = memberFixture.createPostSSAFYMemberInfoReqDto(); + given(memberRepository.existsByNickname(postMemberInfoReqDto.getNickname())).willReturn(false); given(memberRepository.findById(authenticatedMember.getMemberId())).willReturn(Optional.of(member)); + given(metaDataConsumer.getMetaData(any(), any())).willReturn(new MetaData(Campus.SEOUL)); - GetMemberResDto result = memberService.registerMemberInformation(authenticatedMember, SSAFYMemberInfoReqDto); + //when + GetMemberResDto response = memberService.registerMemberInformation(authenticatedMember, postMemberInfoReqDto); - assertThat(result).extracting(GetMemberResDto::getMemberId).isEqualTo(getMemberResDto.getMemberId()); - assertThat(result).extracting(GetMemberResDto::getSsafyMember).isEqualTo(getMemberResDto.getSsafyMember()); - assertThat(result).extracting(GetMemberResDto::getNickname).isEqualTo(getMemberResDto.getNickname()); - assertThat(result).extracting(GetMemberResDto::getIsMajor).isEqualTo(getMemberResDto.getIsMajor()); - assertThat(result).extracting(GetMemberResDto::getSsafyInfo).extracting(SSAFYInfo::getCampus).isEqualTo(getMemberResDto.getSsafyInfo().getCampus()); - assertThat(result).extracting(GetMemberResDto::getSsafyInfo).extracting(SSAFYInfo::getSemester).isEqualTo(getMemberResDto.getSsafyInfo().getSemester()); + //then + assertThat(response).usingRecursiveComparison().isEqualTo(GetMemberResDto.fromSSAFYUser(member)); - verify(metaDataConsumer, times(2)).getMetaData(MetaDataType.CAMPUS.name(), "서울"); - verify(memberRepository).existsByNickname(generalMemberInfoReqDto.getNickname()); - verify(memberRepository).findById(authenticatedMember.getMemberId()); + //verify + verify(memberRepository, times(1)).existsByNickname(postMemberInfoReqDto.getNickname()); + verify(memberRepository, times(1)).findById(authenticatedMember.getMemberId()); } - @ParameterizedTest - @CsvSource({"Java, 1, ONE_SEMESTER, 선물", "Java, 2, TWO_SEMESTER, 하나", "Java, 3, THREE_SEMESTER, 출발", "Java, 4, FOUR_SEMESTER, 충전", "Java, 5, FIVE_SEMESTER, 극복", - "Java, 6, SIX_SEMESTER, hot식스", "Java, 7, SEVEN_SEMESTER, 럭키", "Java, 8, EIGHT_SEMESTER, 칠전팔", "Java, 9, NINE_SEMESTER, great", "Java, 10, TEN_SEMESTER, 텐션"}) + @Test @DisplayName("싸피생 인증 요청 시, 정답에 대한 요청을 했으면 성공한다.") - void Given_PostCertificationInfo_When_Submit_SSAFY_Certification_Answer_Then_Success(String majorTrack, int semester, String name, String answer) { + void Given_PostCertificationInfo_When_Submit_SSAFY_Certification_Answer_Then_Success() { + //given PostCertificationInfoReqDto postCertificationInfoReqDto = PostCertificationInfoReqDto.builder() - .majorTrack(majorTrack) - .semester(semester) - .answer(answer) + .majorTrack("Java") + .semester(1) + .answer("선물") .build(); - - given(metaDataConsumer.getMetaData(MetaDataType.MAJOR_TRACK.name(), majorTrack)) + Member member = memberFixture.createUncertifiedSSAFYMember(); + AuthenticatedMember authenticatedMember = AuthenticatedMember.from(member); + given(metaDataConsumer.getMetaData(MetaDataType.MAJOR_TRACK.name(), "Java")) .willReturn(new MetaData(MajorTrack.JAVA)); given(metaDataConsumer.getMetaData(MetaDataType.CERTIFICATION.name(), postCertificationInfoReqDto.getAnswer())) - .willReturn(new MetaData(Certification.valueOf(name))); + .willReturn(new MetaData(Certification.ONE_SEMESTER)); given(memberRepository.findById(authenticatedMember.getMemberId())) .willReturn(Optional.of(member)); given(memberConstantProvider.getCERTIFICATION_INQUIRY_TIME()).willReturn(5); given(memberConstantProvider.getMAX_MINUTES()).willReturn(5); - PostCertificationInfoResDto postCertificationInfoResDto = memberService + //when + PostCertificationInfoResDto response = memberService .certifySSAFYInformation(authenticatedMember.getMemberId(), postCertificationInfoReqDto); - assertThat(member.getCertificationState()).isEqualTo(AuthenticationStatus.CERTIFIED); - assertThat(member.getMajorTrack().getName()).isEqualTo(majorTrack); - assertTrue(postCertificationInfoResDto.isPossible()); + //then + assertThat(response.isPossible()).isTrue(); - verify(metaDataConsumer).getMetaData(MetaDataType.MAJOR_TRACK.name(), majorTrack); - verify(metaDataConsumer).getMetaData(MetaDataType.CERTIFICATION.name(), postCertificationInfoReqDto.getAnswer()); - verify(memberRepository).findById(authenticatedMember.getMemberId()); + //verify + verify(metaDataConsumer, times(1)) + .getMetaData(MetaDataType.MAJOR_TRACK.name(), "Java"); + verify(metaDataConsumer, times(1)) + .getMetaData(MetaDataType.CERTIFICATION.name(), postCertificationInfoReqDto.getAnswer()); + verify(memberRepository, times(1)).findById(authenticatedMember.getMemberId()); } - @ParameterizedTest - @CsvSource({"Java, 2, ONE_SEMESTER, 선물", "Java, 3, TWO_SEMESTER, 하나", "Java, 1, THREE_SEMESTER, 출발", "Java, 5, FOUR_SEMESTER, 충전", "Java, 6, FIVE_SEMESTER, 극복", - "Java, 2, SIX_SEMESTER, hot식스", "Java, 4, SEVEN_SEMESTER, 럭키", "Java, 7, EIGHT_SEMESTER, 칠전팔", "Java, 8, NINE_SEMESTER, great", "Java, 9, TEN_SEMESTER, 텐션"}) + @Test @DisplayName("싸피생 인증 요청 시, 정답에 대한 요청이 존재하지만 기수 정보가 다를 때 인증에 실패한다.") - void Given_PostCertificationInfo_When_Submit_SSAFY_Certification_Answer_Then_Fail(String majorTrack, int semester, String name, String answer) { + void Given_PostCertificationInfo_When_Submit_SSAFY_Certification_Answer_Then_Fail() { + //given PostCertificationInfoReqDto postCertificationInfoReqDto = PostCertificationInfoReqDto.builder() - .majorTrack(majorTrack) - .semester(semester) - .answer(answer) + .majorTrack("Java") + .semester(2) + .answer("선물") .build(); + Member member = memberFixture.createUncertifiedSSAFYMember(); + AuthenticatedMember authenticatedMember = AuthenticatedMember.from(member); given(memberRepository.findById(authenticatedMember.getMemberId())).willReturn(Optional.of(member)); given(metaDataConsumer.getMetaData(MetaDataType.CERTIFICATION.name(), postCertificationInfoReqDto.getAnswer().toLowerCase())) - .willReturn(new MetaData(Certification.valueOf(name))); + .willReturn(new MetaData(Certification.ONE_SEMESTER)); given(memberConstantProvider.getMAX_MINUTES()).willReturn(5); given(memberConstantProvider.getCERTIFICATION_INQUIRY_TIME()).willReturn(5); - PostCertificationInfoResDto postCertificationInfoResDto = memberService.certifySSAFYInformation( + //when + PostCertificationInfoResDto response = memberService.certifySSAFYInformation( authenticatedMember.getMemberId(), postCertificationInfoReqDto); - assertThat(postCertificationInfoResDto.isPossible()).isFalse(); + //then + assertThat(response.isPossible()).isFalse(); - verify(metaDataConsumer).getMetaData(MetaDataType.CERTIFICATION.name(), postCertificationInfoReqDto.getAnswer().toLowerCase()); + //verify + verify(metaDataConsumer, times(1)) + .getMetaData(MetaDataType.CERTIFICATION.name(), postCertificationInfoReqDto.getAnswer().toLowerCase()); } @Test @DisplayName("싸피생 인증 요청 시, 회원 정보를 찾을 수 없다면 예외가 발생한다.") void Given_PostCertificationInfo_When_Submit_SSAFY_Certification_Answer_Then_ThrowMemberException() { + //given PostCertificationInfoReqDto postCertificationInfoReqDto = PostCertificationInfoReqDto.builder() + .majorTrack("Java") .semester(1) .answer("선물") .build(); - + AuthenticatedMember authenticatedMember = AuthenticatedMember.from(memberFixture.createUncertifiedSSAFYMember()); given(memberRepository.findById(authenticatedMember.getMemberId())).willReturn(Optional.empty()); + //when, then assertThrows(MemberException.class, () -> memberService.certifySSAFYInformation( authenticatedMember.getMemberId(), postCertificationInfoReqDto)); - verify(memberRepository).findById(authenticatedMember.getMemberId()); + //verify + verify(memberRepository, times(1)).findById(authenticatedMember.getMemberId()); } @Test @DisplayName("마이 프로필 공개 여부 수정 시도 시, 회원 정보를 찾을 수 없다면 예외가 발생한다") void Given_IsNotExistMember_When_Try_Change_Public_Profile_Then_ThrowMemberException() { //given - PatchMemberPublicProfileReqDto patchMemberPublicProfileReqDto = new PatchMemberPublicProfileReqDto(); + PatchMemberPublicProfileReqDto patchMemberPublicProfileReqDto = memberFixture.createPatchMemberPublicProfileReqDto(); + Member member = memberFixture.createMember(); given(memberRepository.findById(member.getId())).willReturn(Optional.empty()); - //then + //when, then assertThrows(MemberException.class, () -> memberService.patchMemberPublicProfile(member.getId(), patchMemberPublicProfileReqDto)); @@ -471,10 +446,11 @@ void Given_IsNotExistMember_When_Try_Change_Public_Profile_Then_ThrowMemberExcep @DisplayName("마이 프로필 공개 여부 수정에 성공한다.") void Given_Valid_PatchMemberPublicProfileReqDto_When_Try_Change_Public_Profile_Then_Success() { //given - PatchMemberPublicProfileReqDto patchMemberPublicProfileReqDto = new PatchMemberPublicProfileReqDto(false); + PatchMemberPublicProfileReqDto patchMemberPublicProfileReqDto = memberFixture.createPatchMemberPublicProfileReqDto(); + Member member = memberFixture.createMember(); given(memberRepository.findById(member.getId())).willReturn(Optional.of(member)); - //then + //when, then memberService.patchMemberPublicProfile(member.getId(), patchMemberPublicProfileReqDto); //verify @@ -485,9 +461,10 @@ void Given_Valid_PatchMemberPublicProfileReqDto_When_Try_Change_Public_Profile_T @DisplayName("마이 프로필 공개 여부 조회 시도 시, 회원 정보를 찾을 수 없다면 예외가 발생한다") void Given_IsNotExistMember_When_Get_Public_Profile_Then_ThrowMemberException() { //given + Member member = memberFixture.createMember(); given(memberRepository.findById(member.getId())).willReturn(Optional.empty()); - //then + //when, then assertThrows(MemberException.class, () -> memberService.getMemberPublicProfileByMemberId(member.getId())); @@ -499,10 +476,14 @@ void Given_IsNotExistMember_When_Get_Public_Profile_Then_ThrowMemberException() @DisplayName("마이 프로필 공개 여부 조회에 성공한다.") void Given_Valid_Member_When_Get_Public_Profile_Then_Success() { //given + Member member = memberFixture.createMember(); given(memberRepository.findById(member.getId())).willReturn(Optional.of(member)); + //when + GetMemberPublicProfileResDto response = memberService.getMemberPublicProfileByMemberId(member.getId()); + //then - memberService.getMemberPublicProfileByMemberId(member.getId()); + assertThat(response.getIsPublic()).isEqualTo(member.getPublicProfile()); //verify verify(memberRepository, times(1)).findById(member.getId()); @@ -513,28 +494,36 @@ void Given_Valid_Member_When_Get_Public_Profile_Then_Success() { @DisplayName("멤버의 포트폴리오 정보를 수정하는데 성공한다.") void Given_Valid_Member_Portfolio_Information_When_Put_Portfolio_Then_Success() { //given - PutMemberPortfolioReqDto putMemberPortfolioReqDto = mock(PutMemberPortfolioReqDto.class); - MemberProfile memberProfile = mock(MemberProfile.class); - given(memberRepository.findById(1L)).willReturn(Optional.of(member)); - given(putMemberPortfolioReqDto.getSelfIntroduction()).willReturn("자기소개 합니다."); + PutMemberPortfolioReqDto putMemberPortfolioReqDto = memberFixture.createPutMemberPortfolioReqDto(); + MemberProfile memberProfile = memberFixture.createMemberProfile(); + Member member = memberProfile.getMember(); + given(memberRepository.findById(member.getId())).willReturn(Optional.of(member)); given(memberProfileRepository.findMemberProfileByMember(member)).willReturn(Optional.of(memberProfile)); - //then + //when memberService.registerMemberPortfolio(member.getId(), putMemberPortfolioReqDto); + //then + assertThat(memberProfile.getIntroduce()).isEqualTo(putMemberPortfolioReqDto.getSelfIntroduction()); + //verify verify(memberRepository, times(1)).findById(member.getId()); + verify(memberLinkRepository, times(1)).deleteMemberLinksByMember(member); + verify(memberSkillRepository, times(1)).deleteMemberSkillsByMember(member); } @Test @DisplayName("멤버의 닉네임을 수정하는데 성공한다.") void Given_Nickname_When_ChangeNickname_Then_Success() { //given - PatchMemberNicknameReqDto patchMemberNicknameReqDto = mock(PatchMemberNicknameReqDto.class); + Member member = memberFixture.createMember(); given(memberRepository.findById(member.getId())).willReturn(Optional.of(member)); + //when + memberService.changeMemberNickname(member.getId(), memberFixture.createPatchMemberNicknameReqDto()); + //then - memberService.changeMemberNickname(member.getId(), patchMemberNicknameReqDto); + assertThat(member.getNickname()).isEqualTo(memberFixture.createPatchMemberNicknameReqDto().getNickname()); //verify verify(memberRepository, times(1)).findById(member.getId()); @@ -544,14 +533,16 @@ void Given_Nickname_When_ChangeNickname_Then_Success() { @DisplayName("멤버는 전공자 여부를 수정하는데 성공한다.") void Given_Member_WhenChangeMajor_Then_Success() { //given - PatchMemberMajorReqDto patchMemberMajorReqDto = PatchMemberMajorReqDto - .builder() - .isMajor(false) - .build(); + PatchMemberMajorReqDto patchMemberMajorReqDto = memberFixture.createPatchMemberMajorReqDto(); + Member member = memberFixture.createMember(); given(memberRepository.findById(member.getId())).willReturn(Optional.of(member)); + //when memberService.changeMemberMajor(member.getId(), patchMemberMajorReqDto); + //then + assertThat(member.getMajor()).isEqualTo(patchMemberMajorReqDto.getIsMajor()); + //verify verify(memberRepository, times(1)).findById(member.getId()); } @@ -560,50 +551,39 @@ void Given_Member_WhenChangeMajor_Then_Success() { @DisplayName("멤버 전공자 트랙을 수정하는데 성공합니다.") void Given_Member_WhenChangeMajorTrack_Then_Success() { //given - PatchMemberMajorTrackReqDto patchMemberMajorTrackReqDto = PatchMemberMajorTrackReqDto - .builder() - .majorTrack("Embedded") - .build(); - given(memberRepository.findById(ssafyMember.getId())).willReturn(Optional.of(ssafyMember)); + PatchMemberMajorTrackReqDto patchMemberMajorTrackReqDto = memberFixture.createPatchMemberMajorTrackReqDto(); + Member member = memberFixture.createCertifiedSSAFYMember(); + given(memberRepository.findById(member.getId())).willReturn(Optional.of(member)); given(metaDataConsumer.getMetaData(eq(MetaDataType.MAJOR_TRACK.name()), eq("Embedded"))) .willReturn(new MetaData(MajorTrack.EMBEDDED)); - memberService.changeMemberMajorTrack(ssafyMember.getId(), patchMemberMajorTrackReqDto.getMajorTrack()); + //when + memberService.changeMemberMajorTrack(member.getId(), patchMemberMajorTrackReqDto.getMajorTrack()); + + //then + assertThat(member.getMajorTrack().getName()).isEqualTo(patchMemberMajorTrackReqDto.getMajorTrack()); - verify(memberRepository, times(1)).findById(ssafyMember.getId()); + //verify + verify(memberRepository, times(1)).findById(member.getId()); verify(metaDataConsumer, times(1)) .getMetaData(eq(MetaDataType.MAJOR_TRACK.name()), eq("Embedded")); } - @Test - @DisplayName("잘못된 전공자 트랙 정보를 입력했을때 클라이언트 측 예외가 발생합니다.") - void Given_Member_WhenChangeMajorTrack_Then_Fail() { - //given - PatchMemberMajorTrackReqDto patchMemberMajorTrackReqDto = PatchMemberMajorTrackReqDto - .builder() - .majorTrack("Embed") - .build(); - given(memberRepository.findById(ssafyMember.getId())).willReturn(Optional.of(ssafyMember)); - given(metaDataConsumer.getMetaData(eq(MetaDataType.MAJOR_TRACK.name()), eq("Embed"))) - .willThrow(new ResourceNotFoundException(GlobalErrorInfo.NOT_FOUND)); - - - assertThrows(ResourceNotFoundException.class, - () -> memberService.changeMemberMajorTrack(ssafyMember.getId(), patchMemberMajorTrackReqDto.getMajorTrack())); - } @Test @DisplayName("싸피생이 아닌 멤버가 전공 트랙 정보를 수정하려고 할 때 예외가 발생합니다.") void Given_NotSSAFYMember_WhenChangeMajorTrack_Then_Fail() { //given - PatchMemberMajorTrackReqDto patchMemberMajorTrackReqDto = PatchMemberMajorTrackReqDto - .builder() - .majorTrack("Embedded") - .build(); - given(memberRepository.findById(notSSAFYMember.getId())).willReturn(Optional.of(notSSAFYMember)); + PatchMemberMajorTrackReqDto patchMemberMajorTrackReqDto = memberFixture.createPatchMemberMajorTrackReqDto(); + Member member = memberFixture.createGeneralMember(); + given(memberRepository.findById(member.getId())).willReturn(Optional.of(member)); + //when, then assertThrows(MemberException.class, () -> memberService - .changeMemberMajorTrack(notSSAFYMember.getId(), patchMemberMajorTrackReqDto.getMajorTrack())); + .changeMemberMajorTrack(member.getId(), patchMemberMajorTrackReqDto.getMajorTrack())); + + //verify + verify(memberRepository, times(1)).findById(member.getId()); } } \ No newline at end of file diff --git a/src/test/java/com/ssafy/ssafsound/domain/auth/fixture/AuthFixture.java b/src/test/java/com/ssafy/ssafsound/global/util/fixture/AuthFixture.java similarity index 97% rename from src/test/java/com/ssafy/ssafsound/domain/auth/fixture/AuthFixture.java rename to src/test/java/com/ssafy/ssafsound/global/util/fixture/AuthFixture.java index 63f02c3a5..01204280c 100644 --- a/src/test/java/com/ssafy/ssafsound/domain/auth/fixture/AuthFixture.java +++ b/src/test/java/com/ssafy/ssafsound/global/util/fixture/AuthFixture.java @@ -1,4 +1,4 @@ -package com.ssafy.ssafsound.domain.auth.fixture; +package com.ssafy.ssafsound.global.util.fixture; import com.ssafy.ssafsound.domain.auth.dto.AuthenticatedMember; import com.ssafy.ssafsound.domain.auth.dto.CreateMemberAccessTokenResDto; diff --git a/src/test/java/com/ssafy/ssafsound/global/util/fixture/CommentFixture.java b/src/test/java/com/ssafy/ssafsound/global/util/fixture/CommentFixture.java index 8cc5c2277..7fdf8b268 100644 --- a/src/test/java/com/ssafy/ssafsound/global/util/fixture/CommentFixture.java +++ b/src/test/java/com/ssafy/ssafsound/global/util/fixture/CommentFixture.java @@ -1,31 +1,26 @@ package com.ssafy.ssafsound.global.util.fixture; import com.ssafy.ssafsound.domain.comment.domain.Comment; -import com.ssafy.ssafsound.domain.comment.dto.CommentIdElement; -import com.ssafy.ssafsound.domain.comment.dto.GetCommentElement; -import com.ssafy.ssafsound.domain.comment.dto.GetCommentReplyElement; -import com.ssafy.ssafsound.domain.comment.dto.GetCommentResDto; -import com.ssafy.ssafsound.domain.comment.dto.PatchCommentUpdateReqDto; -import com.ssafy.ssafsound.domain.comment.dto.PostCommentWriteReqDto; +import com.ssafy.ssafsound.domain.comment.dto.*; import com.ssafy.ssafsound.domain.member.dto.AuthorElement; import com.ssafy.ssafsound.domain.post.dto.PostCommonLikeResDto; import java.time.LocalDateTime; import java.util.List; -import static com.ssafy.ssafsound.global.util.fixture.MemberFixture.CERTIFIED_SSAFY_INFO; -import static com.ssafy.ssafsound.global.util.fixture.MemberFixture.MEMBER_TIM; import static com.ssafy.ssafsound.global.util.fixture.PostFixture.POST_FIXTURE1; public class CommentFixture { + private static final MemberFixture memberFixture = new MemberFixture(); + public static final AuthorElement AUTHOR_ELEMENT_COMMENT1 = AuthorElement.builder() .memberId(1L) .nickname("김싸피") .memberRole("user") .ssafyMember(true) .isMajor(true) - .ssafyInfo(CERTIFIED_SSAFY_INFO) + .ssafyInfo(memberFixture.createCertifiedSSAFYInfo()) .build(); public static final AuthorElement AUTHOR_ELEMENT_COMMENT2 = AuthorElement.builder() @@ -94,7 +89,7 @@ public class CommentFixture { public static final Comment COMMENT_FIXTURE_1 = Comment.builder() .id(1L) - .member(MEMBER_TIM) + .member(memberFixture.createMember()) .deletedComment(Boolean.FALSE) .anonymity(Boolean.FALSE) .post(POST_FIXTURE1) diff --git a/src/test/java/com/ssafy/ssafsound/global/util/fixture/MemberFixture.java b/src/test/java/com/ssafy/ssafsound/global/util/fixture/MemberFixture.java index 18750e691..e0aa931e1 100644 --- a/src/test/java/com/ssafy/ssafsound/global/util/fixture/MemberFixture.java +++ b/src/test/java/com/ssafy/ssafsound/global/util/fixture/MemberFixture.java @@ -1,10 +1,11 @@ package com.ssafy.ssafsound.global.util.fixture; +import com.ssafy.ssafsound.domain.auth.dto.CreateMemberTokensResDto; +import com.ssafy.ssafsound.domain.member.domain.*; import com.ssafy.ssafsound.domain.member.dto.*; -import com.ssafy.ssafsound.domain.meta.domain.MetaData; -import com.ssafy.ssafsound.domain.meta.domain.MajorTrack; import com.ssafy.ssafsound.domain.meta.domain.Campus; -import com.ssafy.ssafsound.domain.member.domain.*; +import com.ssafy.ssafsound.domain.meta.domain.MajorTrack; +import com.ssafy.ssafsound.domain.meta.domain.MetaData; import com.ssafy.ssafsound.domain.meta.domain.Skill; import java.time.LocalDateTime; @@ -13,207 +14,296 @@ import java.util.List; import java.util.Set; -import com.ssafy.ssafsound.domain.member.domain.AuthenticationStatus; -import com.ssafy.ssafsound.domain.member.domain.Member; -import com.ssafy.ssafsound.domain.member.domain.MemberRole; - public class MemberFixture { - private static final MemberRole memberRole = MemberRole.builder().id(1).roleType("user").build(); - - public static final Member INITIALIZER_MEMBER = Member.builder() - .id(1L) - .role(memberRole) - .build(); - - public static final Member GENERAL_MEMBER = Member.builder() - .id(1L) - .role(memberRole) - .nickname("james") - .ssafyMember(false) - .major(true) - .build(); - - public static final SSAFYInfo CERTIFIED_SSAFY_INFO = SSAFYInfo - .of(9, "서울", "CERTIFIED", new MetaData(MajorTrack.JAVA)); - - public static final SSAFYInfo UNCERTIFIED_SSAFY_INFO = SSAFYInfo - .of(9, "서울", "UNCERTIFIED", null); - - public static final GetMemberResDto CERTIFIED_SSAFY_MEMBER = new GetMemberResDto( - 1L, "user", "paul", true, true, CERTIFIED_SSAFY_INFO); - public static final GetMemberResDto UNCERTIFIED_SSAFY_MEMBER = new GetMemberResDto( - 1L, "user", "james", true, true, UNCERTIFIED_SSAFY_INFO); - - public static final Member MEMBER_WALTER = Member.builder() - .id(1L) - .role(memberRole) - .nickname("walter") - .build(); - - public static final Member MEMBER_SHERYL = Member.builder() - .id(2L) - .role(memberRole) - .nickname("sheryl") - .build(); - - public static final Member MEMBER_KIM = Member.builder() - .id(99L) - .semester(9) - .oauthIdentifier("oauth") - .nickname("KIM") - .accountState(AccountState.NORMAL) - .certificationState(AuthenticationStatus.CERTIFIED) - .campus(new MetaData(Campus.SEOUL)) - .oauthType(OAuthType.GITHUB) - .role(memberRole) - .majorTrack(new MetaData(MajorTrack.JAVA)) - .ssafyMember(true) - .certificationInquiryCount(1) - .certificationTryTime(LocalDateTime.now()) - .major(true) - .publicProfile(true) - .build(); - - public static final PatchMemberMajorReqDto PATCH_IS_MAJOR_REQUEST = PatchMemberMajorReqDto.builder() - .isMajor(false) - .build(); + private static final MemberRole memberRole = MemberRole.builder().id(1).roleType("user").build(); - public static Set memberLinks = new HashSet<>(){ + public static List skills = new ArrayList<>(){ { - add(MemberLink.builder().member(MEMBER_JAMES).linkName("velog").path("http://test-link1").build()); - add(MemberLink.builder().member(MEMBER_JAMES).linkName("t-story").path("http://test-link2").build()); + add("Java"); + add("Spring"); } }; - public static List putMemberLinks = new ArrayList<>(){ + public MemberProfile createMemberProfile() { + return MemberProfile.builder() + .introduce("자기소개 하겠습니다.") + .member(createMember()) + .build(); + } + + public Set memberLinks = new HashSet<>(){ { - add(PutMemberLink.builder().linkName("velog").path("http://test-link1").build()); - add(PutMemberLink.builder().linkName("t-story").path("http://test-link2").build()); + add(MemberLink.builder().member(createMember()).linkName("velog").path("http://test-link1").build()); + add(MemberLink.builder().member(createMember()).linkName("t-story").path("http://test-link2").build()); } }; - public static List skills = new ArrayList<>(){ + public Set memberSkills = new HashSet<>(){ { - add("Java"); - add("Spring"); + add(MemberSkill.builder().member(createMember()).skill(new MetaData(Skill.JAVA)).build()); + add(MemberSkill.builder().member(createMember()).skill(new MetaData(Skill.ANDROID)).build()); } }; - public static Set memberSkills = new HashSet<>(){ + public List putMemberLinks = new ArrayList<>(){ { - add(MemberSkill.builder().member(MEMBER_JAMES).skill(new MetaData(Skill.JAVA)).build()); - add(MemberSkill.builder().member(MEMBER_JAMES).skill(new MetaData(Skill.ANDROID)).build()); + add(PutMemberLink.builder().linkName("velog").path("http://test-link1").build()); + add(PutMemberLink.builder().linkName("t-story").path("http://test-link2").build()); } }; - public static final MemberProfile memberProfile = MemberProfile.builder() - .introduce("안녕하세요! 반가워요.") + public Member createInitializerMember() { + return Member.builder() + .id(1L) + .role(memberRole) + .oauthType(OAuthType.GOOGLE) + .oauthIdentifier("gimtaeyon@gmail.com") + .build(); + } + + public Member createGeneralMember() { + return Member.builder() + .id(1L) + .role(memberRole) + .oauthType(OAuthType.GITHUB) + .oauthIdentifier("1232312312312") + .nickname("james") + .ssafyMember(false) + .major(true) + .build(); + } + + public Member createCertifiedSSAFYMember() { + return Member.builder() + .id(1L) + .role(memberRole) + .oauthType(OAuthType.GITHUB) + .oauthIdentifier("1232312312312") + .nickname("james") + .ssafyMember(true) + .major(true) + .campus(new MetaData(Campus.SEOUL)) + .majorTrack(new MetaData(MajorTrack.JAVA)) + .semester(9) + .certificationState(AuthenticationStatus.CERTIFIED) + .build(); + } + + public Member createUncertifiedSSAFYMember() { + return Member.builder() + .id(1L) + .role(memberRole) + .oauthType(OAuthType.GITHUB) + .oauthIdentifier("1232312312312") + .nickname("james") + .ssafyMember(true) + .major(true) + .campus(new MetaData(Campus.SEOUL)) + .semester(9) + .certificationState(AuthenticationStatus.UNCERTIFIED) + .build(); + } + + public SSAFYInfo createUncertifiedSSAFYInfo() { + return SSAFYInfo.of(9, "서울", + "UNCERTIFIED", null); + } + + public SSAFYInfo createCertifiedSSAFYInfo() { + return SSAFYInfo.of(9, "서울", "CERTIFIED", new MetaData(MajorTrack.JAVA)); + } + + public GetMemberResDto createCertifiedSSAFYMemberResDto() { + return GetMemberResDto.fromSSAFYUser(createCertifiedSSAFYMember()); + } + + public GetMemberResDto createUncertifiedSSAFYMemberResDto() { + return GetMemberResDto.fromSSAFYUser(createUncertifiedSSAFYMember()); + } + + public PostMemberInfoReqDto createPostGeneralMemberInfoReqDto() { + return PostMemberInfoReqDto.builder() + .ssafyMember(false) + .nickname("james") + .isMajor(true) + .build(); + } + + public PostMemberInfoReqDto createPostSSAFYMemberInfoReqDto() { + return PostMemberInfoReqDto.builder() + .ssafyMember(true) + .nickname("james") + .isMajor(true) + .campus("서울") + .semester(9) + .build(); + } + + public Member createMember() { + return Member.builder() + .id(99L) + .semester(9) + .oauthIdentifier("oauth") + .nickname("KIM") + .accountState(AccountState.NORMAL) + .certificationState(AuthenticationStatus.CERTIFIED) + .campus(new MetaData(Campus.SEOUL)) + .oauthType(OAuthType.GITHUB) + .role(memberRole) + .majorTrack(new MetaData(MajorTrack.JAVA)) + .ssafyMember(true) + .certificationInquiryCount(1) + .certificationTryTime(LocalDateTime.now()) + .major(true) + .publicProfile(true) + .memberLinks(memberLinks) + .memberSkills(memberSkills) + .build(); + } + + public List createMemberList() { + List members = new ArrayList<>(); + members.add(Member.builder() + .id(99L) + .semester(9) + .oauthIdentifier("oauth") + .nickname("KIM") + .accountState(AccountState.NORMAL) + .certificationState(AuthenticationStatus.CERTIFIED) + .campus(new MetaData(Campus.SEOUL)) + .oauthType(OAuthType.GITHUB) + .role(memberRole) + .majorTrack(new MetaData(MajorTrack.JAVA)) + .ssafyMember(true) + .certificationInquiryCount(1) + .certificationTryTime(LocalDateTime.now()) + .major(true) + .publicProfile(true) + .build()); + + members.add(Member.builder() + .id(100L) + .semester(9) + .oauthIdentifier("oauth") + .nickname("TIM") + .accountState(AccountState.NORMAL) + .certificationState(AuthenticationStatus.CERTIFIED) + .campus(new MetaData(Campus.SEOUL)) + .oauthType(OAuthType.GITHUB) + .role(memberRole) + .majorTrack(new MetaData(MajorTrack.JAVA)) + .ssafyMember(true) + .certificationInquiryCount(1) + .certificationTryTime(LocalDateTime.now()) + .major(true) + .publicProfile(true) + .build()); + + return members; + } + + public GetMemberPortfolioResDto createGetMemberPortfolioResDto() { + return GetMemberPortfolioResDto.ofMemberProfile(createMember(), createMemberProfile()); + } + + public PutMemberPortfolioReqDto createPutMemberPortfolioReqDto() { + return PutMemberPortfolioReqDto + .builder() + .selfIntroduction("안녕하세요 자기소개합니다.") + .skills(skills) + .memberLinks(putMemberLinks) + .build(); + } + + public PatchMemberMajorReqDto createPatchMemberMajorReqDto() { + return PatchMemberMajorReqDto.builder() + .isMajor(false) + .build(); + } + + public PatchMemberMajorTrackReqDto createPatchMemberMajorTrackReqDto() { + return PatchMemberMajorTrackReqDto.builder() + .majorTrack("Embedded") + .build(); + } + + public PostCertificationInfoReqDto createPostCertificationInfoReqDto() { + return PostCertificationInfoReqDto.builder() + .majorTrack("Java") + .semester(9) + .answer("great") + .build(); + } + + public PostCertificationInfoResDto createPostCertificationInfoResDto() { + return PostCertificationInfoResDto.builder() + .possible(true) + .certificationInquiryCount(3) + .build(); + } + + public PostNicknameResDto createPostNicknameResDto() { + return PostNicknameResDto.builder() + .possible(true) + .build(); + } + + public PostNicknameReqDto createPostNicknameReqDto() { + return PostNicknameReqDto.builder() + .nickname("james") + .build(); + } + + public GetMemberPublicProfileResDto createGetMemberPublicProfileResDto() { + return GetMemberPublicProfileResDto.builder() + .isPublic(true) + .build(); + } + + public PatchMemberPublicProfileReqDto createPatchMemberPublicProfileReqDto() { + return new PatchMemberPublicProfileReqDto(false); + } + + public PatchMemberDefaultInfoReqDto createPatchMemberDefaultInfoReqDto() { + return new PatchMemberDefaultInfoReqDto(false, null, null); + } + + public PostMemberReqDto createPostMemberReqDto() { + return PostMemberReqDto.builder() + .oauthName("github") + .oauthIdentifier("1232312312312") + .build(); + } + + public CreateMemberTokensResDto createMemberTokensResDto() { + return CreateMemberTokensResDto.builder() + .accessToken(AuthFixture.accessToken) + .refreshToken(AuthFixture.refreshToken) .build(); + } - public static final Member MEMBER_JAMES = Member.builder() - .id(99L) - .semester(9) - .oauthIdentifier("oauth") - .nickname("james") - .accountState(AccountState.NORMAL) - .certificationState(AuthenticationStatus.CERTIFIED) - .campus(new MetaData(Campus.SEOUL)) - .oauthType(OAuthType.GITHUB) - .role(memberRole) - .majorTrack(new MetaData(MajorTrack.JAVA)) - .ssafyMember(true) - .certificationInquiryCount(1) - .certificationTryTime(LocalDateTime.now()) - .major(true) - .publicProfile(true) - .memberLinks(memberLinks) - .memberSkills(memberSkills) - .build(); + public MemberToken createMemberToken() { + return MemberToken.builder() + .member(createGeneralMember()) + .accessToken(AuthFixture.accessToken) + .refreshToken(AuthFixture.refreshToken) + .build(); + } - public static final GetMemberPortfolioResDto MY_PORTFOLIO = GetMemberPortfolioResDto - .builder() - .portfolioElement(PortfolioElement.of(MEMBER_JAMES, memberProfile)) - .build(); - - public static final GetMemberDefaultInfoResDto GET_MEMBER_DEFAULT_INFO = GetMemberDefaultInfoResDto - .builder() - .nickname(MEMBER_JAMES.getNickname()) - .ssafyMember(MEMBER_JAMES.getSsafyMember()) - .isMajor(MEMBER_JAMES.getMajor()) - .ssafyInfo(CERTIFIED_SSAFY_INFO) - .build(); - - public static final PatchMemberDefaultInfoReqDto PATCH_MEMBER_DEFAULT_INFO_REQUEST = new PatchMemberDefaultInfoReqDto(false, null, null); - - public static final PatchMemberPublicProfileReqDto PATCH_MEMBER_PUBLIC_PROFILE_REQUEST = new PatchMemberPublicProfileReqDto(false); - - public static final GetMemberPublicProfileResDto GET_MEMBER_PUBLIC_PROFILE = GetMemberPublicProfileResDto - .builder() - .isPublic(true) - .build(); + public PatchMemberNicknameReqDto createPatchMemberNicknameReqDto() { + return new PatchMemberNicknameReqDto("james"); + } - public static final PostNicknameReqDto POST_NICKNAME_REQUEST = PostNicknameReqDto - .builder() - .nickname("james") - .build(); - - public static final PostNicknameResDto POST_NICKNAME_RESPONSE = PostNicknameResDto - .builder() - .possible(true) - .build(); - - public static final PostCertificationInfoResDto POST_CERTIFICATION_INFO_RESPONSE = PostCertificationInfoResDto - .builder() - .possible(true) - .certificationInquiryCount(3) - .build(); - - public static final PostCertificationInfoReqDto POST_CERTIFICATION_INFO_REQUEST = PostCertificationInfoReqDto - .builder() - .majorTrack("Java") - .semester(9) - .answer("great") - .build(); - - public static final PutMemberPortfolioReqDto PUT_MEMBER_PORTFOLIO_REQUEST = PutMemberPortfolioReqDto - .builder() - .selfIntroduction("안녕하세요 자기소개합니다.") - .skills(skills) - .memberLinks(putMemberLinks) - .build(); - - public static final Member MEMBER_TIM = Member.builder() - .id(100L) - .semester(9) - .oauthIdentifier("oauth") - .nickname("TIM") - .accountState(AccountState.NORMAL) - .certificationState(AuthenticationStatus.CERTIFIED) - .campus(new MetaData(Campus.SEOUL)) - .oauthType(OAuthType.GITHUB) + public static final Member MEMBER_WALTER = Member.builder() + .id(1L) .role(memberRole) - .majorTrack(new MetaData(MajorTrack.JAVA)) - .ssafyMember(true) - .certificationInquiryCount(1) - .certificationTryTime(LocalDateTime.now()) - .major(true) - .publicProfile(true) + .nickname("walter") .build(); - public static final Member MEMBER_YONG = Member.builder() - .id(3L) - .semester(9) - .nickname("yong") - .certificationState(AuthenticationStatus.CERTIFIED) + public static final Member MEMBER_SHERYL = Member.builder() + .id(2L) .role(memberRole) - .campus(new MetaData(Campus.SEOUL)) - .majorTrack(new MetaData(MajorTrack.JAVA)) - .ssafyMember(true) - .major(true) - .build(); - - public static final PatchMemberMajorTrackReqDto PATCH_MEMBER_MAJOR_TRACK = PatchMemberMajorTrackReqDto.builder() - .majorTrack("Embedded") + .nickname("sheryl") .build(); } diff --git a/src/test/java/com/ssafy/ssafsound/global/util/fixture/PostFixture.java b/src/test/java/com/ssafy/ssafsound/global/util/fixture/PostFixture.java index e571500af..fbd22e888 100644 --- a/src/test/java/com/ssafy/ssafsound/global/util/fixture/PostFixture.java +++ b/src/test/java/com/ssafy/ssafsound/global/util/fixture/PostFixture.java @@ -12,13 +12,15 @@ public class PostFixture { + private static final MemberFixture memberFixture = new MemberFixture(); + public static final Post POST_FIXTURE1 = Post.builder() .id(1L) .title("싸탈하고 싶다.") .content("싸탈하고 싶은 밤이네요") .anonymity(false) .board(BOARD_FIXTURE1) - .member(MEMBER_KIM) + .member(memberFixture.createMember()) .build(); public static final Post POST_FIXTURE2 = Post.builder() @@ -27,7 +29,7 @@ public class PostFixture { .content("결과가 암울해") .anonymity(true) .board(BOARD_FIXTURE1) - .member(MEMBER_YONG) + .member(memberFixture.createMember()) .build(); public static final Post POST_FIXTURE3 = Post.builder() @@ -36,7 +38,7 @@ public class PostFixture { .content("취업이 뭐죠??") .anonymity(true) .board(BOARD_FIXTURE2) - .member(MEMBER_YONG) + .member(memberFixture.createMember()) .build(); public static final GetPostElement GET_POST_ELEMENT1 = GetPostElement.builder() @@ -183,7 +185,7 @@ public class PostFixture { POST_FIXTURE1, null); public static final GetPostDetailResDto GET_POST_DETAIL_RES_DTO2 = GetPostDetailResDto.of( - POST_FIXTURE2, MEMBER_YONG); + POST_FIXTURE2, memberFixture.createMember()); public static final PostPostWriteReqDto POST_POST_WRITE_REQ_DTO1 = PostPostWriteReqDto.builder() .title("안녕하세요 첫 글이네요") diff --git a/src/test/java/com/ssafy/ssafsound/global/util/fixture/RecruitApplicationFixture.java b/src/test/java/com/ssafy/ssafsound/global/util/fixture/RecruitApplicationFixture.java index 83551e83e..838d0627b 100644 --- a/src/test/java/com/ssafy/ssafsound/global/util/fixture/RecruitApplicationFixture.java +++ b/src/test/java/com/ssafy/ssafsound/global/util/fixture/RecruitApplicationFixture.java @@ -16,17 +16,21 @@ import java.util.List; public class RecruitApplicationFixture { + + private static final MemberFixture memberFixture = new MemberFixture(); + public static final PostRecruitApplicationReqDto POST_RECRUIT_APPLICATION_REQ_DTO = new PostRecruitApplicationReqDto(RecruitType.FRONT_END.getName(), List.of("취업 준비를 위해서 신청하게되었습니다.")); public static final PostRecruitApplicationLikeResDto POST_RECRUIT_APPLICATION_LIKE_RES_DTO = new PostRecruitApplicationLikeResDto(true); + public static final RecruitApplication getRecruitApplication1_ByMatchStatus(MatchStatus matchStatus, MetaData recruitType, Boolean isLike) { RecruitApplication recruitApplication = RecruitApplication.builder() .id(1L) .matchStatus(matchStatus) .recruit(RecruitFixture.RECRUIT_1) .type(recruitType) - .member(MemberFixture.MEMBER_TIM) + .member(memberFixture.createMember()) .isLike(isLike) .build(); @@ -40,7 +44,7 @@ public static final RecruitApplication getRecruitApplication1_ByMatchStatus(Matc .recruitApplicationId(1L) .recruitType(RecruitType.FRONT_END.getName()) .matchStatus(MatchStatus.PENDING) - .author(new AuthorElement(MemberFixture.MEMBER_TIM, false)) + .author(new AuthorElement(memberFixture.createMember(), false)) .question(RecruitFixture.RECRUIT_1.getQuestions().get(0).getContent()) .reply("취업 준비를 위해서 신청하게되었습니다.") .liked(false) diff --git a/src/test/java/com/ssafy/ssafsound/global/util/fixture/RecruitCommentFixture.java b/src/test/java/com/ssafy/ssafsound/global/util/fixture/RecruitCommentFixture.java index ad2fcac76..8d0c53c4c 100644 --- a/src/test/java/com/ssafy/ssafsound/global/util/fixture/RecruitCommentFixture.java +++ b/src/test/java/com/ssafy/ssafsound/global/util/fixture/RecruitCommentFixture.java @@ -18,10 +18,13 @@ public class RecruitCommentFixture { private static final Long DEFAULT_COMMENT_GROUP = -1L; + private static final MemberFixture memberFixture = new MemberFixture(); + public static final PostRecruitCommentReqDto POST_RECRUIT_COMMENT_REQ_DTO = new PostRecruitCommentReqDto("공모전 수상이 목표인가요?", DEFAULT_COMMENT_GROUP); public static final PostRecruitCommentResDto POST_RECRUIT_COMMENT_RES_DTO - = new PostRecruitCommentResDto(1L, "공모전 수상이 목표인가요?", MemberFixture.MEMBER_TIM.getId(), MemberFixture.MEMBER_TIM.getNickname(), 1L); + = new PostRecruitCommentResDto(1L, "공모전 수상이 목표인가요?", + memberFixture.createMember().getId(), memberFixture.createMember().getNickname(), 1L); public static final PatchRecruitCommentReqDto PATCH_RECRUIT_COMMENT_REQ_DTO = new PatchRecruitCommentReqDto("덧글 수정"); @@ -30,7 +33,7 @@ public class RecruitCommentFixture { .content("공모전 수상이 목표인가요?") .deletedComment(false) .recruit(RecruitFixture.RECRUIT_1) - .member(MemberFixture.MEMBER_TIM) + .member(memberFixture.createMember()) .build(); public static final PostRecruitCommentLikeResDto POST_RECRUIT_COMMENT_LIKE_RES_DTO = new PostRecruitCommentLikeResDto(1, true); diff --git a/src/test/java/com/ssafy/ssafsound/global/util/fixture/RecruitFixture.java b/src/test/java/com/ssafy/ssafsound/global/util/fixture/RecruitFixture.java index 3960c00bd..e3cef28fd 100644 --- a/src/test/java/com/ssafy/ssafsound/global/util/fixture/RecruitFixture.java +++ b/src/test/java/com/ssafy/ssafsound/global/util/fixture/RecruitFixture.java @@ -18,6 +18,7 @@ public class RecruitFixture { + private static final MemberFixture memberFixture = new MemberFixture(); private static String CONTACT_URI = "https://open.kakao.com/o/sA8Kb83b"; private static String RECRUIT_TITLE = "[사이드 프로젝트] 공모전 레퍼런스 웹 플랫폼 개발 프로젝트 팀원을 모집합니다."; private static String RECRUIT_CONTENT = "

[프로젝트 소개]

\n" + @@ -53,7 +54,7 @@ public class RecruitFixture { .finishedRecruit(false) .registerRecruitType(new MetaData(RecruitType.BACK_END)) .contactURI(CONTACT_URI) - .member(MemberFixture.MEMBER_KIM) + .member(memberFixture.createMember()) .build(); static { @@ -116,7 +117,7 @@ public class RecruitFixture { .skills(RECRUIT_1_SKILL_DTO) .limits(RECRUIT_1_LIMIT_DETAIL) .questions(List.of(RECRUIT_QUESTION)) - .author(new AuthorElement(MemberFixture.MEMBER_KIM, false)) + .author(new AuthorElement(memberFixture.createMember(), false)) .scrapCount(1L) .scraped(true) .matchStatus(MatchStatus.INITIAL.name())