diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md index 2226925..7e58900 100644 --- a/.github/pull_request_template.md +++ b/.github/pull_request_template.md @@ -1,8 +1,8 @@ ### PR 타입(하나 이상의 PR 타입을 선택해주세요) --[] 기능 추가 --[] 기능 삭제 --[] 버그 수정 --[] 의존성, 환경 변수, 빌드 관련 코드 업데이트 +- [ ] 기능 추가 +- [ ] 기능 삭제 +- [ ] 버그 수정 +- [ ] 의존성, 환경 변수, 빌드 관련 코드 업데이트 ### 반영 브랜치 ex) feat/login -> dev diff --git a/build.gradle b/build.gradle index 5e5b75d..9a82759 100644 --- a/build.gradle +++ b/build.gradle @@ -39,8 +39,8 @@ dependencies { implementation 'io.sentry:sentry-logback:6.25.2' //swagger implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.1.0' - - + //h2 + implementation 'com.h2database:h2:1.4.200' } tasks.named('test') { @@ -48,4 +48,3 @@ tasks.named('test') { } jar { enabled = false } - diff --git a/src/main/java/com/management/web/domain/GiftcardProduct.java b/src/main/java/com/management/web/domain/GiftcardProduct.java index f7bcc26..975e091 100644 --- a/src/main/java/com/management/web/domain/GiftcardProduct.java +++ b/src/main/java/com/management/web/domain/GiftcardProduct.java @@ -1,6 +1,7 @@ package com.management.web.domain; import jakarta.persistence.*; +import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; import lombok.ToString; @@ -25,7 +26,12 @@ public class GiftcardProduct { @Column(name = "sale_YN") private Boolean saleYN; -// -// @OneToMany(mappedBy = "giftcardProduct") -// private List giftcardOrderList; + + @Builder + public GiftcardProduct(String name, Long price, String image, Boolean saleYN) { + this.name = name; + this.price = price; + this.image = image; + this.saleYN = saleYN; + } } diff --git a/src/main/java/com/management/web/repository/GiftcardProductRepository.java b/src/main/java/com/management/web/repository/GiftcardProductRepository.java index c601252..0d31ea6 100644 --- a/src/main/java/com/management/web/repository/GiftcardProductRepository.java +++ b/src/main/java/com/management/web/repository/GiftcardProductRepository.java @@ -14,4 +14,6 @@ public interface GiftcardProductRepository extends JpaRepository findBySaleYNOrderByPriceAsc(Boolean saleYN); + + GiftcardProduct save(GiftcardProduct giftcardProduct); } diff --git a/src/test/java/com/management/web/api/GiftshopTest.java b/src/test/java/com/management/web/api/GiftshopTest.java new file mode 100644 index 0000000..f9ee8d1 --- /dev/null +++ b/src/test/java/com/management/web/api/GiftshopTest.java @@ -0,0 +1,68 @@ +package com.management.web.api; + +import com.management.chatbot.service.MemberService; +import com.management.chatbot.service.dto.MemberResponseDto; +import com.management.chatbot.service.dto.MemberSaveRequestDto; +import com.management.web.domain.GiftcardProduct; +import com.management.web.repository.GiftcardProductRepository; +import com.management.web.service.GiftcardService; +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.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; +import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; +import org.springframework.test.web.servlet.result.MockMvcResultHandlers; +import org.springframework.test.web.servlet.result.MockMvcResultMatchers; + +@SpringBootTest +@AutoConfigureMockMvc +public class GiftshopTest { + + @Autowired + private MemberService memberService; + + @Autowired + private GiftcardProductRepository giftcardProductRepository; + + @Autowired + MockMvc mvc; + + String kakaoId = "test"; + + @BeforeEach + void setUp() { + memberService.save(MemberSaveRequestDto.builder() + .kakaoId(kakaoId) + .username("test") + .reward(0L) + .savedMoney(0L) + .build()); + + giftcardProductRepository.save(GiftcardProduct.builder() + .name("test") + .price(10000L) + .saleYN(true) + .build()); + } + @Test + @DisplayName("기프티콘 목록 API 테스트") + void getGiftcardList() throws Exception { + // given + MemberResponseDto member = memberService.findByKakaoId(kakaoId); + String username = member.getUsername(); + Long reward = member.getReward(); + + // when + + // then + mvc.perform( + MockMvcRequestBuilders.get("/shop/{kakaoId}", kakaoId)) + .andExpect(MockMvcResultMatchers.status().isOk()) + .andExpect(MockMvcResultMatchers.jsonPath("$.member.username").value(username)) + .andExpect(MockMvcResultMatchers.jsonPath("$.member.reward").value(reward)) + .andDo(MockMvcResultHandlers.print()); + } +} diff --git a/src/test/resources/application.yml b/src/test/resources/application.yml new file mode 100644 index 0000000..a86f772 --- /dev/null +++ b/src/test/resources/application.yml @@ -0,0 +1,18 @@ +spring: + datasource: + driver-class-name: org.h2.Driver + url: jdbc:h2:mem:public;MODE=PostgreSQL;INIT=CREATE DOMAIN IF NOT EXISTS JSONB AS JSON; + username: sa + password: + h2: + console: + enabled: true + profiles: + active: local + jpa: + database-platform: org.hibernate.dialect.H2Dialect + database: h2 + hibernate: + ddl-auto: create-drop + open-in-view: false + show-sql: true