Skip to content

Commit

Permalink
Merge pull request #52 from nhnacademy-be4-ckin/develop
Browse files Browse the repository at this point in the history
오늘의 재배포
  • Loading branch information
nueag authored Mar 20, 2024
2 parents 1eb1e2a + d0a41ce commit 9e67671
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 57 deletions.
61 changes: 55 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,12 @@
<version>4.5.14</version>
</dependency>

<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
Expand Down Expand Up @@ -147,12 +153,55 @@
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<skipTests>true</skipTests>
</configuration>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>book</doctype>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-asciidoctor</artifactId>
<version>${spring-restdocs.version}</version>
</dependency>
</dependencies>
</plugin>

<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.outputDirectory}/static/docs
</outputDirectory>
<resources>
<resource>
<directory>
${project.build.directory}/generated-docs
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.Date;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.ToString;

/**
* 쿠폰 반환시 사용하는 dto 입니다.
Expand All @@ -12,6 +13,7 @@
* @version : 2024. 02. 12
*/
@Getter
@ToString
@NoArgsConstructor
public class GetCouponResponseDto {
private Long id;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,18 @@ public ResponseEntity<Void> deleteCouponTemplate(@PathVariable("couponTemplateId
return ResponseEntity.ok().build();
}

/**
* 쿠폰 템플릿 사용여부를 변경하는 메서드 입니다.
*
* @param templateId 템플릿 아이디
* @param state 사용여부
* @return 200 OK
*/
@PutMapping("/{templateId}")
public ResponseEntity<Void> updateTemplateStatus(@PathVariable("templateId") Long templateId,
@RequestParam("state") Boolean state) {
couponTemplateService.updateCouponTemplateStatus(templateId, state);

return ResponseEntity.ok().build();
}
// /**
// * 쿠폰 템플릿 사용여부를 변경하는 메서드 입니다.
// *
// * @param templateId 템플릿 아이디
// * @param state 사용여부
// * @return 200 OK
// */
// @PutMapping("/{templateId}")
// public ResponseEntity<Void> updateTemplateStatus(@PathVariable("templateId") Long templateId,
// @RequestParam("state") Boolean state) {
// couponTemplateService.updateCouponTemplateStatus(templateId, state);
//
// return ResponseEntity.ok().build();
// }
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.restdocs.AutoConfigureRestDocs;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.domain.PageImpl;
Expand All @@ -25,6 +26,13 @@
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.Mockito.when;
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessRequest;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.preprocessResponse;
import static org.springframework.restdocs.operation.preprocess.Preprocessors.prettyPrint;
import static org.springframework.restdocs.payload.PayloadDocumentation.responseFields;
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
Expand All @@ -36,6 +44,7 @@
* @author : gaeun
* @version : 2024. 02. 23
*/
@AutoConfigureRestDocs
@WebMvcTest(CouponController.class)
class CouponControllerTest {
@Autowired
Expand Down Expand Up @@ -90,6 +99,17 @@ void testCreateCoupon() throws Exception {
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isCreated())
.andDo(print());
// .andDo(document("coupon/createCoupon/success",
// preprocessRequest(prettyPrint()),
// preprocessResponse(prettyPrint()),
// requestParameters(
// parameterWithName("page").description("지정할 페이지"),
// parameterWithName("size").description("한 페이지 당 표시할 개수")
// ),
// responseFields(
//
//
// )));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ void setUp() {
.name("1월 생일 쿠폰")
.amount(100L)
.type(birthType)
.duration(30)
.state(true)
.build();
entityManager.persist(birthCouponTemplate);

Expand All @@ -78,6 +80,8 @@ void setUp() {
.name("사람은 무엇으로 사는가 - 도서 쿠폰")
.amount(100L)
.type(bookType)
.duration(30)
.state(true)
.build();
entityManager.persist(bookCouponTemplate);

Expand All @@ -88,6 +92,8 @@ void setUp() {
.name("소설 - 카테고리 쿠폰")
.amount(100L)
.type(categoryType)
.duration(30)
.state(true)
.build();
entityManager.persist(categoryCouponTemplate);

Expand Down Expand Up @@ -235,16 +241,15 @@ void testGetCouponByMember() {
void testGetCouponForBuyList() {
List<GetCouponResponseDto> results = couponRepository.getCouponForBuyList(1L, List.of(1L), List.of(1L));

Assertions.assertThat(results.get(0).getMemberId()).isEqualTo(birthCoupon.getMemberId());
Assertions.assertThat(results.get(0).getCouponTemplateId()).isEqualTo(birthCoupon.getCouponTemplateId());
Assertions.assertThat(results.get(0).getUsedDate().getMonth()).isEqualTo(birthCoupon.getUsedDate().getMonth());
Assertions.assertThat(results.get(0).getExpirationDate().getMonth()).isEqualTo(birthCoupon.getExpirationDate().getMonth());
Assertions.assertThat(results.get(0).getIssueDate().getMonth()).isEqualTo(birthCoupon.getIssueDate().getMonth());
Assertions.assertThat(results.get(0).getPolicyId()).isEqualTo(birthCouponTemplate.getPolicyId());
Assertions.assertThat(results.get(0).getBookId()).isEqualTo(birthCouponTemplate.getBookId());
Assertions.assertThat(results.get(0).getCategoryId()).isEqualTo(birthCouponTemplate.getCategoryId());
Assertions.assertThat(results.get(0).getName()).isEqualTo(birthCouponTemplate.getName());
Assertions.assertThat(results.get(0).getTypeId()).isEqualTo(birthType.getId());
Assertions.assertThat(results.get(0).getMemberId()).isEqualTo(categoryCoupon.getMemberId());
Assertions.assertThat(results.get(0).getCouponTemplateId()).isNotNull();
Assertions.assertThat(results.get(0).getExpirationDate().getMonth()).isEqualTo(categoryCoupon.getExpirationDate().getMonth());
Assertions.assertThat(results.get(0).getIssueDate().getMonth()).isEqualTo(categoryCoupon.getIssueDate().getMonth());
Assertions.assertThat(results.get(0).getPolicyId()).isEqualTo(categoryCouponTemplate.getPolicyId());
Assertions.assertThat(results.get(0).getBookId()).isEqualTo(categoryCouponTemplate.getBookId());
Assertions.assertThat(results.get(0).getCategoryId()).isEqualTo(categoryCouponTemplate.getCategoryId());
Assertions.assertThat(results.get(0).getName()).isEqualTo(categoryCouponTemplate.getName());
Assertions.assertThat(results.get(0).getTypeId()).isEqualTo(categoryType.getId());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,33 +126,34 @@ void createCouponTemplateTest_X() throws Exception {
.andDo(print());
}

@Test
@DisplayName("쿠폰 템플릿 수정 테스트: 성공")
void updateCouponTemplateTest() throws Exception {
ReflectionTestUtils.setField(couponTemplateRequestDto, "policyId", 1L);
ReflectionTestUtils.setField(couponTemplateRequestDto, "bookId", 1L);
ReflectionTestUtils.setField(couponTemplateRequestDto, "categoryId", 1L);
ReflectionTestUtils.setField(couponTemplateRequestDto, "typeId", 1L);
ReflectionTestUtils.setField(couponTemplateRequestDto, "name", "해리포터 전집");
ReflectionTestUtils.setField(couponTemplateRequestDto, "amount", 100L);

mockMvc.perform(put("/coupon/couponTemplate/{couponTemplateId}", 1L)
.content(objectMapper.writeValueAsString(couponTemplateRequestDto))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(print());
}

@Test
@DisplayName("쿠폰 템플릿 수정 테스트: 실패")
void updateCouponTemplateTest_X() throws Exception {

mockMvc.perform(put("/coupon/couponTemplate/{couponTemplateId}", 1L)
.content(objectMapper.writeValueAsString(couponTemplateRequestDto))
.contentType(MediaType.APPLICATION_JSON))
.andExpect(status().is4xxClientError())
.andDo(print());
}
// @Test
// @DisplayName("쿠폰 템플릿 수정 테스트: 성공")
// void updateCouponTemplateTest() throws Exception {
// ReflectionTestUtils.setField(couponTemplateRequestDto, "policyId", 1L);
// ReflectionTestUtils.setField(couponTemplateRequestDto, "bookId", 1L);
// ReflectionTestUtils.setField(couponTemplateRequestDto, "categoryId", 1L);
// ReflectionTestUtils.setField(couponTemplateRequestDto, "typeId", 1L);
// ReflectionTestUtils.setField(couponTemplateRequestDto, "name", "해리포터 전집");
// ReflectionTestUtils.setField(couponTemplateRequestDto, "amount", 100L);
// ReflectionTestUtils.setField(couponTemplateRequestDto, "state", null);
//
// mockMvc.perform(put("/coupon/couponTemplate/{couponTemplateId}", 1L)
// .content(objectMapper.writeValueAsString(couponTemplateRequestDto))
// .contentType(MediaType.APPLICATION_JSON))
// .andExpect(status().isOk())
// .andDo(print());
// }
//
// @Test
// @DisplayName("쿠폰 템플릿 수정 테스트: 실패")
// void updateCouponTemplateTest_X() throws Exception {
//
// mockMvc.perform(put("/coupon/couponTemplate/{couponTemplateId}", 1L)
// .content(objectMapper.writeValueAsString(couponTemplateRequestDto))
// .contentType(MediaType.APPLICATION_JSON))
// .andExpect(status().is4xxClientError())
// .andDo(print());
// }

@Test
@DisplayName("쿠폰 템플릿 삭제 테스트")
Expand Down

0 comments on commit 9e67671

Please sign in to comment.