Skip to content

Commit

Permalink
[release] : 2차 mvp 배포 (#343)
Browse files Browse the repository at this point in the history
  • Loading branch information
devxb authored Jul 13, 2023
2 parents c5115ae + 7ebdc3d commit 7e771cb
Show file tree
Hide file tree
Showing 121 changed files with 4,478 additions and 91 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,21 @@ protected ResultActions findReviewers(String token, String surveyId) throws Exce
);
}


protected ResultActions findFeedback(String token, Long surveyId) throws Exception {
return mockMvc.perform(MockMvcRequestBuilders
.get(String.format("/v2/surveys/%d/feedbacks", surveyId))
.get(String.format("/v2/surveys/%d/feedbacks", surveyId))
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, token)
);
}

protected ResultActions findBookmarkedFeedback(Long surveyId) throws Exception {
return mockMvc.perform(MockMvcRequestBuilders
.get("/v1/feedbacks/bookmarks")
.queryParam("survey-id", surveyId.toString())
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, token)
);
}

Expand All @@ -78,6 +86,25 @@ protected ResultActions findSpecific(String token, Long feedbackId) throws Excep
);
}

protected ResultActions replaceBookmark(String token, String form_question_feedback_id) throws Exception {
return mockMvc.perform(MockMvcRequestBuilders
.patch("/v1/feedbacks/bookmarks")
.queryParam("form-question-feedback-id", form_question_feedback_id)
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
.header(HttpHeaders.AUTHORIZATION, token)
);
}

protected ResultActions findFeedbackByType(Long surveyId, String formType) throws Exception {
return mockMvc.perform(MockMvcRequestBuilders
.get("/v2/feedbacks?survey-id=" + surveyId)
.queryParam("form-type", formType)
.accept(MediaType.APPLICATION_JSON)
.contentType(MediaType.APPLICATION_JSON)
);
}

@Autowired
final void setMockMvc(MockMvc mockMvc) {
this.mockMvc = mockMvc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ public static void assertIsFeedbackFound(ResultActions resultActions) throws Exc
jsonPath("$.question_feedback.[0].feedbacks.[0].reviewer.position").isString()
);
}

public static void assertIsFeedbackNotFound(ResultActions resultActions) throws Exception {
resultActions.andExpectAll(
status().isOk(),
Expand All @@ -75,6 +74,46 @@ public static void assertIsFeedbackNotFound(ResultActions resultActions) throws
);
}

public static void assertIsBookmarkedFeedbackFound(ResultActions resultActions) throws Exception {
resultActions.andExpectAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON),

jsonPath("$.question_feedback").isArray(),
jsonPath("$.question_feedback").isNotEmpty(),
jsonPath("$.question_feedback.[0].question_id").isString(),
jsonPath("$.question_feedback.[0].order").isNumber(),
jsonPath("$.question_feedback.[0].type").isString(),
jsonPath("$.question_feedback.[0].form_type").isString(),
jsonPath("$.question_feedback.[0].title").isString(),

jsonPath("$.question_feedback.[0].feedbacks").isArray(),
jsonPath("$.question_feedback.[0].feedbacks").isNotEmpty(),
jsonPath("$.question_feedback.[0].feedbacks.[0].feedback_id").isString(),
jsonPath("$.question_feedback.[0].feedbacks.[0].form_question_feedback_id").isString(),
jsonPath("$.question_feedback.[0].feedbacks.[0].created_at").isString(),
jsonPath("$.question_feedback.[0].feedbacks.[0].is_read").isBoolean(),
jsonPath("$.question_feedback.[0].feedbacks.[0].bookmark").isNotEmpty(),
jsonPath("$.question_feedback.[0].feedbacks.[0].bookmark.is_bookmarked").isBoolean(),
jsonPath("$.question_feedback.[0].feedbacks.[0].bookmark.bookmarked_at").isString(),

jsonPath("$.question_feedback.[0].feedbacks.[0].reviewer.reviewer_id").isString(),
jsonPath("$.question_feedback.[0].feedbacks.[0].reviewer.nickname").isString(),
jsonPath("$.question_feedback.[0].feedbacks.[0].reviewer.collaboration_experience").isBoolean(),
jsonPath("$.question_feedback.[0].feedbacks.[0].reviewer.position").isString()
);
}

public static void assertIsBookmarkedFeedbackNotFound(ResultActions resultActions) throws Exception {
resultActions.andExpectAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON),

jsonPath("$.question_feedback").isArray(),
jsonPath("$.question_feedback").isEmpty()
);
}

public static void assertIsFeedbackSummaryFound(ResultActions resultActions) throws Exception {
resultActions.andExpectAll(
status().isOk(),
Expand Down Expand Up @@ -126,4 +165,57 @@ public static void assertIsSpecificFound(ResultActions resultActions) throws Exc
);
}

public static void assertIsBookmarkReplaced(ResultActions resultActions) throws Exception {
resultActions.andExpectAll(status().isOk());
}

public static void assertIsFeedbackFoundByTendency(ResultActions resultActions) throws Exception {
resultActions.andExpectAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON),

jsonPath("$.question_feedback").isArray(),
jsonPath("$.question_feedback").isNotEmpty(),

jsonPath("$.question_feedback.[0].question_id").isString(),
jsonPath("$.question_feedback.[0].order").isNumber(),
jsonPath("$.question_feedback.[0].type").isString(),
jsonPath("$.question_feedback.[0].form_type").value("tendency"),
jsonPath("$.question_feedback.[0].title").isString(),
jsonPath("$.question_feedback.[0].choices").isArray()
);
}

public static void assertIsFeedbackFoundByCustom(ResultActions resultActions) throws Exception {
resultActions.andExpectAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON),

jsonPath("$.question_feedback").isArray(),
jsonPath("$.question_feedback").isNotEmpty(),

jsonPath("$.question_feedback.[0].question_id").isString(),
jsonPath("$.question_feedback.[0].order").isNumber(),
jsonPath("$.question_feedback.[0].type").isString(),
jsonPath("$.question_feedback.[0].form_type").value("custom"),
jsonPath("$.question_feedback.[0].title").isString()
);
}

public static void assertIsFeedbackFoundByFormTypeWithNoFeedback(ResultActions resultActions) throws Exception {
resultActions.andExpectAll(
status().isOk(),
content().contentType(MediaType.APPLICATION_JSON),

jsonPath("$.question_feedback").isArray(),
jsonPath("$.question_feedback").isNotEmpty(),

jsonPath("$.question_feedback.[0].question_id").isString(),
jsonPath("$.question_feedback.[0].order").isNumber(),
jsonPath("$.question_feedback.[0].type").isString(),
jsonPath("$.question_feedback.[0].form_type").isString(),
jsonPath("$.question_feedback.[0].title").isString()
);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package me.nalab.luffy.api.acceptance.test.feedback.bookmark;

import static me.nalab.luffy.api.acceptance.test.feedback.FeedbackAcceptanceValidator.*;
import static me.nalab.luffy.api.acceptance.test.feedback.FeedbackCreateRequestFixture.*;

import java.time.Instant;
import java.util.Map;

import org.json.JSONObject;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.domain.EntityScan;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.ResultActions;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;

import me.nalab.auth.mock.api.MockUserRegisterEvent;
import me.nalab.luffy.api.acceptance.test.TargetInitializer;
import me.nalab.luffy.api.acceptance.test.feedback.AbstractFeedbackTestSupporter;
import me.nalab.luffy.api.acceptance.test.feedback.create.request.FeedbackCreateRequest;
import me.nalab.luffy.api.acceptance.test.feedback.create.response.SurveyFindResponse;
import me.nalab.luffy.api.acceptance.test.survey.RequestSample;

@SpringBootTest
@AutoConfigureMockMvc
@TestPropertySource("classpath:h2.properties")
@ComponentScan("me.nalab")
@EnableJpaRepositories(basePackages = {"me.nalab"})
@EntityScan(basePackages = {"me.nalab"})
class BookmarkReplaceAcceptanceTest extends AbstractFeedbackTestSupporter {

@Autowired
private ApplicationEventPublisher applicationEventPublisher;

@Autowired
private TargetInitializer targetInitializer;

private static final ObjectMapper OBJECT_MAPPER;

static {
OBJECT_MAPPER = new ObjectMapper();
OBJECT_MAPPER.setVisibility(PropertyAccessor.FIELD, JsonAutoDetect.Visibility.ANY);
}

@Test
@DisplayName("북마크 교체 성공 인수테스트")
void REPLACE_BOOKMARK_SUCCESS_TEST() throws Exception {

// given
Long targetId = targetInitializer.saveTargetAndGetId("target", Instant.now());
String token = "token";
applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder()
.expectedId(targetId)
.expectedToken(token)
.build());

Long surveyId = createAndGetSurveyId(token, RequestSample.DEFAULT_JSON);
SurveyFindResponse surveyFindResponse = getSurveyFindResponse(surveyId);
FeedbackCreateRequest feedbackCreateRequest = getFeedbackCreateRequest(surveyFindResponse, true, "developer");
createFeedback(surveyId, OBJECT_MAPPER.writeValueAsString(feedbackCreateRequest));
String formQuestionFeedbackId = findFeedbackAndGetFormQuestionFeedbackId(token, surveyId);

// when
ResultActions resultActions = replaceBookmark(token, formQuestionFeedbackId);

// then
assertIsBookmarkReplaced(resultActions);
}

private Long createAndGetSurveyId(String token, String content) throws Exception {
ResultActions resultActions = createSurvey(token, content);
Map<String, Long> surveyIdMap = OBJECT_MAPPER.readValue(
resultActions.andReturn().getResponse().getContentAsString(), new TypeReference<>() {
});
return surveyIdMap.get("survey_id");
}

private SurveyFindResponse getSurveyFindResponse(Long surveyId) throws Exception {
ResultActions resultActions = findSurvey(surveyId);
return OBJECT_MAPPER.readValue(resultActions.andReturn().getResponse().getContentAsString(),
SurveyFindResponse.class);
}

private String findFeedbackAndGetFormQuestionFeedbackId(String token, Long surveyId) throws Exception {
String stringResponse = findFeedback(token, surveyId).andReturn()
.getResponse()
.getContentAsString();
JSONObject jsonObject = new JSONObject(stringResponse);
return jsonObject.getJSONArray("question_feedback").getJSONObject(0).getJSONArray("feedbacks")
.getJSONObject(0).getString("form_question_feedback_id");
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
package me.nalab.luffy.api.acceptance.test.feedback.find;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import me.nalab.auth.mock.api.MockUserRegisterEvent;
import me.nalab.luffy.api.acceptance.test.TargetInitializer;
import me.nalab.luffy.api.acceptance.test.feedback.AbstractFeedbackTestSupporter;
import me.nalab.luffy.api.acceptance.test.feedback.create.request.FeedbackCreateRequest;
import me.nalab.luffy.api.acceptance.test.feedback.create.response.SurveyFindResponse;
import me.nalab.luffy.api.acceptance.test.survey.RequestSample;
import org.json.JSONObject;

import static me.nalab.luffy.api.acceptance.test.feedback.FeedbackAcceptanceValidator.*;
import static me.nalab.luffy.api.acceptance.test.feedback.FeedbackCreateRequestFixture.*;

Expand All @@ -18,17 +30,11 @@
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.web.servlet.ResultActions;

import com.fasterxml.jackson.annotation.JsonAutoDetect;
import com.fasterxml.jackson.annotation.PropertyAccessor;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
import java.time.Instant;
import java.util.Map;

import me.nalab.auth.mock.api.MockUserRegisterEvent;
import me.nalab.luffy.api.acceptance.test.TargetInitializer;
import me.nalab.luffy.api.acceptance.test.feedback.AbstractFeedbackTestSupporter;
import me.nalab.luffy.api.acceptance.test.feedback.create.request.FeedbackCreateRequest;
import me.nalab.luffy.api.acceptance.test.feedback.create.response.SurveyFindResponse;
import me.nalab.luffy.api.acceptance.test.survey.RequestSample;
import static me.nalab.luffy.api.acceptance.test.feedback.FeedbackAcceptanceValidator.*;
import static me.nalab.luffy.api.acceptance.test.feedback.FeedbackCreateRequestFixture.getFeedbackCreateRequest;

@SpringBootTest
@AutoConfigureMockMvc
Expand Down Expand Up @@ -95,6 +101,67 @@ void FIND_FEED_BACK_SUCCESS_ANY_FEEDBACK() throws Exception {
assertIsFeedbackNotFound(resultActions);
}

@Test
@DisplayName("북마크된 피드백 조회 성공 인수테스트")
void FIND_BOOKMARKED_FEED_BACK_SUCCESS() throws Exception {
// given
Long surveyId = setUpSurveyAndFeedbackAndBookmark();

// when
ResultActions resultActions = findBookmarkedFeedback(surveyId);

// then
assertIsBookmarkedFeedbackFound(resultActions);
}

@Test
@DisplayName("북마크된 피드백 조회 성공 인수테스트 - 피드백이 없을때")
void FIND_BOOKMARKED_FEED_BACK_SUCCESS_ANY_FEEDBACK() throws Exception {
// given
Long targetId = targetInitializer.saveTargetAndGetId("hello world", Instant.now());
String token = "mock token";
applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder()
.expectedId(targetId)
.expectedToken(token)
.build());

Long surveyId = createAndGetSurveyId(token, RequestSample.DEFAULT_JSON);

// when
ResultActions resultActions = findBookmarkedFeedback(surveyId);

// then
assertIsBookmarkedFeedbackNotFound(resultActions);
}

private Long setUpSurveyAndFeedbackAndBookmark() throws Exception {
// 유저 생성
Long targetId = targetInitializer.saveTargetAndGetId("hello world", Instant.now());
String token = "mock token";
applicationEventPublisher.publishEvent(MockUserRegisterEvent.builder()
.expectedId(targetId)
.expectedToken(token)
.build());
// 서베이 생성
Long surveyId = createAndGetSurveyId(token, RequestSample.DEFAULT_JSON);
SurveyFindResponse surveyFindResponse = getSurveyFindResponse(surveyId);
FeedbackCreateRequest feedbackCreateRequest = getFeedbackCreateRequest(surveyFindResponse, true, "developer");
// 피드백 생성
createFeedback(surveyId, OBJECT_MAPPER.writeValueAsString(feedbackCreateRequest));

// 피드백 조회
String stringResponse = findFeedback(token, surveyId).andReturn()
.getResponse()
.getContentAsString();
JSONObject jsonObject = new JSONObject(stringResponse);
String feedbackId = jsonObject.getJSONArray("question_feedback").getJSONObject(2).getJSONArray("feedbacks")
.getJSONObject(0).getString("form_question_feedback_id");
// 북마크 처리
replaceBookmark(token, feedbackId);

return surveyId;
}

private Long createAndGetSurveyId(String token, String content) throws Exception {
ResultActions resultActions = createSurvey(token, content);
Map<String, Long> surveyIdMap = OBJECT_MAPPER.readValue(
Expand Down
Loading

0 comments on commit 7e771cb

Please sign in to comment.