-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #24 from DAY0522/feature/giftshop-list-test-code
독립적인 test code DB 환경 구축(h2 database)
- Loading branch information
Showing
6 changed files
with
103 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |