Skip to content

Commit

Permalink
[Weekly/10/Test/Refactor-MemberId] test 관련 member 도메인의 아이디 상수화 이외 1개 (#…
Browse files Browse the repository at this point in the history
…86)

* refactor: test 관련 memberId 상수화

* chore: 이제는 github action시 테스트도 수행함
  • Loading branch information
lja3723 authored Nov 8, 2024
1 parent 3db4d86 commit 34b4ca9
Show file tree
Hide file tree
Showing 17 changed files with 314 additions and 273 deletions.
7 changes: 6 additions & 1 deletion .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ jobs:
restore-keys: |
${{ runner.os }}-gradle-
- name: Build With Gradle (exclude test)
- name: Build Application only using gradlew
run: |
chmod +x gradlew
./gradlew clean build -x test
- name: Test Application using gradlew
run: |
chmod +x gradlew
./gradlew test
- name: Docker Hub Login
if: github.event_name == 'push'
uses: docker/login-action@v3
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ktc2.cokaen.wouldyouin.global;
package org.ktc2.cokaen.wouldyouin._global;

import java.time.LocalDateTime;
import java.util.List;
Expand Down Expand Up @@ -66,13 +66,13 @@ public static CurationImage createValidCurationImage(Long id) {

public static class MemberDomain {

public static final Long memberId = 1L;
public static final Long curatorId = 5L;
public static final Long hostId = 3L;
public static final Long welcomeMemberId = 4L;
public static final long validMemberId = 1L;
public static final long validCuratorId = 2L;
public static final long validHostId = 3L;
public static final long validWelcomeMemberId = 4L;

public static Member createValidMember() {
MemberImage memberImage = ImageDomain.createValidMemberImage(1L);
MemberImage memberImage = ImageDomain.createValidMemberImage(validMemberId);
Member ret = Member.builder()
.accountType(AccountType.kakao)
.email("[email protected]")
Expand All @@ -83,75 +83,63 @@ public static Member createValidMember() {
.gender("Men")
.socialId("100100100100100")
.build();
ReflectionTestUtils.setField(ret, "Id", 1L);
ReflectionTestUtils.setField(ret, "Id", validMemberId);
ReflectionTestUtils.setField(ret, "memberType", MemberType.normal);
ReflectionTestUtils.setField(memberImage, "baseMember", ret);
return ret;
}

public static Member createValidWelcomeMember() {
MemberImage memberImage = ImageDomain.createValidMemberImage(4L);
Member ret = Member.builder()
.accountType(AccountType.kakao)
.email("member2@example.com")
.nickname("nick_normal_333")
.phone("010-4414-1144")
public static Curator createValidCurator() {
MemberImage memberImage = ImageDomain.createValidMemberImage(validCuratorId);
Curator ret = Curator.curatorBuilder()
.accountType(AccountType.google)
.email("curator1@example.com")
.nickname("nick_curator_12")
.phone("010-4545-6767")
.profileImage(memberImage)
.area(Area.서울)
.gender("Men")
.socialId("456456456456")
.area(Area.광주)
.gender("Women")
.socialId("200200200200200")
.build();
ReflectionTestUtils.setField(ret, "Id", 4L);
ReflectionTestUtils.setField(ret, "Id", validCuratorId);
ReflectionTestUtils.setField(ret, "intro", "큐레이터 자기소개입니다.");
ReflectionTestUtils.setField(ret, "hashtag", "#큐레이터#해시태그#입니다");
ReflectionTestUtils.setField(memberImage, "baseMember", ret);
return ret;
}

public static Host createValidHost() {
MemberImage memberImage = ImageDomain.createValidMemberImage(3L);
MemberImage memberImage = ImageDomain.createValidMemberImage(validHostId);
Host ret = Host.builder()
.email("[email protected]")
.nickname("nick_curator_12")
.phone("010-4545-6767")
.hashedPassword("hashed_password")
.profileImage(memberImage)
.build();
ReflectionTestUtils.setField(ret, "Id", 3L);
ReflectionTestUtils.setField(ret, "Id", validHostId);
ReflectionTestUtils.setField(ret, "intro", "주최자 자기소개입니다.");
ReflectionTestUtils.setField(ret, "hashtag", "#주최자#해시태그#입니다");
ReflectionTestUtils.setField(memberImage, "baseMember", ret);
return ret;
}

public static Curator createValidCurator() {
MemberImage memberImage = ImageDomain.createValidMemberImage(2L);
Curator ret = Curator.curatorBuilder()
.accountType(AccountType.google)
.email("curator1@example.com")
.nickname("nick_curator_12")
.phone("010-4545-6767")
public static Member createValidWelcomeMember() {
MemberImage memberImage = ImageDomain.createValidMemberImage(validWelcomeMemberId);
Member ret = Member.builder()
.accountType(AccountType.kakao)
.email("member2@example.com")
.nickname("nick_normal_333")
.phone("010-4414-1144")
.profileImage(memberImage)
.area(Area.광주)
.gender("Women")
.socialId("200200200200200")
.area(Area.서울)
.gender("Men")
.socialId("456456456456")
.build();
ReflectionTestUtils.setField(ret, "Id", 2L);
ReflectionTestUtils.setField(ret, "intro", "큐레이터 자기소개입니다.");
ReflectionTestUtils.setField(ret, "hashtag", "#큐레이터#해시태그#입니다");
ReflectionTestUtils.setField(ret, "Id", validWelcomeMemberId);
ReflectionTestUtils.setField(memberImage, "baseMember", ret);
return ret;
}

public static CurationCuratorResponse createCurationCuratorResponse() {
return CurationCuratorResponse.builder()
.nickname("nick_curator_12")
.email("[email protected]")
.phone("010-4545-6767")
.profileImageUrl("image2.com")
.intro("큐레이터 자기소개입니다.")
.likes(0)
.hashtags(List.of("#큐레이터", "#해시태그", "#입니다"))
.build();
}
}

public static class EventDomain {
Expand Down Expand Up @@ -302,9 +290,22 @@ public static CurationEditRequest createValidCurationEditRequest() {
.build();
}

public static CurationCuratorResponse createCurationCuratorResponse() {
Curator curator = MemberDomain.createValidCurator();
return CurationCuratorResponse.builder()
.nickname(curator.getNickname())
.email(curator.getEmail())
.phone(curator.getPhone())
.profileImageUrl(curator.getProfileImageUrl())
.intro(curator.getIntro())
.likes(curator.getLikes())
.hashtags(curator.getHashTagList())
.build();
}

public static CurationResponse createValidCurationResponse() {
return CurationResponse.builder()
.curator(MemberDomain.createCurationCuratorResponse())
.curator(createCurationCuratorResponse())
.title("title")
.content("content")
.curationCards(List.of(createCurationCardResponse1()))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ktc2.cokaen.wouldyouin.global;
package org.ktc2.cokaen.wouldyouin._global;

public class TestUtil {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.ktc2.cokaen.wouldyouin.global.mockMember;
package org.ktc2.cokaen.wouldyouin._global.mockMember;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.ktc2.cokaen.wouldyouin.global.TestData;
import org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain;
import org.ktc2.cokaen.wouldyouin.member.persist.MemberType;

@Retention(RetentionPolicy.RUNTIME)
@WithMockCustomUser(memberId = 5L, memberType = MemberType.curator)
@WithMockCustomUser(memberId = MemberDomain.validCuratorId, memberType = MemberType.curator)
public @interface WithMockCurator {

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ktc2.cokaen.wouldyouin.global.mockMember;
package org.ktc2.cokaen.wouldyouin._global.mockMember;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
Expand All @@ -8,6 +8,6 @@
@Retention(RetentionPolicy.RUNTIME)
@WithSecurityContext(factory = WithMockCustomUserSecurityContextFactory.class)
public @interface WithMockCustomUser {
long memberId() default 1L;
long memberId();
MemberType memberType();
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.ktc2.cokaen.wouldyouin.global.mockMember;
package org.ktc2.cokaen.wouldyouin._global.mockMember;

import org.ktc2.cokaen.wouldyouin.auth.MemberIdentifier;
import org.ktc2.cokaen.wouldyouin.auth.persist.CustomUserDetails;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.ktc2.cokaen.wouldyouin.global.mockMember;
package org.ktc2.cokaen.wouldyouin._global.mockMember;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.ktc2.cokaen.wouldyouin.global.TestData;
import org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain;
import org.ktc2.cokaen.wouldyouin.member.persist.MemberType;

@Retention(RetentionPolicy.RUNTIME)
@WithMockCustomUser(memberId = 3L, memberType = MemberType.host)
@WithMockCustomUser(memberId = MemberDomain.validHostId, memberType = MemberType.host)
public @interface WithMockHost {

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.ktc2.cokaen.wouldyouin.global.mockMember;
package org.ktc2.cokaen.wouldyouin._global.mockMember;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.ktc2.cokaen.wouldyouin.global.TestData;
import org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain;
import org.ktc2.cokaen.wouldyouin.member.persist.MemberType;

@Retention(RetentionPolicy.RUNTIME)
@WithMockCustomUser(memberId = 1L, memberType = MemberType.normal)
@WithMockCustomUser(memberId = MemberDomain.validMemberId, memberType = MemberType.normal)
public @interface WithMockMember {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.ktc2.cokaen.wouldyouin._global.mockMember;

import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain;
import org.ktc2.cokaen.wouldyouin.member.persist.MemberType;

@Retention(RetentionPolicy.RUNTIME)
@WithMockCustomUser(memberId = MemberDomain.validWelcomeMemberId, memberType = MemberType.welcome)
public @interface WithMockWelcomeMember {

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@
import org.ktc2.cokaen.wouldyouin.curation.api.CurationController;
import org.ktc2.cokaen.wouldyouin.curation.api.dto.CurationCreateRequest;
import org.ktc2.cokaen.wouldyouin.curation.application.CurationService;
import org.ktc2.cokaen.wouldyouin.global.TestData.CurationDomain;
import org.ktc2.cokaen.wouldyouin.global.TestData.MemberDomain;
import org.ktc2.cokaen.wouldyouin.global.mockMember.WithMockCurator;
import org.ktc2.cokaen.wouldyouin.global.mockMember.WithMockHost;
import org.ktc2.cokaen.wouldyouin.global.mockMember.WithMockMember;
import org.ktc2.cokaen.wouldyouin._global.TestData.CurationDomain;
import org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain;
import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockCurator;
import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost;
import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockMember;
import org.mockito.ArgumentCaptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
Expand Down Expand Up @@ -159,7 +159,7 @@ void createCuration1() throws Exception {
.andExpect(status().isCreated());

// then
then(curationService).should(times(1)).create(eq(MemberDomain.curatorId), captor.capture());
then(curationService).should(times(1)).create(eq(MemberDomain.validCuratorId), captor.capture());
assertThat(captor.getValue()).isEqualTo(request);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.ktc2.cokaen.wouldyouin.event;


import static org.ktc2.cokaen.wouldyouin.global.TestData.MemberDomain.createValidHost;
import static org.ktc2.cokaen.wouldyouin._global.TestData.MemberDomain.createValidHost;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
Expand Down Expand Up @@ -34,8 +34,8 @@
import org.ktc2.cokaen.wouldyouin.event.api.dto.EventEditRequest;
import org.ktc2.cokaen.wouldyouin.event.api.dto.EventSliceResponse;
import org.ktc2.cokaen.wouldyouin.event.application.EventService;
import org.ktc2.cokaen.wouldyouin.global.TestData.EventDomain;
import org.ktc2.cokaen.wouldyouin.global.mockMember.WithMockHost;
import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain;
import org.ktc2.cokaen.wouldyouin._global.mockMember.WithMockHost;
import org.ktc2.cokaen.wouldyouin.member.application.MemberService;
import org.ktc2.cokaen.wouldyouin.member.persist.Host;
import org.springframework.beans.factory.annotation.Autowired;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.ktc2.cokaen.wouldyouin.event.application.EventService;
import org.ktc2.cokaen.wouldyouin.event.persist.Event;
import org.ktc2.cokaen.wouldyouin.event.persist.EventRepository;
import org.ktc2.cokaen.wouldyouin.global.TestData.EventDomain;
import org.ktc2.cokaen.wouldyouin._global.TestData.EventDomain;
import org.ktc2.cokaen.wouldyouin.member.application.HostService;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,31 @@

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.ktc2.cokaen.wouldyouin.auth.application.CustomUserDetailsService;
import org.ktc2.cokaen.wouldyouin.auth.application.JwtService;
import org.ktc2.cokaen.wouldyouin.member.application.BaseMemberService;
import org.ktc2.cokaen.wouldyouin.member.application.HostService;
import org.ktc2.cokaen.wouldyouin.member.application.MemberService;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;

@WebMvcTest(MemberController.class)
class MemberControllerUnitTest {

@MockBean
private CustomUserDetailsService customUserDetailsService;

@MockBean
private JwtService jwtService;

@MockBean
private BaseMemberService baseMemberService;

@MockBean
private MemberService memberService;

@MockBean
private HostService hostService;

@BeforeEach
void setUp() {
Expand Down
Loading

0 comments on commit 34b4ca9

Please sign in to comment.