From bf8c0acb6da26976e02eb400619c74e1f80fea94 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Mon, 8 Jan 2024 21:51:29 +0900 Subject: [PATCH 01/24] =?UTF-8?q?RAC-254=20feat:=20=ED=85=8C=EC=8A=A4?= =?UTF-8?q?=ED=8A=B8=20=EC=9D=98=EC=A1=B4=EC=84=B1=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 78 +++++++++++++++++++++++++++------------------------- 1 file changed, 40 insertions(+), 38 deletions(-) diff --git a/build.gradle b/build.gradle index 41f022be..83ee3c7d 100644 --- a/build.gradle +++ b/build.gradle @@ -1,65 +1,67 @@ plugins { - id 'java' - id 'org.springframework.boot' version '3.1.4' - id 'io.spring.dependency-management' version '1.1.3' + id 'java' + id 'org.springframework.boot' version '3.1.4' + id 'io.spring.dependency-management' version '1.1.3' } group = 'com' version = '0.0.1-SNAPSHOT' java { - sourceCompatibility = '17' + sourceCompatibility = '17' } configurations { - compileOnly { - extendsFrom annotationProcessor - } + compileOnly { + extendsFrom annotationProcessor + } } repositories { - mavenCentral() + mavenCentral() } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-amqp' - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' - implementation 'org.springframework.boot:spring-boot-starter-data-redis' - implementation 'org.springframework.boot:spring-boot-starter-security' - implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springframework.boot:spring-boot-starter-webflux' - implementation 'org.springframework.boot:spring-boot-starter-validation' - compileOnly 'org.projectlombok:lombok' - runtimeOnly 'com.mysql:mysql-connector-j' - annotationProcessor 'org.projectlombok:lombok' - testImplementation 'org.springframework.boot:spring-boot-starter-test' - testImplementation 'io.projectreactor:reactor-test' - testImplementation 'org.springframework.amqp:spring-rabbit-test' - testImplementation 'org.springframework.security:spring-security-test' + implementation 'org.springframework.boot:spring-boot-starter-amqp' + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + implementation 'org.springframework.boot:spring-boot-starter-data-redis' + implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'org.springframework.boot:spring-boot-starter-web' + implementation 'org.springframework.boot:spring-boot-starter-webflux' + implementation 'org.springframework.boot:spring-boot-starter-validation' + compileOnly 'org.projectlombok:lombok' + runtimeOnly 'com.mysql:mysql-connector-j' + annotationProcessor 'org.projectlombok:lombok' + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'io.projectreactor:reactor-test' + testImplementation 'org.springframework.amqp:spring-rabbit-test' + testImplementation 'org.springframework.security:spring-security-test' + testCompileOnly 'org.springframework.security:spring-security-test' + testAnnotationProcessor 'org.springframework.security:spring-security-test' - implementation 'io.jsonwebtoken:jjwt-api:0.11.5' - implementation 'io.jsonwebtoken:jjwt-impl:0.11.5' - implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5' - //jwt 추가 + implementation 'io.jsonwebtoken:jjwt-api:0.11.5' + implementation 'io.jsonwebtoken:jjwt-impl:0.11.5' + implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5' + //jwt 추가 - // https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webmvc-ui - implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0' - //swagger 추가 + // https://mvnrepository.com/artifact/org.springdoc/springdoc-openapi-starter-webmvc-ui + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0' + //swagger 추가 - // Spring boot 3.x이상에서 QueryDsl 패키지를 정의하는 방법 - implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' - annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta" - annotationProcessor "jakarta.annotation:jakarta.annotation-api" - annotationProcessor "jakarta.persistence:jakarta.persistence-api" + // Spring boot 3.x이상에서 QueryDsl 패키지를 정의하는 방법 + implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta' + annotationProcessor "com.querydsl:querydsl-apt:5.0.0:jakarta" + annotationProcessor "jakarta.annotation:jakarta.annotation-api" + annotationProcessor "jakarta.persistence:jakarta.persistence-api" - // aws s3 - implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' + // aws s3 + implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE' // https://mvnrepository.com/artifact/org.mockito/mockito-core - testImplementation 'org.mockito:mockito-core:5.6.0' + testImplementation 'org.mockito:mockito-core:5.6.0' } tasks.named('test') { - useJUnitPlatform() + useJUnitPlatform() } \ No newline at end of file From 4e029754de97a20251f7a2eb9d06f3cea6b89656 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Tue, 9 Jan 2024 14:07:59 +0900 Subject: [PATCH 02/24] =?UTF-8?q?RAC-254=20feat:=20=EB=8C=80=ED=95=99?= =?UTF-8?q?=EC=83=9D=20=EB=A9=98=ED=86=A0=EB=A7=81=20=EC=A1=B0=ED=9A=8C=20?= =?UTF-8?q?=EC=83=81=ED=83=9C=EB=B3=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/postgraduate/IntegrationTest.java | 36 ++++++ .../presentation/MentoringControllerTest.java | 111 ++++++++++++++++++ 2 files changed, 147 insertions(+) create mode 100644 src/test/java/com/postgraduate/IntegrationTest.java create mode 100644 src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java diff --git a/src/test/java/com/postgraduate/IntegrationTest.java b/src/test/java/com/postgraduate/IntegrationTest.java new file mode 100644 index 00000000..54c376af --- /dev/null +++ b/src/test/java/com/postgraduate/IntegrationTest.java @@ -0,0 +1,36 @@ +package com.postgraduate; + +import org.junit.jupiter.api.BeforeEach; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.http.MediaType; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.setup.MockMvcBuilders; +import org.springframework.transaction.annotation.Transactional; +import org.springframework.web.context.WebApplicationContext; + +import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +@SpringBootTest +@AutoConfigureMockMvc +@Transactional +public class IntegrationTest { + + @Autowired + protected MockMvc mvc; + @Autowired + private WebApplicationContext ctx; + + @BeforeEach + void setUp() { + mvc = MockMvcBuilders + .webAppContextSetup(ctx) + .apply(springSecurity()) + .alwaysExpect(status().isOk()) + .alwaysExpect(content().contentType(MediaType.APPLICATION_JSON)) + .build(); + } +} diff --git a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java new file mode 100644 index 00000000..5c5a06f4 --- /dev/null +++ b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java @@ -0,0 +1,111 @@ +package com.postgraduate.domain.mentoring.presentation; + +import com.postgraduate.IntegrationTest; +import com.postgraduate.domain.mentoring.domain.entity.Mentoring; +import com.postgraduate.domain.mentoring.domain.entity.constant.Status; +import com.postgraduate.domain.mentoring.domain.repository.MentoringRepository; +import com.postgraduate.domain.senior.domain.entity.Info; +import com.postgraduate.domain.senior.domain.entity.Profile; +import com.postgraduate.domain.senior.domain.entity.Senior; +import com.postgraduate.domain.senior.domain.repository.SeniorRepository; +import com.postgraduate.domain.user.domain.entity.User; +import com.postgraduate.domain.user.domain.entity.constant.Role; +import com.postgraduate.domain.user.domain.repository.UserRepository; +import com.postgraduate.global.config.security.jwt.util.JwtUtils; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.security.test.context.support.WithMockUser; + +import static com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING; +import static java.time.LocalDateTime.now; +import static org.hamcrest.Matchers.containsString; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +class MentoringControllerTest extends IntegrationTest { + + @Autowired + private JwtUtils jwtUtil; + @Autowired + private UserRepository userRepository; + @Autowired + private SeniorRepository seniorRepository; + @Autowired + private MentoringRepository mentoringRepository; + private User user; + private Senior senior; + private Long userId; + private String accessToken; + + @BeforeEach + void setUp() { + user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.USER, true, now(), now(), false); + userRepository.save(user); + userId = user.getUserId(); + + User userOfSenior = new User(0L, 2L, "mail", "선배", "012", "profile", 0, Role.SENIOR, true, now(), now(), false); + userRepository.save(userOfSenior); + + Info info = new Info("major", "서울대학교", "교수님", "키워드1,키워드2", "랩실", "인공지능", false, false, "인공지능,키워드1,키워드2"); + Profile profile = new Profile("저는요", "한줄소개", "대상", "chatLink", 40); + senior = new Senior(0L, userOfSenior, "certification", WAITING, 0, info, profile, now(), now()); + seniorRepository.save(senior); + + accessToken = jwtUtil.generateAccessToken(userId, Role.USER); + } + + @Test + @DisplayName("대학생이 신청한 멘토링 목록을 조회한다") + @WithMockUser + void getWaitingMentorings() throws Exception { + Mentoring waitingMentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, Status.WAITING, now(), now()); + mentoringRepository.save(waitingMentoring); + + mvc.perform(get("/mentoring/me/waiting") + .header("Authorization", "Bearer " + accessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("MT200")) + .andExpect(jsonPath("$.message").value("멘토링 리스트 조회에 성공하였습니다.")) + .andExpect(jsonPath("$.data.mentoringInfos[0].profile").value(containsString("profile"))) + .andExpect(jsonPath("$.data.mentoringInfos[0].nickName").value(containsString("선배"))) + .andExpect(jsonPath("$.data.mentoringInfos[0].postgradu").value(containsString("서울대학교"))) + .andExpect(jsonPath("$.data.mentoringInfos[0].major").value(containsString("major"))) + .andExpect(jsonPath("$.data.mentoringInfos[0].lab").value(containsString("랩실"))) + .andExpect(jsonPath("$.data.mentoringInfos[0].term").value(40)) + .andExpect(jsonPath("$.data.mentoringInfos[0].chatLink").doesNotExist()); + } + + @Test + @DisplayName("대학생이 예정된 멘토링 목록을 조회한다") + @WithMockUser + void getExpectedMentorings() throws Exception { + Mentoring expectedMentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); + mentoringRepository.save(expectedMentoring); + + mvc.perform(get("/mentoring/me/expected") + .header("Authorization", "Bearer " + accessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("MT200")) + .andExpect(jsonPath("$.message").value("멘토링 리스트 조회에 성공하였습니다.")) + .andExpect(jsonPath("$.data.mentoringInfos[0].chatLink").value("chatLink")) + .andExpect(jsonPath("$.data.mentoringInfos[0].date").value("date")); + } + + @Test + @DisplayName("대학생이 완료된 멘토링 목록을 조회한다") + @WithMockUser + void getDoneMentorings() throws Exception { + Mentoring doneMentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, Status.DONE, now(), now()); + mentoringRepository.save(doneMentoring); + + mvc.perform(get("/mentoring/me/done") + .header("Authorization", "Bearer " + accessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("MT200")) + .andExpect(jsonPath("$.message").value("멘토링 리스트 조회에 성공하였습니다.")) + .andExpect(jsonPath("$.data.mentoringInfos[0].chatLink").doesNotExist()); + } +} \ No newline at end of file From b9ef6e1c8cd50d83a7109dbc32fe731bface0a01 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Tue, 9 Jan 2024 17:54:45 +0900 Subject: [PATCH 03/24] =?UTF-8?q?RAC-254=20test:=20=EB=8C=80=ED=95=99?= =?UTF-8?q?=EC=83=9D=20=EB=A9=98=ED=86=A0=EB=A7=81=20=EC=83=81=EC=84=B8?= =?UTF-8?q?=EC=A1=B0=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/MentoringControllerTest.java | 84 ++++++++++++------- 1 file changed, 54 insertions(+), 30 deletions(-) diff --git a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java index 5c5a06f4..cd23cbbc 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java @@ -15,17 +15,21 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.MethodSource; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.security.test.context.support.WithMockUser; + +import java.util.stream.Stream; import static com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING; import static java.time.LocalDateTime.now; -import static org.hamcrest.Matchers.containsString; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; class MentoringControllerTest extends IntegrationTest { + private static final String AUTHORIZATION = "Authorization"; + private static final String BEARER = "Bearer "; @Autowired private JwtUtils jwtUtil; @@ -37,14 +41,20 @@ class MentoringControllerTest extends IntegrationTest { private MentoringRepository mentoringRepository; private User user; private Senior senior; - private Long userId; private String accessToken; + private static Stream statusProvider() { + return Stream.of(Status.DONE, Status.CANCEL, Status.REFUSE); + } + + private static Stream waitingAndDoneProvider() { + return Stream.of(Status.DONE, Status.WAITING); + } + @BeforeEach void setUp() { user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.USER, true, now(), now(), false); userRepository.save(user); - userId = user.getUserId(); User userOfSenior = new User(0L, 2L, "mail", "선배", "012", "profile", 0, Role.SENIOR, true, now(), now(), false); userRepository.save(userOfSenior); @@ -54,39 +64,38 @@ void setUp() { senior = new Senior(0L, userOfSenior, "certification", WAITING, 0, info, profile, now(), now()); seniorRepository.save(senior); - accessToken = jwtUtil.generateAccessToken(userId, Role.USER); + accessToken = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); } - @Test - @DisplayName("대학생이 신청한 멘토링 목록을 조회한다") - @WithMockUser - void getWaitingMentorings() throws Exception { - Mentoring waitingMentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, Status.WAITING, now(), now()); - mentoringRepository.save(waitingMentoring); - - mvc.perform(get("/mentoring/me/waiting") - .header("Authorization", "Bearer " + accessToken)) + @ParameterizedTest + @MethodSource("waitingAndDoneProvider") + @DisplayName("대학생이 확정대기 및 완료 상태의 멘토링 목록을 조회한다") + void getWaitingMentorings(Status status) throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, status, now(), now()); + mentoringRepository.save(mentoring); + + mvc.perform(get("/mentoring/me/{status}", status.name().toLowerCase()) + .header(AUTHORIZATION, BEARER + accessToken)) .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value("MT200")) .andExpect(jsonPath("$.message").value("멘토링 리스트 조회에 성공하였습니다.")) - .andExpect(jsonPath("$.data.mentoringInfos[0].profile").value(containsString("profile"))) - .andExpect(jsonPath("$.data.mentoringInfos[0].nickName").value(containsString("선배"))) - .andExpect(jsonPath("$.data.mentoringInfos[0].postgradu").value(containsString("서울대학교"))) - .andExpect(jsonPath("$.data.mentoringInfos[0].major").value(containsString("major"))) - .andExpect(jsonPath("$.data.mentoringInfos[0].lab").value(containsString("랩실"))) + .andExpect(jsonPath("$.data.mentoringInfos[0].profile").value("profile")) + .andExpect(jsonPath("$.data.mentoringInfos[0].nickName").value("선배")) + .andExpect(jsonPath("$.data.mentoringInfos[0].postgradu").value("서울대학교")) + .andExpect(jsonPath("$.data.mentoringInfos[0].major").value("major")) + .andExpect(jsonPath("$.data.mentoringInfos[0].lab").value("랩실")) .andExpect(jsonPath("$.data.mentoringInfos[0].term").value(40)) .andExpect(jsonPath("$.data.mentoringInfos[0].chatLink").doesNotExist()); } @Test @DisplayName("대학생이 예정된 멘토링 목록을 조회한다") - @WithMockUser void getExpectedMentorings() throws Exception { Mentoring expectedMentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); mentoringRepository.save(expectedMentoring); mvc.perform(get("/mentoring/me/expected") - .header("Authorization", "Bearer " + accessToken)) + .header(AUTHORIZATION, BEARER + accessToken)) .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value("MT200")) .andExpect(jsonPath("$.message").value("멘토링 리스트 조회에 성공하였습니다.")) @@ -95,17 +104,32 @@ void getExpectedMentorings() throws Exception { } @Test - @DisplayName("대학생이 완료된 멘토링 목록을 조회한다") - @WithMockUser - void getDoneMentorings() throws Exception { - Mentoring doneMentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, Status.DONE, now(), now()); - mentoringRepository.save(doneMentoring); - - mvc.perform(get("/mentoring/me/done") - .header("Authorization", "Bearer " + accessToken)) + @DisplayName("대학생이 멘토링을 상세조회한다.") + void getMentoringDetail() throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, Status.WAITING, now(), now()); + mentoringRepository.save(mentoring); + + mvc.perform(get("/mentoring/me/{mentoringId}", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + accessToken)) .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value("MT200")) - .andExpect(jsonPath("$.message").value("멘토링 리스트 조회에 성공하였습니다.")) + .andExpect(jsonPath("$.message").value("멘토링 상세 조회에 성공하였습니다.")) .andExpect(jsonPath("$.data.mentoringInfos[0].chatLink").doesNotExist()); } + + + @ParameterizedTest + @MethodSource("statusProvider") + @DisplayName("완료, 취소, 거절 상태의 멘토링은 상세조회되지 않는다.") + void getDoneMentoringDetail(Status status) throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, status, now(), now()); + mentoringRepository.save(mentoring); + + mvc.perform(get("/mentoring/me/{mentoringId}", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + accessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("EX701")) + .andExpect(jsonPath("$.message").value("볼 수 없는 신청서 입니다.")); + } + } \ No newline at end of file From 4b9995babbe14c5993d0daed231fd3556d7a83e8 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Tue, 9 Jan 2024 19:57:22 +0900 Subject: [PATCH 04/24] =?UTF-8?q?RAC-254=20test:=20=EB=8C=80=ED=95=99?= =?UTF-8?q?=EC=83=9D=20=EB=A9=98=ED=86=A0=EB=A7=81=20=EC=8B=A0=EC=B2=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/MentoringControllerTest.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java index cd23cbbc..d1790628 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java @@ -1,6 +1,8 @@ package com.postgraduate.domain.mentoring.presentation; +import com.fasterxml.jackson.databind.ObjectMapper; import com.postgraduate.IntegrationTest; +import com.postgraduate.domain.mentoring.application.dto.req.MentoringApplyRequest; import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.domain.mentoring.domain.repository.MentoringRepository; @@ -18,19 +20,22 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.MediaType; import java.util.stream.Stream; import static com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING; import static java.time.LocalDateTime.now; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; class MentoringControllerTest extends IntegrationTest { private static final String AUTHORIZATION = "Authorization"; private static final String BEARER = "Bearer "; - + @Autowired + private ObjectMapper objectMapper; @Autowired private JwtUtils jwtUtil; @Autowired @@ -132,4 +137,19 @@ void getDoneMentoringDetail(Status status) throws Exception { .andExpect(jsonPath("$.message").value("볼 수 없는 신청서 입니다.")); } + @Test + @DisplayName("대학생이 멘토링을 신청한다.") + void applyMentoring() throws Exception { + String request = objectMapper.writeValueAsString(new MentoringApplyRequest(senior.getSeniorId(), "topic", "question", "date1,date2,date3")); + + mvc.perform(post("/mentoring/applying") + .header(AUTHORIZATION, BEARER + accessToken) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("MT202")) + .andExpect(jsonPath("$.message").value("멘토링 신청에 성공하였습니다.")); + } + } \ No newline at end of file From f0ac27b059ac099ed56f0971fff9e9c30bf92b5e Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 10 Jan 2024 14:06:22 +0900 Subject: [PATCH 05/24] =?UTF-8?q?RAC-254=20test:=20=EB=8C=80=ED=95=99?= =?UTF-8?q?=EC=83=9D=20=EB=A9=98=ED=86=A0=EB=A7=81=20=EC=83=81=ED=83=9C?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/MentoringControllerTest.java | 36 +++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java index d1790628..43401a4c 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java @@ -6,6 +6,8 @@ import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.domain.mentoring.domain.repository.MentoringRepository; +import com.postgraduate.domain.salary.domain.entity.Salary; +import com.postgraduate.domain.salary.domain.repository.SalaryRepository; import com.postgraduate.domain.senior.domain.entity.Info; import com.postgraduate.domain.senior.domain.entity.Profile; import com.postgraduate.domain.senior.domain.entity.Senior; @@ -22,12 +24,12 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; +import java.time.LocalDate; import java.util.stream.Stream; import static com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING; import static java.time.LocalDateTime.now; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; @@ -44,6 +46,8 @@ class MentoringControllerTest extends IntegrationTest { private SeniorRepository seniorRepository; @Autowired private MentoringRepository mentoringRepository; + @Autowired + private SalaryRepository salaryRepository; private User user; private Senior senior; private String accessToken; @@ -152,4 +156,32 @@ void applyMentoring() throws Exception { .andExpect(jsonPath("$.message").value("멘토링 신청에 성공하였습니다.")); } + @Test + @DisplayName("대학생이 멘토링을 완료한다.") + void updateMentoringDone() throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); + mentoringRepository.save(mentoring); + + Salary salary = new Salary(0L, false, senior, null, 10000, LocalDate.now(), now(), null, null, null); + salaryRepository.save(salary); + + mvc.perform(patch("/mentoring/me/{mentoringId}/done", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + accessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("MT201")) + .andExpect(jsonPath("$.message").value("멘토링 상태 갱신에 성공하였습니다.")); + } + + @Test + @DisplayName("대학생이 멘토링을 취소한다.") + void updateMentoringCancel() throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, Status.WAITING, now(), now()); + mentoringRepository.save(mentoring); + + mvc.perform(patch("/mentoring/me/{mentoringId}/cancel", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + accessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("MT201")) + .andExpect(jsonPath("$.message").value("멘토링 상태 갱신에 성공하였습니다.")); + } } \ No newline at end of file From c379692b65417ffc9aa615afedab469a95cab75a Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 10 Jan 2024 15:06:58 +0900 Subject: [PATCH 06/24] =?UTF-8?q?RAC-254=20test:=20=EB=8C=80=ED=95=99?= =?UTF-8?q?=EC=9B=90=EC=83=9D=20=EB=A9=98=ED=86=A0=EB=A7=81=20=EC=A1=B0?= =?UTF-8?q?=ED=9A=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/MentoringControllerTest.java | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java index 43401a4c..d97b691a 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java @@ -184,4 +184,56 @@ void updateMentoringCancel() throws Exception { .andExpect(jsonPath("$.code").value("MT201")) .andExpect(jsonPath("$.message").value("멘토링 상태 갱신에 성공하였습니다.")); } + + @ParameterizedTest + @EnumSource(value = Status.class, names = {"WAITING", "EXPECTED", "DONE"}) + @DisplayName("대학원생이 멘토링 목록을 조회한다.") + void getSeniorMentorings(Status status) throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, status, now(), now()); + mentoringRepository.save(mentoring); + + Salary salary = new Salary(0L, false, senior, null, 10000, LocalDate.now(), now(), null, null, null); + salaryRepository.save(salary); + + Payment payment = new Payment(0L, mentoring, salary, 10000, "cardAuthNumber", "cardReceipt", now(), null, DONE); + paymentRepository.save(payment); + + mvc.perform(get("/mentoring/senior/me/{status}", status.name().toLowerCase()) + .header(AUTHORIZATION, BEARER + seniorAccessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("MT200")) + .andExpect(jsonPath("$.message").value("멘토링 리스트 조회에 성공하였습니다.")) + .andExpect(jsonPath("$.data.seniorMentoringInfos[0].mentoringId").value(mentoring.getMentoringId())); + } + + @ParameterizedTest + @EnumSource(value = Status.class, names = {"WAITING", "EXPECTED"}) + @DisplayName("대학원생이 멘토링을 상세조회합니다.") + void getSeniorMentoringDetails(Status status) throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, status, now(), now()); + mentoringRepository.save(mentoring); + + mvc.perform(get("/mentoring/senior/me/{mentoringId}", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + seniorAccessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("MT200")) + .andExpect(jsonPath("$.message").value("멘토링 상세 조회에 성공하였습니다.")) + .andExpect(jsonPath("$.data.nickName").value("후배")); + + } + + @ParameterizedTest + @EnumSource(value = Status.class, names = {"DONE", "CANCEL", "REFUSE"}) + @DisplayName("대학원생의 완료, 취소, 거절 상태의 멘토링은 상세조회되지 않는다.") + void doNotGetMentoringDetails(Status status) throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, status, now(), now()); + mentoringRepository.save(mentoring); + + mvc.perform(get("/mentoring/senior/me/{mentoringId}", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + seniorAccessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("EX701")) + .andExpect(jsonPath("$.message").value("볼 수 없는 신청서 입니다.")); + + } } \ No newline at end of file From ec0bd6aa247d968a9b6bbecf3ae46d7c6fb804e0 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 10 Jan 2024 15:08:49 +0900 Subject: [PATCH 07/24] =?UTF-8?q?RAC-254=20fix:=20@EnumSource=20=EC=82=AC?= =?UTF-8?q?=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/MentoringControllerTest.java | 58 +++++++++---------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java index d97b691a..72795faa 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java @@ -6,6 +6,8 @@ import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.domain.mentoring.domain.repository.MentoringRepository; +import com.postgraduate.domain.payment.domain.entity.Payment; +import com.postgraduate.domain.payment.domain.repository.PaymentRepository; import com.postgraduate.domain.salary.domain.entity.Salary; import com.postgraduate.domain.salary.domain.repository.SalaryRepository; import com.postgraduate.domain.senior.domain.entity.Info; @@ -20,13 +22,13 @@ import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.provider.EnumSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; import java.time.LocalDate; -import java.util.stream.Stream; +import static com.postgraduate.domain.payment.domain.entity.constant.Status.DONE; import static com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING; import static java.time.LocalDateTime.now; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; @@ -48,17 +50,12 @@ class MentoringControllerTest extends IntegrationTest { private MentoringRepository mentoringRepository; @Autowired private SalaryRepository salaryRepository; + @Autowired + private PaymentRepository paymentRepository; private User user; private Senior senior; - private String accessToken; - - private static Stream statusProvider() { - return Stream.of(Status.DONE, Status.CANCEL, Status.REFUSE); - } - - private static Stream waitingAndDoneProvider() { - return Stream.of(Status.DONE, Status.WAITING); - } + private String userAccessToken; + private String seniorAccessToken; @BeforeEach void setUp() { @@ -73,21 +70,23 @@ void setUp() { senior = new Senior(0L, userOfSenior, "certification", WAITING, 0, info, profile, now(), now()); seniorRepository.save(senior); - accessToken = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); + userAccessToken = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); + seniorAccessToken = jwtUtil.generateAccessToken(userOfSenior.getUserId(), Role.SENIOR); } @ParameterizedTest - @MethodSource("waitingAndDoneProvider") + @EnumSource(value = Status.class, names = {"WAITING", "DONE"}) @DisplayName("대학생이 확정대기 및 완료 상태의 멘토링 목록을 조회한다") void getWaitingMentorings(Status status) throws Exception { Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, status, now(), now()); mentoringRepository.save(mentoring); mvc.perform(get("/mentoring/me/{status}", status.name().toLowerCase()) - .header(AUTHORIZATION, BEARER + accessToken)) + .header(AUTHORIZATION, BEARER + userAccessToken)) .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value("MT200")) .andExpect(jsonPath("$.message").value("멘토링 리스트 조회에 성공하였습니다.")) + .andExpect(jsonPath("$.data.mentoringInfos[0].mentoringId").value(mentoring.getMentoringId())) .andExpect(jsonPath("$.data.mentoringInfos[0].profile").value("profile")) .andExpect(jsonPath("$.data.mentoringInfos[0].nickName").value("선배")) .andExpect(jsonPath("$.data.mentoringInfos[0].postgradu").value("서울대학교")) @@ -100,42 +99,44 @@ void getWaitingMentorings(Status status) throws Exception { @Test @DisplayName("대학생이 예정된 멘토링 목록을 조회한다") void getExpectedMentorings() throws Exception { - Mentoring expectedMentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); - mentoringRepository.save(expectedMentoring); + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); + mentoringRepository.save(mentoring); mvc.perform(get("/mentoring/me/expected") - .header(AUTHORIZATION, BEARER + accessToken)) + .header(AUTHORIZATION, BEARER + userAccessToken)) .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value("MT200")) .andExpect(jsonPath("$.message").value("멘토링 리스트 조회에 성공하였습니다.")) + .andExpect(jsonPath("$.data.mentoringInfos[0].mentoringId").value(mentoring.getMentoringId())) .andExpect(jsonPath("$.data.mentoringInfos[0].chatLink").value("chatLink")) .andExpect(jsonPath("$.data.mentoringInfos[0].date").value("date")); } - @Test + @ParameterizedTest + @EnumSource(value = Status.class, names = {"WAITING", "EXPECTED"}) @DisplayName("대학생이 멘토링을 상세조회한다.") - void getMentoringDetail() throws Exception { - Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, Status.WAITING, now(), now()); + void getMentoringDetail(Status status) throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, status, now(), now()); mentoringRepository.save(mentoring); mvc.perform(get("/mentoring/me/{mentoringId}", mentoring.getMentoringId()) - .header(AUTHORIZATION, BEARER + accessToken)) + .header(AUTHORIZATION, BEARER + userAccessToken)) .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value("MT200")) .andExpect(jsonPath("$.message").value("멘토링 상세 조회에 성공하였습니다.")) - .andExpect(jsonPath("$.data.mentoringInfos[0].chatLink").doesNotExist()); + .andExpect(jsonPath("$.data.seniorId").value(senior.getSeniorId())); } @ParameterizedTest - @MethodSource("statusProvider") - @DisplayName("완료, 취소, 거절 상태의 멘토링은 상세조회되지 않는다.") + @EnumSource(value = Status.class, names = {"DONE", "CANCEL", "REFUSE"}) + @DisplayName("대학생의 완료, 취소, 거절 상태의 멘토링은 상세조회되지 않는다.") void getDoneMentoringDetail(Status status) throws Exception { Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, status, now(), now()); mentoringRepository.save(mentoring); mvc.perform(get("/mentoring/me/{mentoringId}", mentoring.getMentoringId()) - .header(AUTHORIZATION, BEARER + accessToken)) + .header(AUTHORIZATION, BEARER + userAccessToken)) .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value("EX701")) .andExpect(jsonPath("$.message").value("볼 수 없는 신청서 입니다.")); @@ -147,7 +148,7 @@ void applyMentoring() throws Exception { String request = objectMapper.writeValueAsString(new MentoringApplyRequest(senior.getSeniorId(), "topic", "question", "date1,date2,date3")); mvc.perform(post("/mentoring/applying") - .header(AUTHORIZATION, BEARER + accessToken) + .header(AUTHORIZATION, BEARER + userAccessToken) .content(request) .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) @@ -166,7 +167,7 @@ void updateMentoringDone() throws Exception { salaryRepository.save(salary); mvc.perform(patch("/mentoring/me/{mentoringId}/done", mentoring.getMentoringId()) - .header(AUTHORIZATION, BEARER + accessToken)) + .header(AUTHORIZATION, BEARER + userAccessToken)) .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value("MT201")) .andExpect(jsonPath("$.message").value("멘토링 상태 갱신에 성공하였습니다.")); @@ -179,7 +180,7 @@ void updateMentoringCancel() throws Exception { mentoringRepository.save(mentoring); mvc.perform(patch("/mentoring/me/{mentoringId}/cancel", mentoring.getMentoringId()) - .header(AUTHORIZATION, BEARER + accessToken)) + .header(AUTHORIZATION, BEARER + userAccessToken)) .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value("MT201")) .andExpect(jsonPath("$.message").value("멘토링 상태 갱신에 성공하였습니다.")); @@ -234,6 +235,5 @@ void doNotGetMentoringDetails(Status status) throws Exception { .andExpect(status().isOk()) .andExpect(jsonPath("$.code").value("EX701")) .andExpect(jsonPath("$.message").value("볼 수 없는 신청서 입니다.")); - } } \ No newline at end of file From d178b24ad9a23ebf0f26a888d8e269f53e87f7dc Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 10 Jan 2024 15:21:40 +0900 Subject: [PATCH 08/24] =?UTF-8?q?RAC-254=20test:=20=EB=8C=80=ED=95=99?= =?UTF-8?q?=EC=9B=90=EC=83=9D=20=EB=A9=98=ED=86=A0=EB=A7=81=20=EC=83=81?= =?UTF-8?q?=ED=83=9C=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/MentoringControllerTest.java | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java index 72795faa..52af8fb5 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java @@ -3,11 +3,13 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.postgraduate.IntegrationTest; import com.postgraduate.domain.mentoring.application.dto.req.MentoringApplyRequest; +import com.postgraduate.domain.mentoring.application.dto.req.MentoringDateRequest; import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.domain.mentoring.domain.repository.MentoringRepository; import com.postgraduate.domain.payment.domain.entity.Payment; import com.postgraduate.domain.payment.domain.repository.PaymentRepository; +import com.postgraduate.domain.refuse.application.dto.req.MentoringRefuseRequest; import com.postgraduate.domain.salary.domain.entity.Salary; import com.postgraduate.domain.salary.domain.repository.SalaryRepository; import com.postgraduate.domain.senior.domain.entity.Info; @@ -236,4 +238,38 @@ void doNotGetMentoringDetails(Status status) throws Exception { .andExpect(jsonPath("$.code").value("EX701")) .andExpect(jsonPath("$.message").value("볼 수 없는 신청서 입니다.")); } + + @Test + @DisplayName("대학원생이 멘토링을 수락한다.") + void updateSeniorMentoringExpected() throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date1,date2,date3", 40, Status.WAITING, now(), now()); + mentoringRepository.save(mentoring); + + String request = objectMapper.writeValueAsString(new MentoringDateRequest("date1")); + mvc.perform(patch("/mentoring/senior/me/{mentoringId}/expected", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + seniorAccessToken) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("MT201")) + .andExpect(jsonPath("$.message").value("멘토링 상태 갱신에 성공하였습니다.")); + } + + @Test + @DisplayName("대학원생이 멘토링을 거절한다.") + void updateSeniorMentoringRefuse() throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date1,date2,date3", 40, Status.WAITING, now(), now()); + mentoringRepository.save(mentoring); + + String request = objectMapper.writeValueAsString(new MentoringRefuseRequest("reason")); + mvc.perform(patch("/mentoring/senior/me/{mentoringId}/refuse", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + seniorAccessToken) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("MT201")) + .andExpect(jsonPath("$.message").value("멘토링 상태 갱신에 성공하였습니다.")); + } } \ No newline at end of file From dbc5536c9f9c171b50cbdd4cf066bc1f854ce8e2 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 10 Jan 2024 16:12:08 +0900 Subject: [PATCH 09/24] =?UTF-8?q?RAC-254=20test:=20=EC=86=8C=EC=85=9C=20?= =?UTF-8?q?=EB=A1=9C=EA=B7=B8=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/presentation/AuthControllerTest.java | 124 ++++++++++++++++++ 1 file changed, 124 insertions(+) create mode 100644 src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java diff --git a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java new file mode 100644 index 00000000..673b5326 --- /dev/null +++ b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java @@ -0,0 +1,124 @@ +package com.postgraduate.domain.auth.presentation; + +import com.fasterxml.jackson.databind.ObjectMapper; +import com.postgraduate.IntegrationTest; +import com.postgraduate.domain.auth.application.dto.req.CodeRequest; +import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse; +import com.postgraduate.domain.auth.application.usecase.oauth.kakao.KakaoAccessTokenUseCase; +import com.postgraduate.domain.user.domain.entity.User; +import com.postgraduate.domain.user.domain.entity.constant.Role; +import com.postgraduate.domain.user.domain.repository.UserRepository; +import com.postgraduate.domain.wish.domain.entity.Wish; +import com.postgraduate.domain.wish.domain.entity.constant.Status; +import com.postgraduate.domain.wish.domain.repository.WishRepository; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.http.MediaType; + +import static java.time.LocalDateTime.now; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.Mockito.when; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + +class AuthControllerTest extends IntegrationTest { + @Autowired + private ObjectMapper objectMapper; + @MockBean + private KakaoAccessTokenUseCase kakaoAccessTokenUseCase; + @Autowired + private UserRepository userRepository; + @Autowired + private WishRepository wishRepository; + private User user; + + @BeforeEach + void setUp() { + user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.USER, true, now(), now(), false); + userRepository.save(user); + } + + @Test + @DisplayName("회원이 로그인한다.") + void authLoginByUser() throws Exception { + Wish wish = new Wish(0L, "major", "field", true, user, Status.MATCHED); + wishRepository.save(wish); + + CodeRequest codeRequest = new CodeRequest("code"); + String request = objectMapper.writeValueAsString(codeRequest); + + when(kakaoAccessTokenUseCase.getAccessToken(codeRequest)) + .thenReturn(new KakaoUserInfoResponse(1L, any())); + + mvc.perform(post("/auth/login/KAKAO") + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("AU204")) + .andExpect(jsonPath("$.message").value("사용자 인증에 성공하였습니다.")) + .andExpect(jsonPath("$.data.accessToken").exists()) + .andExpect(jsonPath("$.data.socialId").doesNotExist()); + } + + @Test + @DisplayName("비회원이 로그인한다.") + void authLoginByAnonymousUser() throws Exception { + CodeRequest codeRequest = new CodeRequest("code"); + String request = objectMapper.writeValueAsString(codeRequest); + + Long socialId = 2L; + when(kakaoAccessTokenUseCase.getAccessToken(codeRequest)) + .thenReturn(new KakaoUserInfoResponse(socialId, any())); + + mvc.perform(post("/auth/login/KAKAO") + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("AU205")) + .andExpect(jsonPath("$.message").value("가입하지 않은 유저입니다.")) + .andExpect(jsonPath("$.data.accessToken").doesNotExist()) + .andExpect(jsonPath("$.data.socialId").value(socialId)); + } + + @Test + void logout() { + } + + @Test + void signOut() { + } + + @Test + void signUpUser() { + } + + @Test + void changeUserToken() { + } + + @Test + void changeUser() { + } + + @Test + void singUpSenior() { + } + + @Test + void changeSenior() { + } + + @Test + void changeSeniorToken() { + } + + @Test + void refresh() { + } +} \ No newline at end of file From 4ed6ac3394e73deadc6a79d371c66385f3f57b76 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 10 Jan 2024 16:25:46 +0900 Subject: [PATCH 10/24] =?UTF-8?q?RAC-254=20test:=20=ED=9A=8C=EC=9B=90?= =?UTF-8?q?=EA=B0=80=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/presentation/AuthControllerTest.java | 52 +++++++++++++++---- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java index 673b5326..cddc79a9 100644 --- a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java @@ -3,6 +3,8 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.postgraduate.IntegrationTest; import com.postgraduate.domain.auth.application.dto.req.CodeRequest; +import com.postgraduate.domain.auth.application.dto.req.SeniorSignUpRequest; +import com.postgraduate.domain.auth.application.dto.req.SignUpRequest; import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse; import com.postgraduate.domain.auth.application.usecase.oauth.kakao.KakaoAccessTokenUseCase; import com.postgraduate.domain.user.domain.entity.User; @@ -35,6 +37,8 @@ class AuthControllerTest extends IntegrationTest { @Autowired private WishRepository wishRepository; private User user; + private final Long anonymousUserSocialId = 2L; + @BeforeEach void setUp() { @@ -71,9 +75,8 @@ void authLoginByAnonymousUser() throws Exception { CodeRequest codeRequest = new CodeRequest("code"); String request = objectMapper.writeValueAsString(codeRequest); - Long socialId = 2L; when(kakaoAccessTokenUseCase.getAccessToken(codeRequest)) - .thenReturn(new KakaoUserInfoResponse(socialId, any())); + .thenReturn(new KakaoUserInfoResponse(anonymousUserSocialId, any())); mvc.perform(post("/auth/login/KAKAO") .content(request) @@ -83,19 +86,28 @@ void authLoginByAnonymousUser() throws Exception { .andExpect(jsonPath("$.code").value("AU205")) .andExpect(jsonPath("$.message").value("가입하지 않은 유저입니다.")) .andExpect(jsonPath("$.data.accessToken").doesNotExist()) - .andExpect(jsonPath("$.data.socialId").value(socialId)); + .andExpect(jsonPath("$.data.socialId").value(anonymousUserSocialId)); } @Test - void logout() { - } + @DisplayName("대학생이 회원가입 한다.") + void signUpUser() throws Exception { + authLoginByAnonymousUser(); - @Test - void signOut() { - } + String request = objectMapper.writeValueAsString( + new SignUpRequest(anonymousUserSocialId, "01012345678", "nickname", + true, "major", "field", true) + ); - @Test - void signUpUser() { + mvc.perform(post("/auth/user/signup") + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("AU202")) + .andExpect(jsonPath("$.message").value("사용자 인증에 성공하였습니다.")) + .andExpect(jsonPath("$.data.accessToken").exists()) + .andExpect(jsonPath("$.data.role").value("USER")); } @Test @@ -107,7 +119,25 @@ void changeUser() { } @Test - void singUpSenior() { + void singUpSenior() throws Exception { + + authLoginByAnonymousUser(); + + String request = objectMapper.writeValueAsString( + new SeniorSignUpRequest(anonymousUserSocialId, "01012345678", "nickname", + true, "전공", "서울대학교", "교수", "연구실", + "AI", "키워드", "certification") + ); + + mvc.perform(post("/auth/senior/signup") + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("SNR202")) + .andExpect(jsonPath("$.message").value("대학원생 가입에 성공하였습니다.")) + .andExpect(jsonPath("$.data.accessToken").exists()) + .andExpect(jsonPath("$.data.role").value("SENIOR")); } @Test From 6abe99c8505f8d5b215d3d3c755a5e46077c804f Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 10 Jan 2024 16:35:54 +0900 Subject: [PATCH 11/24] =?UTF-8?q?RAC-254=20test:=20=EC=B6=94=EA=B0=80=20?= =?UTF-8?q?=EA=B0=80=EC=9E=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/presentation/AuthControllerTest.java | 48 +++++++++++++++++-- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java index cddc79a9..2215fab2 100644 --- a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java @@ -2,9 +2,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.postgraduate.IntegrationTest; -import com.postgraduate.domain.auth.application.dto.req.CodeRequest; -import com.postgraduate.domain.auth.application.dto.req.SeniorSignUpRequest; -import com.postgraduate.domain.auth.application.dto.req.SignUpRequest; +import com.postgraduate.domain.auth.application.dto.req.*; import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse; import com.postgraduate.domain.auth.application.usecase.oauth.kakao.KakaoAccessTokenUseCase; import com.postgraduate.domain.user.domain.entity.User; @@ -13,6 +11,7 @@ import com.postgraduate.domain.wish.domain.entity.Wish; import com.postgraduate.domain.wish.domain.entity.constant.Status; import com.postgraduate.domain.wish.domain.repository.WishRepository; +import com.postgraduate.global.config.security.jwt.util.JwtUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -28,6 +27,10 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; class AuthControllerTest extends IntegrationTest { + private static final String AUTHORIZATION = "Authorization"; + private static final String BEARER = "Bearer "; + @Autowired + private JwtUtils jwtUtil; @Autowired private ObjectMapper objectMapper; @MockBean @@ -115,7 +118,24 @@ void changeUserToken() { } @Test - void changeUser() { + @DisplayName("선배가 후배로 추가 가입합니다.") + void changeUser() throws Exception { + String seniorAccessToken = jwtUtil.generateAccessToken(user.getUserId(), Role.SENIOR); + + String request = objectMapper.writeValueAsString( + new UserChangeRequest("major", "field", true) + ); + + mvc.perform(post("/auth/user/change") + .header(AUTHORIZATION, BEARER + seniorAccessToken) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("AU202")) + .andExpect(jsonPath("$.message").value("사용자 인증에 성공하였습니다.")) + .andExpect(jsonPath("$.data.accessToken").exists()) + .andExpect(jsonPath("$.data.role").value("USER")); } @Test @@ -141,7 +161,25 @@ void singUpSenior() throws Exception { } @Test - void changeSenior() { + @DisplayName("후배가 선배로 추가 가입합니다.") + void changeSenior() throws Exception { + String userAccessToken = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); + + String request = objectMapper.writeValueAsString( + new SeniorChangeRequest("major", "field", "교수", "연구실", + "AI", "키워드", "certification") + ); + + mvc.perform(post("/auth/senior/change") + .header(AUTHORIZATION, BEARER + userAccessToken) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("SNR202")) + .andExpect(jsonPath("$.message").value("대학원생 가입에 성공하였습니다.")) + .andExpect(jsonPath("$.data.accessToken").exists()) + .andExpect(jsonPath("$.data.role").value("SENIOR")); } @Test From 2d3ef1352c723cc1360ab0ccf3dd8adff3862532 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 10 Jan 2024 16:55:56 +0900 Subject: [PATCH 12/24] =?UTF-8?q?RAC-254=20test:=20=EA=B6=8C=ED=95=9C=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/presentation/AuthControllerTest.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java index 2215fab2..ff729605 100644 --- a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java @@ -114,7 +114,20 @@ void signUpUser() throws Exception { } @Test - void changeUserToken() { + @DisplayName("대학원생이 대학생으로 변경한다.") + void changeUserToken() throws Exception { + Wish wish = new Wish(0L, "major", "field", true, user, Status.MATCHED); + wishRepository.save(wish); + + String token = jwtUtil.generateAccessToken(user.getUserId(), Role.SENIOR); + + mvc.perform(post("/auth/user/token") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("AU202")) + .andExpect(jsonPath("$.message").value("사용자 인증에 성공하였습니다.")) + .andExpect(jsonPath("$.data.accessToken").exists()) + .andExpect(jsonPath("$.data.role").value("USER")); } @Test @@ -183,7 +196,17 @@ void changeSenior() throws Exception { } @Test - void changeSeniorToken() { + @DisplayName("대학생이 대학원생으로 변경한다.") + void changeSeniorToken() throws Exception { + String token = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); + + mvc.perform(post("/auth/senior/token") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("AU202")) + .andExpect(jsonPath("$.message").value("사용자 인증에 성공하였습니다.")) + .andExpect(jsonPath("$.data.accessToken").exists()) + .andExpect(jsonPath("$.data.role").value("SENIOR")); } @Test From db48fdf28591636d0f749cb5c4b0f3f7af9b4ed5 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 10 Jan 2024 17:17:34 +0900 Subject: [PATCH 13/24] =?UTF-8?q?RAC-254=20test:=20=EB=A6=AC=ED=94=84?= =?UTF-8?q?=EB=A0=88=EC=8B=9C=20=ED=86=A0=ED=81=B0=20=EC=9E=AC=EB=B0=9C?= =?UTF-8?q?=EA=B8=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/auth/presentation/AuthControllerTest.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java index ff729605..b4885288 100644 --- a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java @@ -210,6 +210,16 @@ void changeSeniorToken() throws Exception { } @Test - void refresh() { + void refresh() throws Exception { + Wish wish = new Wish(0L, "major", "field", true, user, Status.MATCHED); + wishRepository.save(wish); + + String refreshToken = jwtUtil.generateRefreshToken(user.getUserId(), Role.USER); + + mvc.perform(post("/auth/refresh") + .header(AUTHORIZATION, BEARER + refreshToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.data.accessToken").exists()) + .andExpect(jsonPath("$.data.role").value("USER")); } } \ No newline at end of file From 16cff8a2ff78af95f7974bd98965e511b18594a8 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 10 Jan 2024 17:43:10 +0900 Subject: [PATCH 14/24] =?UTF-8?q?RAC-254=20test:=20=EB=A1=9C=EA=B7=B8?= =?UTF-8?q?=EC=95=84=EC=9B=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/presentation/AuthControllerTest.java | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java index b4885288..e548ed87 100644 --- a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java @@ -152,8 +152,8 @@ void changeUser() throws Exception { } @Test + @DisplayName("선배가 회원가입한다.") void singUpSenior() throws Exception { - authLoginByAnonymousUser(); String request = objectMapper.writeValueAsString( @@ -210,6 +210,7 @@ void changeSeniorToken() throws Exception { } @Test + @DisplayName("토큰을 재발급한다.") void refresh() throws Exception { Wish wish = new Wish(0L, "major", "field", true, user, Status.MATCHED); wishRepository.save(wish); @@ -219,7 +220,21 @@ void refresh() throws Exception { mvc.perform(post("/auth/refresh") .header(AUTHORIZATION, BEARER + refreshToken)) .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("AU201")) + .andExpect(jsonPath("$.message").value("토큰 재발급에 성공하였습니다.")) .andExpect(jsonPath("$.data.accessToken").exists()) .andExpect(jsonPath("$.data.role").value("USER")); } + + @Test + @DisplayName("로그아웃한다.") + void logout() throws Exception { + String accessToken = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); + + mvc.perform(post("/auth/logout") + .header(AUTHORIZATION, BEARER + accessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value("AU203")) + .andExpect(jsonPath("$.message").value("로그아웃에 성공하였습니다.")); + } } \ No newline at end of file From 797f8efd2060937013411ee524725fcfd87a063b Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 10 Jan 2024 17:43:27 +0900 Subject: [PATCH 15/24] =?UTF-8?q?RAC-254=20test:=20@Disabled=20=EC=B6=94?= =?UTF-8?q?=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/test/java/com/postgraduate/IntegrationTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/test/java/com/postgraduate/IntegrationTest.java b/src/test/java/com/postgraduate/IntegrationTest.java index 54c376af..1d4ba382 100644 --- a/src/test/java/com/postgraduate/IntegrationTest.java +++ b/src/test/java/com/postgraduate/IntegrationTest.java @@ -1,6 +1,7 @@ package com.postgraduate; import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; @@ -17,6 +18,7 @@ @SpringBootTest @AutoConfigureMockMvc @Transactional +@Disabled public class IntegrationTest { @Autowired From 9f25dab86363174513cce20071e6f885acee652a Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Wed, 10 Jan 2024 22:01:57 +0900 Subject: [PATCH 16/24] =?UTF-8?q?RAC-254=20fix:=20redis=20MockBean=20?= =?UTF-8?q?=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/auth/presentation/AuthControllerTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java index e548ed87..99577bbb 100644 --- a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java @@ -11,6 +11,7 @@ import com.postgraduate.domain.wish.domain.entity.Wish; import com.postgraduate.domain.wish.domain.entity.constant.Status; import com.postgraduate.domain.wish.domain.repository.WishRepository; +import com.postgraduate.global.config.redis.RedisRepository; import com.postgraduate.global.config.security.jwt.util.JwtUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -19,6 +20,8 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; +import java.util.Optional; + import static java.time.LocalDateTime.now; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -39,6 +42,8 @@ class AuthControllerTest extends IntegrationTest { private UserRepository userRepository; @Autowired private WishRepository wishRepository; + @MockBean + RedisRepository redisRepository; private User user; private final Long anonymousUserSocialId = 2L; @@ -216,6 +221,7 @@ void refresh() throws Exception { wishRepository.save(wish); String refreshToken = jwtUtil.generateRefreshToken(user.getUserId(), Role.USER); + when(redisRepository.getValues(any())).thenReturn(Optional.of(refreshToken)); mvc.perform(post("/auth/refresh") .header(AUTHORIZATION, BEARER + refreshToken)) From 2233564786df7a7224355a26008a909ae1235a29 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Thu, 11 Jan 2024 14:09:29 +0900 Subject: [PATCH 17/24] =?UTF-8?q?RAC-254=20fix:=20=EC=9D=91=EB=8B=B5=20enu?= =?UTF-8?q?m=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/presentation/AuthControllerTest.java | 44 +++++++------ .../presentation/MentoringControllerTest.java | 63 +++++++++---------- 2 files changed, 53 insertions(+), 54 deletions(-) diff --git a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java index 99577bbb..f00cb9d9 100644 --- a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java @@ -22,6 +22,10 @@ import java.util.Optional; +import static com.postgraduate.domain.auth.presentation.constant.AuthResponseCode.*; +import static com.postgraduate.domain.auth.presentation.constant.AuthResponseMessage.*; +import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode.SENIOR_CREATE; +import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage.CREATE_SENIOR; import static java.time.LocalDateTime.now; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -71,8 +75,8 @@ void authLoginByUser() throws Exception { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("AU204")) - .andExpect(jsonPath("$.message").value("사용자 인증에 성공하였습니다.")) + .andExpect(jsonPath("$.code").value(AUTH_ALREADY.getCode())) + .andExpect(jsonPath("$.message").value(SUCCESS_AUTH.getMessage())) .andExpect(jsonPath("$.data.accessToken").exists()) .andExpect(jsonPath("$.data.socialId").doesNotExist()); } @@ -91,8 +95,8 @@ void authLoginByAnonymousUser() throws Exception { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("AU205")) - .andExpect(jsonPath("$.message").value("가입하지 않은 유저입니다.")) + .andExpect(jsonPath("$.code").value(AUTH_NONE.getCode())) + .andExpect(jsonPath("$.message").value(NOT_REGISTERED_USER.getMessage())) .andExpect(jsonPath("$.data.accessToken").doesNotExist()) .andExpect(jsonPath("$.data.socialId").value(anonymousUserSocialId)); } @@ -112,8 +116,8 @@ void signUpUser() throws Exception { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("AU202")) - .andExpect(jsonPath("$.message").value("사용자 인증에 성공하였습니다.")) + .andExpect(jsonPath("$.code").value(AUTH_CREATE.getCode())) + .andExpect(jsonPath("$.message").value(SUCCESS_AUTH.getMessage())) .andExpect(jsonPath("$.data.accessToken").exists()) .andExpect(jsonPath("$.data.role").value("USER")); } @@ -129,8 +133,8 @@ void changeUserToken() throws Exception { mvc.perform(post("/auth/user/token") .header(AUTHORIZATION, BEARER + token)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("AU202")) - .andExpect(jsonPath("$.message").value("사용자 인증에 성공하였습니다.")) + .andExpect(jsonPath("$.code").value(AUTH_CREATE.getCode())) + .andExpect(jsonPath("$.message").value(SUCCESS_AUTH.getMessage())) .andExpect(jsonPath("$.data.accessToken").exists()) .andExpect(jsonPath("$.data.role").value("USER")); } @@ -150,8 +154,8 @@ void changeUser() throws Exception { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("AU202")) - .andExpect(jsonPath("$.message").value("사용자 인증에 성공하였습니다.")) + .andExpect(jsonPath("$.code").value(AUTH_CREATE.getCode())) + .andExpect(jsonPath("$.message").value(SUCCESS_AUTH.getMessage())) .andExpect(jsonPath("$.data.accessToken").exists()) .andExpect(jsonPath("$.data.role").value("USER")); } @@ -172,8 +176,8 @@ void singUpSenior() throws Exception { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("SNR202")) - .andExpect(jsonPath("$.message").value("대학원생 가입에 성공하였습니다.")) + .andExpect(jsonPath("$.code").value(SENIOR_CREATE.getCode())) + .andExpect(jsonPath("$.message").value(CREATE_SENIOR.getMessage())) .andExpect(jsonPath("$.data.accessToken").exists()) .andExpect(jsonPath("$.data.role").value("SENIOR")); } @@ -194,8 +198,8 @@ void changeSenior() throws Exception { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("SNR202")) - .andExpect(jsonPath("$.message").value("대학원생 가입에 성공하였습니다.")) + .andExpect(jsonPath("$.code").value(SENIOR_CREATE.getCode())) + .andExpect(jsonPath("$.message").value(CREATE_SENIOR.getMessage())) .andExpect(jsonPath("$.data.accessToken").exists()) .andExpect(jsonPath("$.data.role").value("SENIOR")); } @@ -208,8 +212,8 @@ void changeSeniorToken() throws Exception { mvc.perform(post("/auth/senior/token") .header(AUTHORIZATION, BEARER + token)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("AU202")) - .andExpect(jsonPath("$.message").value("사용자 인증에 성공하였습니다.")) + .andExpect(jsonPath("$.code").value(AUTH_CREATE.getCode())) + .andExpect(jsonPath("$.message").value(SUCCESS_AUTH.getMessage())) .andExpect(jsonPath("$.data.accessToken").exists()) .andExpect(jsonPath("$.data.role").value("SENIOR")); } @@ -226,8 +230,8 @@ void refresh() throws Exception { mvc.perform(post("/auth/refresh") .header(AUTHORIZATION, BEARER + refreshToken)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("AU201")) - .andExpect(jsonPath("$.message").value("토큰 재발급에 성공하였습니다.")) + .andExpect(jsonPath("$.code").value(AUTH_UPDATE.getCode())) + .andExpect(jsonPath("$.message").value(SUCCESS_REGENERATE_TOKEN.getMessage())) .andExpect(jsonPath("$.data.accessToken").exists()) .andExpect(jsonPath("$.data.role").value("USER")); } @@ -240,7 +244,7 @@ void logout() throws Exception { mvc.perform(post("/auth/logout") .header(AUTHORIZATION, BEARER + accessToken)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("AU203")) - .andExpect(jsonPath("$.message").value("로그아웃에 성공하였습니다.")); + .andExpect(jsonPath("$.code").value(AUTH_DELETE.getCode())) + .andExpect(jsonPath("$.message").value(LOGOUT_USER.getMessage())); } } \ No newline at end of file diff --git a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java index 52af8fb5..42148a21 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java @@ -30,7 +30,10 @@ import java.time.LocalDate; +import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode.*; +import static com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage.*; import static com.postgraduate.domain.payment.domain.entity.constant.Status.DONE; +import static com.postgraduate.domain.salary.util.SalaryUtil.getSalaryDate; import static com.postgraduate.domain.senior.domain.entity.constant.Status.WAITING; import static java.time.LocalDateTime.now; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; @@ -86,15 +89,9 @@ void getWaitingMentorings(Status status) throws Exception { mvc.perform(get("/mentoring/me/{status}", status.name().toLowerCase()) .header(AUTHORIZATION, BEARER + userAccessToken)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("MT200")) - .andExpect(jsonPath("$.message").value("멘토링 리스트 조회에 성공하였습니다.")) + .andExpect(jsonPath("$.code").value(MENTORING_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_MENTORING_LIST_INFO.getMessage())) .andExpect(jsonPath("$.data.mentoringInfos[0].mentoringId").value(mentoring.getMentoringId())) - .andExpect(jsonPath("$.data.mentoringInfos[0].profile").value("profile")) - .andExpect(jsonPath("$.data.mentoringInfos[0].nickName").value("선배")) - .andExpect(jsonPath("$.data.mentoringInfos[0].postgradu").value("서울대학교")) - .andExpect(jsonPath("$.data.mentoringInfos[0].major").value("major")) - .andExpect(jsonPath("$.data.mentoringInfos[0].lab").value("랩실")) - .andExpect(jsonPath("$.data.mentoringInfos[0].term").value(40)) .andExpect(jsonPath("$.data.mentoringInfos[0].chatLink").doesNotExist()); } @@ -107,11 +104,9 @@ void getExpectedMentorings() throws Exception { mvc.perform(get("/mentoring/me/expected") .header(AUTHORIZATION, BEARER + userAccessToken)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("MT200")) - .andExpect(jsonPath("$.message").value("멘토링 리스트 조회에 성공하였습니다.")) - .andExpect(jsonPath("$.data.mentoringInfos[0].mentoringId").value(mentoring.getMentoringId())) - .andExpect(jsonPath("$.data.mentoringInfos[0].chatLink").value("chatLink")) - .andExpect(jsonPath("$.data.mentoringInfos[0].date").value("date")); + .andExpect(jsonPath("$.code").value(MENTORING_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_MENTORING_LIST_INFO.getMessage())) + .andExpect(jsonPath("$.data.mentoringInfos[0].mentoringId").value(mentoring.getMentoringId())); } @ParameterizedTest @@ -124,8 +119,8 @@ void getMentoringDetail(Status status) throws Exception { mvc.perform(get("/mentoring/me/{mentoringId}", mentoring.getMentoringId()) .header(AUTHORIZATION, BEARER + userAccessToken)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("MT200")) - .andExpect(jsonPath("$.message").value("멘토링 상세 조회에 성공하였습니다.")) + .andExpect(jsonPath("$.code").value(MENTORING_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_MENTORING_DETAIL_INFO.getMessage())) .andExpect(jsonPath("$.data.seniorId").value(senior.getSeniorId())); } @@ -140,8 +135,8 @@ void getDoneMentoringDetail(Status status) throws Exception { mvc.perform(get("/mentoring/me/{mentoringId}", mentoring.getMentoringId()) .header(AUTHORIZATION, BEARER + userAccessToken)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("EX701")) - .andExpect(jsonPath("$.message").value("볼 수 없는 신청서 입니다.")); + .andExpect(jsonPath("$.code").value(DETAIL_NOT_FOUND.getCode())) + .andExpect(jsonPath("$.message").value(NOT_FOUND_DETAIL.getMessage())); } @Test @@ -155,8 +150,8 @@ void applyMentoring() throws Exception { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("MT202")) - .andExpect(jsonPath("$.message").value("멘토링 신청에 성공하였습니다.")); + .andExpect(jsonPath("$.code").value(MENTORING_CREATE.getCode())) + .andExpect(jsonPath("$.message").value(CREATE_MENTORING.getMessage())); } @Test @@ -165,14 +160,14 @@ void updateMentoringDone() throws Exception { Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, Status.EXPECTED, now(), now()); mentoringRepository.save(mentoring); - Salary salary = new Salary(0L, false, senior, null, 10000, LocalDate.now(), now(), null, null, null); + Salary salary = new Salary(0L, false, senior, null, 10000, getSalaryDate(), now(), null, null, null); salaryRepository.save(salary); mvc.perform(patch("/mentoring/me/{mentoringId}/done", mentoring.getMentoringId()) .header(AUTHORIZATION, BEARER + userAccessToken)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("MT201")) - .andExpect(jsonPath("$.message").value("멘토링 상태 갱신에 성공하였습니다.")); + .andExpect(jsonPath("$.code").value(MENTORING_UPDATE.getCode())) + .andExpect(jsonPath("$.message").value(UPDATE_MENTORING.getMessage())); } @Test @@ -184,8 +179,8 @@ void updateMentoringCancel() throws Exception { mvc.perform(patch("/mentoring/me/{mentoringId}/cancel", mentoring.getMentoringId()) .header(AUTHORIZATION, BEARER + userAccessToken)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("MT201")) - .andExpect(jsonPath("$.message").value("멘토링 상태 갱신에 성공하였습니다.")); + .andExpect(jsonPath("$.code").value(MENTORING_UPDATE.getCode())) + .andExpect(jsonPath("$.message").value(UPDATE_MENTORING.getMessage())); } @ParameterizedTest @@ -204,8 +199,8 @@ void getSeniorMentorings(Status status) throws Exception { mvc.perform(get("/mentoring/senior/me/{status}", status.name().toLowerCase()) .header(AUTHORIZATION, BEARER + seniorAccessToken)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("MT200")) - .andExpect(jsonPath("$.message").value("멘토링 리스트 조회에 성공하였습니다.")) + .andExpect(jsonPath("$.code").value(MENTORING_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_MENTORING_LIST_INFO.getMessage())) .andExpect(jsonPath("$.data.seniorMentoringInfos[0].mentoringId").value(mentoring.getMentoringId())); } @@ -219,8 +214,8 @@ void getSeniorMentoringDetails(Status status) throws Exception { mvc.perform(get("/mentoring/senior/me/{mentoringId}", mentoring.getMentoringId()) .header(AUTHORIZATION, BEARER + seniorAccessToken)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("MT200")) - .andExpect(jsonPath("$.message").value("멘토링 상세 조회에 성공하였습니다.")) + .andExpect(jsonPath("$.code").value(MENTORING_FIND.getCode())) + .andExpect(jsonPath("$.message").value(GET_MENTORING_DETAIL_INFO.getMessage())) .andExpect(jsonPath("$.data.nickName").value("후배")); } @@ -235,8 +230,8 @@ void doNotGetMentoringDetails(Status status) throws Exception { mvc.perform(get("/mentoring/senior/me/{mentoringId}", mentoring.getMentoringId()) .header(AUTHORIZATION, BEARER + seniorAccessToken)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("EX701")) - .andExpect(jsonPath("$.message").value("볼 수 없는 신청서 입니다.")); + .andExpect(jsonPath("$.code").value(DETAIL_NOT_FOUND.getCode())) + .andExpect(jsonPath("$.message").value(NOT_FOUND_DETAIL.getMessage())); } @Test @@ -252,8 +247,8 @@ void updateSeniorMentoringExpected() throws Exception { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("MT201")) - .andExpect(jsonPath("$.message").value("멘토링 상태 갱신에 성공하였습니다.")); + .andExpect(jsonPath("$.code").value(MENTORING_UPDATE.getCode())) + .andExpect(jsonPath("$.message").value(UPDATE_MENTORING.getMessage())); } @Test @@ -269,7 +264,7 @@ void updateSeniorMentoringRefuse() throws Exception { .contentType(MediaType.APPLICATION_JSON) .accept(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.code").value("MT201")) - .andExpect(jsonPath("$.message").value("멘토링 상태 갱신에 성공하였습니다.")); + .andExpect(jsonPath("$.code").value(MENTORING_UPDATE.getCode())) + .andExpect(jsonPath("$.message").value(UPDATE_MENTORING.getMessage())); } } \ No newline at end of file From 1f364cdc1dae20467d987739a15d3a7a1f060953 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Thu, 11 Jan 2024 14:22:24 +0900 Subject: [PATCH 18/24] =?UTF-8?q?RAC-254=20test:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=83=81=ED=83=9C=EB=B3=80=EA=B2=BD=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/MentoringControllerTest.java | 67 +++++++++++++++++++ 1 file changed, 67 insertions(+) diff --git a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java index 42148a21..03b2c607 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java @@ -170,6 +170,23 @@ void updateMentoringDone() throws Exception { .andExpect(jsonPath("$.message").value(UPDATE_MENTORING.getMessage())); } + @ParameterizedTest + @EnumSource(value = Status.class, names = {"WAITING", "DONE", "CANCEL", "REFUSE"}) + @DisplayName("진행예정이 아닌 멘토링의 경우 완료할 수 없다.") + void updateMentoringDoneWithoutExpected(Status status) throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, status, now(), now()); + mentoringRepository.save(mentoring); + + Salary salary = new Salary(0L, false, senior, null, 10000, getSalaryDate(), now(), null, null, null); + salaryRepository.save(salary); + + mvc.perform(patch("/mentoring/me/{mentoringId}/done", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + userAccessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(MENTORING_NOT_EXPECTED.getCode())) + .andExpect(jsonPath("$.message").value(NOT_EXPECTED_MENTORING.getMessage())); + } + @Test @DisplayName("대학생이 멘토링을 취소한다.") void updateMentoringCancel() throws Exception { @@ -183,6 +200,20 @@ void updateMentoringCancel() throws Exception { .andExpect(jsonPath("$.message").value(UPDATE_MENTORING.getMessage())); } + @ParameterizedTest + @EnumSource(value = Status.class, names = {"EXPECTED", "DONE", "CANCEL", "REFUSE"}) + @DisplayName("멘토링이 확정대기 상태가 아니라면 취소할 수 없다.") + void updateMentoringCancelWithoutWaiting(Status status) throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, status, now(), now()); + mentoringRepository.save(mentoring); + + mvc.perform(patch("/mentoring/me/{mentoringId}/cancel", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + userAccessToken)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(MENTORING_NOT_WAITING.getCode())) + .andExpect(jsonPath("$.message").value(NOT_WAITING_MENTORING.getMessage())); + } + @ParameterizedTest @EnumSource(value = Status.class, names = {"WAITING", "EXPECTED", "DONE"}) @DisplayName("대학원생이 멘토링 목록을 조회한다.") @@ -251,6 +282,24 @@ void updateSeniorMentoringExpected() throws Exception { .andExpect(jsonPath("$.message").value(UPDATE_MENTORING.getMessage())); } + @ParameterizedTest + @EnumSource(value = Status.class, names = {"EXPECTED", "DONE", "CANCEL", "REFUSE"}) + @DisplayName("멘토링이 확정대기 상태가 아니라면 수락할 수 없다.") + void updateSeniorMentoringExpectedWithoutWaiting(Status status) throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date1,date2,date3", 40, status, now(), now()); + mentoringRepository.save(mentoring); + + String request = objectMapper.writeValueAsString(new MentoringDateRequest("date1")); + mvc.perform(patch("/mentoring/senior/me/{mentoringId}/expected", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + seniorAccessToken) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(MENTORING_NOT_WAITING.getCode())) + .andExpect(jsonPath("$.message").value(NOT_WAITING_MENTORING.getMessage())); + } + @Test @DisplayName("대학원생이 멘토링을 거절한다.") void updateSeniorMentoringRefuse() throws Exception { @@ -267,4 +316,22 @@ void updateSeniorMentoringRefuse() throws Exception { .andExpect(jsonPath("$.code").value(MENTORING_UPDATE.getCode())) .andExpect(jsonPath("$.message").value(UPDATE_MENTORING.getMessage())); } + + @ParameterizedTest + @EnumSource(value = Status.class, names = {"EXPECTED", "DONE", "CANCEL", "REFUSE"}) + @DisplayName("멘토링이 확정대기 상태가 아니라면 거절할 수 없다.") + void updateSeniorMentoringRefuseWithoutWaiting(Status status) throws Exception { + Mentoring mentoring = new Mentoring(0L, user, senior, "topic", "question", "date", 40, status, now(), now()); + mentoringRepository.save(mentoring); + + String request = objectMapper.writeValueAsString(new MentoringRefuseRequest("reason")); + mvc.perform(patch("/mentoring/senior/me/{mentoringId}/refuse", mentoring.getMentoringId()) + .header(AUTHORIZATION, BEARER + seniorAccessToken) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(MENTORING_NOT_WAITING.getCode())) + .andExpect(jsonPath("$.message").value(NOT_WAITING_MENTORING.getMessage())); + } } \ No newline at end of file From d3071b34b44e20a471640f6fe085547394c4b69f Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Thu, 11 Jan 2024 14:27:42 +0900 Subject: [PATCH 19/24] =?UTF-8?q?RAC-254=20test:=20=EB=A9=98=ED=86=A0?= =?UTF-8?q?=EB=A7=81=20=EC=8B=A0=EC=B2=AD=20=EB=82=A0=EC=A7=9C=20=EC=98=88?= =?UTF-8?q?=EC=99=B8=20=ED=85=8C=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presentation/MentoringControllerTest.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java index 03b2c607..01d3d1d2 100644 --- a/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java +++ b/src/test/java/com/postgraduate/domain/mentoring/presentation/MentoringControllerTest.java @@ -7,6 +7,8 @@ import com.postgraduate.domain.mentoring.domain.entity.Mentoring; import com.postgraduate.domain.mentoring.domain.entity.constant.Status; import com.postgraduate.domain.mentoring.domain.repository.MentoringRepository; +import com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseCode; +import com.postgraduate.domain.mentoring.presentation.constant.MentoringResponseMessage; import com.postgraduate.domain.payment.domain.entity.Payment; import com.postgraduate.domain.payment.domain.repository.PaymentRepository; import com.postgraduate.domain.refuse.application.dto.req.MentoringRefuseRequest; @@ -25,6 +27,7 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.EnumSource; +import org.junit.jupiter.params.provider.ValueSource; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.MediaType; @@ -154,6 +157,23 @@ void applyMentoring() throws Exception { .andExpect(jsonPath("$.message").value(CREATE_MENTORING.getMessage())); } + @ParameterizedTest + @ValueSource(strings = {"date1", "date1,date2", "date1,date2,date3,date4"}) + @DisplayName("날짜가 3개가 아니라면 멘토링을 신청할 수 없다.") + void applyMentoringWithoutThreeDates(String date) throws Exception { + String request = objectMapper.writeValueAsString(new MentoringApplyRequest(senior.getSeniorId(), "topic", "question", date)); + + mvc.perform(post("/mentoring/applying") + .header(AUTHORIZATION, BEARER + userAccessToken) + .content(request) + .contentType(MediaType.APPLICATION_JSON) + .accept(MediaType.APPLICATION_JSON)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(MentoringResponseCode.INVALID_DATE.getCode())) + .andExpect(jsonPath("$.message").value(MentoringResponseMessage.INVALID_DATE.getMessage())); + + } + @Test @DisplayName("대학생이 멘토링을 완료한다.") void updateMentoringDone() throws Exception { From b623a40ea053398fad5debfcd14cb3473ec95cb3 Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Thu, 11 Jan 2024 14:36:42 +0900 Subject: [PATCH 20/24] =?UTF-8?q?RAC-254=20fix:=20=EC=9D=91=EB=8B=B5=20Rol?= =?UTF-8?q?e=20enum=20=EC=82=AC=EC=9A=A9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/presentation/AuthControllerTest.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java index f00cb9d9..089209b6 100644 --- a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java @@ -6,7 +6,6 @@ import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse; import com.postgraduate.domain.auth.application.usecase.oauth.kakao.KakaoAccessTokenUseCase; import com.postgraduate.domain.user.domain.entity.User; -import com.postgraduate.domain.user.domain.entity.constant.Role; import com.postgraduate.domain.user.domain.repository.UserRepository; import com.postgraduate.domain.wish.domain.entity.Wish; import com.postgraduate.domain.wish.domain.entity.constant.Status; @@ -26,6 +25,8 @@ import static com.postgraduate.domain.auth.presentation.constant.AuthResponseMessage.*; import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode.SENIOR_CREATE; import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage.CREATE_SENIOR; +import static com.postgraduate.domain.user.domain.entity.constant.Role.SENIOR; +import static com.postgraduate.domain.user.domain.entity.constant.Role.USER; import static java.time.LocalDateTime.now; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -54,7 +55,7 @@ class AuthControllerTest extends IntegrationTest { @BeforeEach void setUp() { - user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, Role.USER, true, now(), now(), false); + user = new User(0L, 1L, "mail", "후배", "011", "profile", 0, USER, true, now(), now(), false); userRepository.save(user); } @@ -119,7 +120,7 @@ void signUpUser() throws Exception { .andExpect(jsonPath("$.code").value(AUTH_CREATE.getCode())) .andExpect(jsonPath("$.message").value(SUCCESS_AUTH.getMessage())) .andExpect(jsonPath("$.data.accessToken").exists()) - .andExpect(jsonPath("$.data.role").value("USER")); + .andExpect(jsonPath("$.data.role").value(USER.name())); } @Test @@ -128,7 +129,7 @@ void changeUserToken() throws Exception { Wish wish = new Wish(0L, "major", "field", true, user, Status.MATCHED); wishRepository.save(wish); - String token = jwtUtil.generateAccessToken(user.getUserId(), Role.SENIOR); + String token = jwtUtil.generateAccessToken(user.getUserId(), SENIOR); mvc.perform(post("/auth/user/token") .header(AUTHORIZATION, BEARER + token)) @@ -136,13 +137,13 @@ void changeUserToken() throws Exception { .andExpect(jsonPath("$.code").value(AUTH_CREATE.getCode())) .andExpect(jsonPath("$.message").value(SUCCESS_AUTH.getMessage())) .andExpect(jsonPath("$.data.accessToken").exists()) - .andExpect(jsonPath("$.data.role").value("USER")); + .andExpect(jsonPath("$.data.role").value(USER.name())); } @Test @DisplayName("선배가 후배로 추가 가입합니다.") void changeUser() throws Exception { - String seniorAccessToken = jwtUtil.generateAccessToken(user.getUserId(), Role.SENIOR); + String seniorAccessToken = jwtUtil.generateAccessToken(user.getUserId(), SENIOR); String request = objectMapper.writeValueAsString( new UserChangeRequest("major", "field", true) @@ -157,7 +158,7 @@ void changeUser() throws Exception { .andExpect(jsonPath("$.code").value(AUTH_CREATE.getCode())) .andExpect(jsonPath("$.message").value(SUCCESS_AUTH.getMessage())) .andExpect(jsonPath("$.data.accessToken").exists()) - .andExpect(jsonPath("$.data.role").value("USER")); + .andExpect(jsonPath("$.data.role").value(USER.name())); } @Test @@ -179,13 +180,13 @@ void singUpSenior() throws Exception { .andExpect(jsonPath("$.code").value(SENIOR_CREATE.getCode())) .andExpect(jsonPath("$.message").value(CREATE_SENIOR.getMessage())) .andExpect(jsonPath("$.data.accessToken").exists()) - .andExpect(jsonPath("$.data.role").value("SENIOR")); + .andExpect(jsonPath("$.data.role").value(SENIOR.name())); } @Test @DisplayName("후배가 선배로 추가 가입합니다.") void changeSenior() throws Exception { - String userAccessToken = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); + String userAccessToken = jwtUtil.generateAccessToken(user.getUserId(), USER); String request = objectMapper.writeValueAsString( new SeniorChangeRequest("major", "field", "교수", "연구실", @@ -201,13 +202,13 @@ void changeSenior() throws Exception { .andExpect(jsonPath("$.code").value(SENIOR_CREATE.getCode())) .andExpect(jsonPath("$.message").value(CREATE_SENIOR.getMessage())) .andExpect(jsonPath("$.data.accessToken").exists()) - .andExpect(jsonPath("$.data.role").value("SENIOR")); + .andExpect(jsonPath("$.data.role").value(SENIOR.name())); } @Test @DisplayName("대학생이 대학원생으로 변경한다.") void changeSeniorToken() throws Exception { - String token = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); + String token = jwtUtil.generateAccessToken(user.getUserId(), USER); mvc.perform(post("/auth/senior/token") .header(AUTHORIZATION, BEARER + token)) @@ -215,7 +216,7 @@ void changeSeniorToken() throws Exception { .andExpect(jsonPath("$.code").value(AUTH_CREATE.getCode())) .andExpect(jsonPath("$.message").value(SUCCESS_AUTH.getMessage())) .andExpect(jsonPath("$.data.accessToken").exists()) - .andExpect(jsonPath("$.data.role").value("SENIOR")); + .andExpect(jsonPath("$.data.role").value(SENIOR.name())); } @Test @@ -224,7 +225,7 @@ void refresh() throws Exception { Wish wish = new Wish(0L, "major", "field", true, user, Status.MATCHED); wishRepository.save(wish); - String refreshToken = jwtUtil.generateRefreshToken(user.getUserId(), Role.USER); + String refreshToken = jwtUtil.generateRefreshToken(user.getUserId(), USER); when(redisRepository.getValues(any())).thenReturn(Optional.of(refreshToken)); mvc.perform(post("/auth/refresh") @@ -233,13 +234,13 @@ void refresh() throws Exception { .andExpect(jsonPath("$.code").value(AUTH_UPDATE.getCode())) .andExpect(jsonPath("$.message").value(SUCCESS_REGENERATE_TOKEN.getMessage())) .andExpect(jsonPath("$.data.accessToken").exists()) - .andExpect(jsonPath("$.data.role").value("USER")); + .andExpect(jsonPath("$.data.role").value(USER.name())); } @Test @DisplayName("로그아웃한다.") void logout() throws Exception { - String accessToken = jwtUtil.generateAccessToken(user.getUserId(), Role.USER); + String accessToken = jwtUtil.generateAccessToken(user.getUserId(), USER); mvc.perform(post("/auth/logout") .header(AUTHORIZATION, BEARER + accessToken)) From 45a67edf9535e2eaa3a90baece6f2523d19a9d9b Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Thu, 11 Jan 2024 15:29:29 +0900 Subject: [PATCH 21/24] =?UTF-8?q?RAC-254=20fix:=20=EC=84=A0=EB=B0=B0?= =?UTF-8?q?=EB=A1=9C=20=EB=B3=80=EA=B2=BD=20=EC=8B=9C=20=EC=84=A0=EB=B0=B0?= =?UTF-8?q?=EA=B0=80=EC=9E=85=EC=97=AC=EB=B6=80=20=ED=99=95=EC=9D=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/auth/application/usecase/jwt/JwtUseCase.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/postgraduate/domain/auth/application/usecase/jwt/JwtUseCase.java b/src/main/java/com/postgraduate/domain/auth/application/usecase/jwt/JwtUseCase.java index 6a021173..67ac334d 100644 --- a/src/main/java/com/postgraduate/domain/auth/application/usecase/jwt/JwtUseCase.java +++ b/src/main/java/com/postgraduate/domain/auth/application/usecase/jwt/JwtUseCase.java @@ -1,6 +1,7 @@ package com.postgraduate.domain.auth.application.usecase.jwt; import com.postgraduate.domain.auth.application.dto.res.JwtTokenResponse; +import com.postgraduate.domain.senior.exception.NoneSeniorException; import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.domain.user.domain.entity.constant.Role; import com.postgraduate.domain.user.exception.DeletedUserException; @@ -32,7 +33,7 @@ public JwtTokenResponse signIn(User user) { return adminToken(user); return userToken(user); } - + public void logout(User user) { jwtUtils.makeExpired(user.getUserId()); } @@ -52,7 +53,8 @@ public JwtTokenResponse changeUser(User user) { } public JwtTokenResponse changeSenior(User user) { - checkDelete(user); + if (!SENIOR.equals(user.getRole())) + throw new NoneSeniorException(); return seniorToken(user); } From c9c696aaedfd61b17a42256d4645684f1bd844ae Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Thu, 11 Jan 2024 15:31:25 +0900 Subject: [PATCH 22/24] =?UTF-8?q?RAC-254=20test:=20=ED=9B=84=EB=B0=B0=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EA=B0=80=20=EC=97=86=EB=8A=94=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EB=B3=80=EA=B2=BD=20=EC=98=88=EC=99=B8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/auth/presentation/AuthControllerTest.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java index 089209b6..d4bc43a1 100644 --- a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java @@ -140,6 +140,18 @@ void changeUserToken() throws Exception { .andExpect(jsonPath("$.data.role").value(USER.name())); } + @Test + @DisplayName("대학생으로 가입하지 않은 경우 대학생으로 변경할 수 없다.") + void changeUserTokenWithoutWish() throws Exception { + String token = jwtUtil.generateAccessToken(user.getUserId(), SENIOR); + + mvc.perform(post("/auth/user/token") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(USER_NOT_FOUND.getCode())) + .andExpect(jsonPath("$.message").value(NOT_FOUND_USER.getMessage())); + } + @Test @DisplayName("선배가 후배로 추가 가입합니다.") void changeUser() throws Exception { From 88cf5b16f8a4333dcc4d44b908d65f1ac5b2d0af Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Thu, 11 Jan 2024 15:31:33 +0900 Subject: [PATCH 23/24] =?UTF-8?q?RAC-254=20test:=20=EC=84=A0=EB=B0=B0=20?= =?UTF-8?q?=EC=A0=95=EB=B3=B4=EA=B0=80=20=EC=97=86=EB=8A=94=20=EA=B2=BD?= =?UTF-8?q?=EC=9A=B0=20=EB=B3=80=EA=B2=BD=20=EC=98=88=EC=99=B8=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../auth/presentation/AuthControllerTest.java | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java index d4bc43a1..249924e7 100644 --- a/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java +++ b/src/test/java/com/postgraduate/domain/auth/presentation/AuthControllerTest.java @@ -5,6 +5,8 @@ import com.postgraduate.domain.auth.application.dto.req.*; import com.postgraduate.domain.auth.application.dto.res.KakaoUserInfoResponse; import com.postgraduate.domain.auth.application.usecase.oauth.kakao.KakaoAccessTokenUseCase; +import com.postgraduate.domain.senior.presentation.constant.SeniorResponseCode; +import com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage; import com.postgraduate.domain.user.domain.entity.User; import com.postgraduate.domain.user.domain.repository.UserRepository; import com.postgraduate.domain.wish.domain.entity.Wish; @@ -27,6 +29,8 @@ import static com.postgraduate.domain.senior.presentation.constant.SeniorResponseMessage.CREATE_SENIOR; import static com.postgraduate.domain.user.domain.entity.constant.Role.SENIOR; import static com.postgraduate.domain.user.domain.entity.constant.Role.USER; +import static com.postgraduate.domain.user.presentation.constant.UserResponseCode.USER_NOT_FOUND; +import static com.postgraduate.domain.user.presentation.constant.UserResponseMessage.NOT_FOUND_USER; import static java.time.LocalDateTime.now; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.when; @@ -220,7 +224,10 @@ void changeSenior() throws Exception { @Test @DisplayName("대학생이 대학원생으로 변경한다.") void changeSeniorToken() throws Exception { - String token = jwtUtil.generateAccessToken(user.getUserId(), USER); + User senior = new User(0L, 2L, "mail", "선배", "011", "profile", 0, SENIOR, true, now(), now(), false); + userRepository.save(senior); + + String token = jwtUtil.generateAccessToken(senior.getUserId(), USER); mvc.perform(post("/auth/senior/token") .header(AUTHORIZATION, BEARER + token)) @@ -231,6 +238,18 @@ void changeSeniorToken() throws Exception { .andExpect(jsonPath("$.data.role").value(SENIOR.name())); } + @Test + @DisplayName("대학원생으로 가입하지 않은 경우 대학원생으로 변경할 수 없다.") + void changeSeniorTokenWithoutWish() throws Exception { + String token = jwtUtil.generateAccessToken(user.getUserId(), USER); + + mvc.perform(post("/auth/senior/token") + .header(AUTHORIZATION, BEARER + token)) + .andExpect(status().isOk()) + .andExpect(jsonPath("$.code").value(SeniorResponseCode.NONE_SENIOR.getCode())) + .andExpect(jsonPath("$.message").value(SeniorResponseMessage.NONE_SENIOR.getMessage())); + } + @Test @DisplayName("토큰을 재발급한다.") void refresh() throws Exception { From 6a15f7a5050ad9a8014a88c13152821af15ea8af Mon Sep 17 00:00:00 2001 From: ay-eonii Date: Fri, 12 Jan 2024 02:21:16 +0900 Subject: [PATCH 24/24] =?UTF-8?q?RAC-254=20comment:=20log=20=EC=A0=84?= =?UTF-8?q?=EC=86=A1=20=EC=A3=BC=EC=84=9D=EC=B2=98=EB=A6=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/postgraduate/global/logging/service/LogService.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/com/postgraduate/global/logging/service/LogService.java b/src/main/java/com/postgraduate/global/logging/service/LogService.java index 99bf92fb..c331c872 100644 --- a/src/main/java/com/postgraduate/global/logging/service/LogService.java +++ b/src/main/java/com/postgraduate/global/logging/service/LogService.java @@ -15,6 +15,6 @@ public class LogService { public void save(LogRequest logRequest) throws JsonProcessingException { log.info("log save"); - messageProducer.sendMessage(logRequest); +// messageProducer.sendMessage(logRequest); } }