Skip to content

Commit

Permalink
test: 리뷰 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
hongdosan committed Nov 12, 2023
1 parent 46003be commit c5a3044
Show file tree
Hide file tree
Showing 5 changed files with 59 additions and 8 deletions.
2 changes: 2 additions & 0 deletions src/docs/asciidoc/coupon.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ include::{snippets}/coupons/search/http-response.adoc[]

사용자가 발급 가능한 쿠폰을 선착순으로 발급 받습니다.

---

=== 쿠폰 사용 (진행 중)

사용자가 자신의 보관함에 있는 쿠폰들을 사용합니다.
3 changes: 2 additions & 1 deletion src/main/resources/static/docs/coupon.html
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ <h3 id="_쿠폰_발급_진행_중">쿠폰 발급 (진행 중)</h3>
<pre>사용자가 발급 가능한 쿠폰을 선착순으로 발급 받습니다.</pre>
</div>
</div>
<hr>
</div>
<div class="sect2">
<h3 id="_쿠폰_사용_진행_중">쿠폰 사용 (진행 중)</h3>
Expand All @@ -626,7 +627,7 @@ <h3 id="_쿠폰_사용_진행_중">쿠폰 사용 (진행 중)</h3>
<div id="footer">
<div id="footer-text">
Version 0.0.1-SNAPSHOT<br>
Last updated 2023-11-10 21:20:44 +0900
Last updated 2023-11-12 15:35:21 +0900
</div>
</div>
</body>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import com.moabam.global.error.model.ErrorMessage;
import com.moabam.support.fixture.CouponFixture;
import com.moabam.support.fixture.CouponSnippetFixture;
import com.moabam.support.fixture.ErrorSnippetFixture;

@Transactional
@SpringBootTest
Expand Down Expand Up @@ -66,6 +67,28 @@ void couponController_createCoupon() throws Exception {
.andExpect(status().isCreated());
}

@DisplayName("쿠폰 발급 종료기간 시작기간보다 이전인 쿠폰을 발행한다. - BadRequestException")
@Test
void couponController_createCoupon_BadRequestException() throws Exception {
// Given
String couponType = CouponType.GOLDEN_COUPON.getTypeName();
CreateCouponRequest request = CouponFixture.createCouponRequest(couponType, 2, 1);

// When & Then
mockMvc.perform(post("/admins/coupons")
.contentType(MediaType.APPLICATION_JSON)
.content(objectMapper.writeValueAsString(request)))
.andDo(print())
.andDo(document("admins/coupons",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
CouponSnippetFixture.CREATE_COUPON_REQUEST,
ErrorSnippetFixture.ERROR_MESSAGE_RESPONSE))
.andExpect(status().isBadRequest())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.message").value(ErrorMessage.INVALID_COUPON_PERIOD.getMessage()));
}

@DisplayName("쿠폰명이 중복된 쿠폰을 발행한다. - ConflictException")
@Test
void couponController_createCoupon_ConflictException() throws Exception {
Expand All @@ -82,7 +105,8 @@ void couponController_createCoupon_ConflictException() throws Exception {
.andDo(document("admins/coupons",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint()),
CouponSnippetFixture.CREATE_COUPON_REQUEST))
CouponSnippetFixture.CREATE_COUPON_REQUEST,
ErrorSnippetFixture.ERROR_MESSAGE_RESPONSE))
.andExpect(status().isConflict())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.message").value(ErrorMessage.CONFLICT_COUPON_NAME.getMessage()));
Expand Down Expand Up @@ -111,7 +135,8 @@ void couponController_deleteCoupon_NotFoundException() throws Exception {
.andDo(print())
.andDo(document("admins/coupons/couponId",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint())))
preprocessResponse(prettyPrint()),
ErrorSnippetFixture.ERROR_MESSAGE_RESPONSE))
.andExpect(status().isNotFound())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.message").value(ErrorMessage.NOT_FOUND_COUPON.getMessage()));
Expand Down Expand Up @@ -143,7 +168,8 @@ void couponController_getCouponById_NotFoundException() throws Exception {
.andDo(print())
.andDo(document("coupons/couponId",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint())))
preprocessResponse(prettyPrint()),
ErrorSnippetFixture.ERROR_MESSAGE_RESPONSE))
.andExpect(status().isNotFound())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.message").value(ErrorMessage.NOT_FOUND_COUPON.getMessage()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.transaction.annotation.Transactional;

Expand All @@ -28,6 +29,8 @@
import com.moabam.api.domain.repository.NotificationRepository;
import com.moabam.api.domain.repository.RoomRepository;
import com.moabam.global.common.repository.StringRedisRepository;
import com.moabam.global.error.model.ErrorMessage;
import com.moabam.support.fixture.ErrorSnippetFixture;
import com.moabam.support.fixture.MemberFixture;
import com.moabam.support.fixture.RoomFixture;

Expand Down Expand Up @@ -99,8 +102,11 @@ void notificationController_sendKnockNotification_NotFoundException() throws Exc
.andDo(print())
.andDo(document("notifications/rooms/roomId/members/memberId",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint())))
.andExpect(status().isNotFound());
preprocessResponse(prettyPrint()),
ErrorSnippetFixture.ERROR_MESSAGE_RESPONSE))
.andExpect(status().isNotFound())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.message").value(ErrorMessage.NOT_FOUND_FCM_TOKEN.getMessage()));
}

@DisplayName("GET - 이미 콕 알림을 보낸 대상이다. - ConflictException")
Expand All @@ -115,7 +121,10 @@ void notificationController_sendKnockNotification_ConflictException() throws Exc
.andDo(print())
.andDo(document("notifications/rooms/roomId/members/memberId",
preprocessRequest(prettyPrint()),
preprocessResponse(prettyPrint())))
.andExpect(status().isConflict());
preprocessResponse(prettyPrint()),
ErrorSnippetFixture.ERROR_MESSAGE_RESPONSE))
.andExpect(status().isConflict())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.message").value(ErrorMessage.CONFLICT_KNOCK.getMessage()));
}
}
13 changes: 13 additions & 0 deletions src/test/java/com/moabam/support/fixture/ErrorSnippetFixture.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.moabam.support.fixture;

import static org.springframework.restdocs.payload.JsonFieldType.*;
import static org.springframework.restdocs.payload.PayloadDocumentation.*;

import org.springframework.restdocs.snippet.Snippet;

public class ErrorSnippetFixture {

public static final Snippet ERROR_MESSAGE_RESPONSE = responseFields(
fieldWithPath("message").type(STRING).description("에러 메시지")
);
}

0 comments on commit c5a3044

Please sign in to comment.