Skip to content

Commit

Permalink
[feat #177] 질문 글 작성 응답 DTO 잔여 크레딧 추가 (#180)
Browse files Browse the repository at this point in the history
* [feat #177] 질문 글 작성 응답 DTO 잔여 크레딧 추가

* [test #177] 질문 글 작성 단위 테스트 잔여 크레딧 검증

* [test #177] 질문 글 작성 통합 테스트 잔여 크레딧 검증
  • Loading branch information
dudxo authored Jan 1, 2025
1 parent fc2dd72 commit b8991ed
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ public static QuestionPostDetailResponse toQuestionPostDetailResponse(
}

public static RegisterQuestionPostResponse toRegisterQuestionPostResponse(
QuestionPost questionPost
QuestionPost questionPost, Member member
) {
Member member = questionPost.getMember();
return new RegisterQuestionPostResponse(
questionPost.getId(),
questionPost.getTitle(),
Expand All @@ -74,6 +73,7 @@ public static RegisterQuestionPostResponse toRegisterQuestionPostResponse(
member.getJobGroup().getLabel(),
member.getProfileImageNo()
),
member.getCredit(),
questionPost.getCreatedAt().toString()
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public record RegisterQuestionPostResponse(
String targetJobGroup,
String status,
MemberInfo memberInfo,
int remainingCredit,
String createdAt
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public RegisterQuestionPostResponse registerQuestionPost(

QuestionPost questionPost = QuestionPostMapper.toQuestionPost(request, member);
return QuestionPostMapper.toRegisterQuestionPostResponse(
questionPostRepository.save(questionPost)
questionPostRepository.save(questionPost),
member
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,13 @@ void teardown() {
@DisplayName("[질문글을 등록할 수 있다.]")
@Test
void registerQuestionPost() throws Exception {
final int reward = 2_000;

RegisterQuestionPostRequest request = new RegisterQuestionPostRequest(
"제목",
"정정기간에 여석이 있을까요?",
List.of("image1.jpg", "image2.jpg"),
2000,
reward,
"공업"
);

Expand All @@ -86,7 +88,8 @@ void registerQuestionPost() throws Exception {
.andExpect(jsonPath("$.targetJobGroup").value(request.targetJobGroup()))
.andExpect(jsonPath("$.memberInfo.memberId").value(loginMember.getId()))
.andExpect(jsonPath("$.memberInfo.nickname").value(loginMember.getNickname()))
.andExpect(jsonPath("$.memberInfo.memberJobGroup").value(loginMember.getJobGroup().getLabel()));
.andExpect(jsonPath("$.memberInfo.memberJobGroup").value(loginMember.getJobGroup().getLabel()))
.andExpect(jsonPath("$.remainingCredit").value(loginMember.getCredit() - reward));
}

@DisplayName("[보유 크레딧이 부족하면 질문글을 등록할 수 없다.]")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ void registerQuestionPost() {
() -> assertThat(response.content()).isEqualTo(request.content()),
() -> assertThat(response.reward()).isEqualTo(request.reward()),
() -> assertThat(response.targetJobGroup()).isEqualTo(request.targetJobGroup()),
() -> assertThat(response.status()).isEqualTo(QuestionPostStatus.ANSWER_WAITING.getStatus())
() -> assertThat(response.status()).isEqualTo(QuestionPostStatus.ANSWER_WAITING.getStatus()),
() -> assertThat(response.remainingCredit()).isEqualTo(member.getCredit())
);
}

Expand Down

0 comments on commit b8991ed

Please sign in to comment.