refactor(store-service): favorite store 테스트 코드 작성
favorite store 테스트 코드 작성
This commit is contained in:
43
customer-vue/src/components/SlideStore.vue
Normal file
43
customer-vue/src/components/SlideStore.vue
Normal file
@@ -0,0 +1,43 @@
|
||||
<template>
|
||||
<div >
|
||||
<v-slide-group
|
||||
show-arrows="desktop"
|
||||
>
|
||||
<v-slide-item
|
||||
v-for="item in storeList"
|
||||
:key="item.id"
|
||||
>
|
||||
<v-card
|
||||
elevation="7"
|
||||
class="my-3 mx-3"
|
||||
height="250"
|
||||
width="165"
|
||||
>
|
||||
<v-img
|
||||
height="165"
|
||||
width="165"
|
||||
src="https://cdn.vuetifyjs.com/images/cards/cooking.png"
|
||||
></v-img>
|
||||
<v-card-subtitle style="white-space:nowrap; overflow:hidden; text-overflow:ellipsis;">{{item.name}}</v-card-subtitle>
|
||||
<v-card-text>
|
||||
거리 : {{item.distance}}
|
||||
</v-card-text>
|
||||
</v-card>
|
||||
</v-slide-item>
|
||||
</v-slide-group>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
export default {
|
||||
name: "SlideStore",
|
||||
props:{
|
||||
storeList:Array,
|
||||
},
|
||||
|
||||
}
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
||||
@@ -23,7 +23,7 @@ spring:
|
||||
globalcors:
|
||||
cors-configurations:
|
||||
'[/**]':
|
||||
allowedOrigins: "http://localhost:8080"
|
||||
allowedOrigins: "http://just-pickup.com:8081"
|
||||
allowedMethods:
|
||||
- GET
|
||||
- POST
|
||||
|
||||
@@ -1 +1 @@
|
||||
VUE_APP_OWNER_SERVICE_BASEURL=http://localhost:8001
|
||||
VUE_APP_OWNER_SERVICE_BASEURL=http://just-pickup.com:8001
|
||||
@@ -9,7 +9,7 @@ export default {
|
||||
}
|
||||
}
|
||||
|
||||
const res = await axios.get("http://localhost:8001/user-service/auth/reissue", config);
|
||||
const res = await axios.get(process.env.VUE_APP_OWNER_SERVICE_BASEURL+"/user-service/auth/reissue", config);
|
||||
|
||||
const accessToken = res.data.data.accessToken;
|
||||
jwt.saveToken(accessToken);
|
||||
@@ -21,6 +21,6 @@ export default {
|
||||
requestCheckAccessToken() {
|
||||
axios.defaults.headers.common['Authorization'] = "Bearer " + jwt.getToken();
|
||||
|
||||
return axios.get("http://localhost:8001/user-service/auth/check/access-token");
|
||||
return axios.get(process.env.VUE_APP_OWNER_SERVICE_BASEURL+"/user-service/auth/check/access-token");
|
||||
}
|
||||
}
|
||||
@@ -2,12 +2,12 @@ import axios from "axios";
|
||||
|
||||
export default {
|
||||
getCategoryList(){
|
||||
return axios.get(process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/category');
|
||||
return axios.get(process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/api/customer/category');
|
||||
},
|
||||
putCategoryList(data){
|
||||
return axios({
|
||||
method:'put',
|
||||
url:process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/category',
|
||||
url:process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/api/customer/category',
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json;charset=UTF-8'
|
||||
@@ -17,12 +17,14 @@ export default {
|
||||
})
|
||||
},
|
||||
getItemById(itemId){
|
||||
return axios.get(process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/item/'+itemId)
|
||||
return axios.get(process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/api/customer/item/'+itemId)
|
||||
},
|
||||
saveItem(method, itemData){
|
||||
const _url = process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/api/customer/item'+(method==='put'?+"/"+itemData.itemId:'')
|
||||
console.log(_url)
|
||||
return axios({
|
||||
method:method,
|
||||
url: process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/item',
|
||||
url: _url,
|
||||
headers: {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json;charset=UTF-8'
|
||||
@@ -31,4 +33,7 @@ export default {
|
||||
responseType:'json'
|
||||
})
|
||||
},
|
||||
getMenu(searchParam){
|
||||
return axios.get(process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/api/customer/item',searchParam);
|
||||
},
|
||||
}
|
||||
@@ -12,7 +12,7 @@ export default {
|
||||
}
|
||||
|
||||
try {
|
||||
const response = await axios.post("http://localhost:8001/user-service/login", user);
|
||||
const response = await axios.post(process.env.VUE_APP_OWNER_SERVICE_BASEURL+"/user-service/login", user);
|
||||
const data = response.data.data;
|
||||
|
||||
jwt.saveToken(data.accessToken);
|
||||
|
||||
@@ -146,12 +146,7 @@ export default {
|
||||
word: vm.word,
|
||||
page: vm.page-1
|
||||
}
|
||||
this.$axios({
|
||||
method:'get',
|
||||
url:process.env.VUE_APP_OWNER_SERVICE_BASEURL+'/store-service/item',
|
||||
params : searchParam,
|
||||
responseType:'json'
|
||||
})
|
||||
store.getMenu(searchParam)
|
||||
.then(function (response) {
|
||||
const page = response.data.data.page;
|
||||
vm.menus = response.data.data.itemList;
|
||||
@@ -203,7 +198,6 @@ export default {
|
||||
method='put'
|
||||
else
|
||||
method='post'
|
||||
|
||||
store.saveItem(method,itemData)
|
||||
.then(response => console.log(response))
|
||||
.catch(reason => console.log(reason))
|
||||
|
||||
@@ -2,4 +2,7 @@ module.exports = {
|
||||
transpileDependencies: [
|
||||
'vuetify'
|
||||
],
|
||||
devServer:{
|
||||
allowedHosts: ['just-pickup.com'],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -81,4 +81,7 @@ operation::put-categoryList[snippets='curl-request,http-request,http-response,re
|
||||
=== 매장 검색 조회
|
||||
operation::searchStore-get[snippets='curl-request,http-request,http-response,request-parameters,response-fields']
|
||||
|
||||
=== 자주찾는 매장
|
||||
operation::favoriteStore-get[snippets='curl-request,http-request,http-response,request-headers,request-parameters,response-fields']
|
||||
|
||||
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
package com.justpickup.storeservice.domain.category.dto;
|
||||
|
||||
import com.justpickup.storeservice.domain.category.entity.Category;
|
||||
import com.justpickup.storeservice.domain.category.web.CategoryController;
|
||||
import com.justpickup.storeservice.domain.category.web.CategoryOwnerApiController;
|
||||
import com.justpickup.storeservice.domain.item.dto.ItemDto;
|
||||
import com.justpickup.storeservice.domain.item.entity.Item;
|
||||
import com.justpickup.storeservice.domain.store.entity.Store;
|
||||
import lombok.*;
|
||||
|
||||
@@ -32,19 +31,18 @@ public class CategoryDto {
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public CategoryDto(CategoryController.PutCategoryRequest.Category category) {
|
||||
public CategoryDto(CategoryOwnerApiController.PutCategoryRequest.Category category) {
|
||||
this.id = category.getCategoryId();
|
||||
this.name = category.getName();
|
||||
this.order = category.getOrder();
|
||||
}
|
||||
|
||||
public static Category createCategory(CategoryDto categoryDto){
|
||||
Category category = Category.createCategory(
|
||||
return Category.createCategory(
|
||||
categoryDto.getId()
|
||||
,categoryDto.getName()
|
||||
, categoryDto.getOrder()
|
||||
, categoryDto.getStore());
|
||||
return category;
|
||||
}
|
||||
|
||||
public void setStore(Store store){
|
||||
|
||||
@@ -10,14 +10,14 @@ import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@RestController
|
||||
@RequiredArgsConstructor
|
||||
@Slf4j
|
||||
public class CategoryController {
|
||||
@RequestMapping("/api/owner")
|
||||
public class CategoryOwnerApiController {
|
||||
|
||||
private final CategoryService categoryService;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package com.justpickup.storeservice.domain.category.web;
|
||||
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.justpickup.storeservice.config.TestConfig;
|
||||
import com.justpickup.storeservice.domain.category.dto.CategoryDto;
|
||||
@@ -15,7 +14,6 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Import;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.restdocs.mockmvc.MockMvcRestDocumentation;
|
||||
import org.springframework.restdocs.request.RequestDocumentation;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
|
||||
@@ -25,15 +23,14 @@ import org.springframework.test.web.servlet.result.MockMvcResultMatchers;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.*;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.parameterWithName;
|
||||
import static org.springframework.restdocs.request.RequestDocumentation.requestParameters;
|
||||
|
||||
@WebMvcTest(CategoryController.class)
|
||||
@WebMvcTest(CategoryOwnerApiController.class)
|
||||
@Import(TestConfig.class)
|
||||
@AutoConfigureRestDocs(uriHost = "127.0.0.1",uriPort = 8001)
|
||||
class CategoryControllerTest {
|
||||
class CategoryOwnerApiControllerTest {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
@@ -101,30 +98,30 @@ class CategoryControllerTest {
|
||||
|
||||
//given
|
||||
Long storeId = 1L;
|
||||
List<CategoryController.PutCategoryRequest.Category> categoryList = new ArrayList<>();
|
||||
categoryList.add(CategoryController.PutCategoryRequest.Category.builder()
|
||||
List<CategoryOwnerApiController.PutCategoryRequest.Category> categoryList = new ArrayList<>();
|
||||
categoryList.add(CategoryOwnerApiController.PutCategoryRequest.Category.builder()
|
||||
.categoryId(10L)
|
||||
.name("카테고리1")
|
||||
.order(2)
|
||||
.build());
|
||||
|
||||
categoryList.add(CategoryController.PutCategoryRequest.Category.builder()
|
||||
categoryList.add(CategoryOwnerApiController.PutCategoryRequest.Category.builder()
|
||||
.categoryId(11L)
|
||||
.name("카테고리2")
|
||||
.order(1)
|
||||
.build());
|
||||
|
||||
List<CategoryController.PutCategoryRequest.Category> deletedList = new ArrayList<>();
|
||||
List<CategoryOwnerApiController.PutCategoryRequest.Category> deletedList = new ArrayList<>();
|
||||
|
||||
deletedList.add(CategoryController.PutCategoryRequest.Category.builder()
|
||||
deletedList.add(CategoryOwnerApiController.PutCategoryRequest.Category.builder()
|
||||
.categoryId(11L)
|
||||
.name("Non Coffee")
|
||||
.order(3)
|
||||
.build());
|
||||
|
||||
|
||||
CategoryController.PutCategoryRequest putCategoryRequest =
|
||||
CategoryController.PutCategoryRequest.builder()
|
||||
CategoryOwnerApiController.PutCategoryRequest putCategoryRequest =
|
||||
CategoryOwnerApiController.PutCategoryRequest.builder()
|
||||
.storeId(storeId)
|
||||
.categoryList(categoryList)
|
||||
.deletedList(deletedList)
|
||||
@@ -0,0 +1,105 @@
|
||||
package com.justpickup.storeservice.domain.store.web;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.justpickup.storeservice.config.TestConfig;
|
||||
import com.justpickup.storeservice.domain.favoritestore.repository.FavoriteStoreRepository;
|
||||
import com.justpickup.storeservice.domain.store.dto.SearchStoreCondition;
|
||||
import com.justpickup.storeservice.domain.store.dto.SearchStoreResult;
|
||||
import com.justpickup.storeservice.domain.store.repository.StoreRepository;
|
||||
import com.justpickup.storeservice.domain.store.service.StoreService;
|
||||
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.context.annotation.Import;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.springframework.restdocs.headers.HeaderDocumentation.headerWithName;
|
||||
import static org.springframework.restdocs.headers.HeaderDocumentation.requestHeaders;
|
||||
import static org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.document;
|
||||
import static org.springframework.restdocs.payload.PayloadDocumentation.fieldWithPath;
|
||||
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.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
@WebMvcTest(StoreCustomerApiController.class)
|
||||
@Import(TestConfig.class)
|
||||
@AutoConfigureRestDocs(uriHost = "127.0.0.1", uriPort = 8000)
|
||||
class StoreCustomerApiControllerTest {
|
||||
|
||||
@Autowired
|
||||
MockMvc mockMvc;
|
||||
|
||||
@MockBean
|
||||
StoreService storeService;
|
||||
|
||||
@MockBean
|
||||
StoreRepository storeRepository;
|
||||
|
||||
@MockBean
|
||||
FavoriteStoreRepository favoriteStoreRepository;
|
||||
|
||||
|
||||
@Test
|
||||
@DisplayName("즐겨찾는 매장")
|
||||
void getFavoriteStore() throws Exception {
|
||||
//given
|
||||
|
||||
double latitude = 37.5403912;
|
||||
double longitude = 126.9438922;
|
||||
SearchStoreCondition condition = new SearchStoreCondition(latitude, longitude, null);
|
||||
given(storeService.findFavoriteStore(any(SearchStoreCondition.class),eq(2L)))
|
||||
.willReturn(getWillReturnSearchStore());
|
||||
|
||||
|
||||
//when
|
||||
String s = new ObjectMapper()
|
||||
.writeValueAsString(condition);
|
||||
|
||||
ResultActions resultActions = mockMvc.perform(get("/api/customer/store/favorite")
|
||||
.param("latitude",String.valueOf(condition.getLatitude()))
|
||||
.param("longitude",String.valueOf(condition.getLongitude()))
|
||||
.header("user-id","2")
|
||||
);
|
||||
|
||||
//then
|
||||
resultActions.andExpect(status().isOk())
|
||||
.andDo(print())
|
||||
.andDo(document("favoriteStore-get",
|
||||
requestHeaders(
|
||||
headerWithName("user-id").description("로그인한 유저 id")
|
||||
),
|
||||
requestParameters(
|
||||
parameterWithName("latitude").description("고객의 위도 [필수]"),
|
||||
parameterWithName("longitude").description("고객의 경도 [필수]")
|
||||
),
|
||||
responseFields(
|
||||
fieldWithPath("code").description("결과 코드 SUCCESS/ERROR"),
|
||||
fieldWithPath("message").description("메시지"),
|
||||
fieldWithPath("data[*].id").description("매장 고유번호"),
|
||||
fieldWithPath("data[*].name").description("매장 이름"),
|
||||
fieldWithPath("data[*].distance").description("고객과의 거리차이 m/km")
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
private List<SearchStoreResult> getWillReturnSearchStore(){
|
||||
SearchStoreResult result_1 = new SearchStoreResult(1L, "이디야커피 마포오벨리스크점", 145.11980562222007);
|
||||
SearchStoreResult result_2 = new SearchStoreResult(2L, "만랩커피 마포점", 150.97181089895466);
|
||||
SearchStoreResult result_3 = new SearchStoreResult(3L, "커피온리 마포역점", 341.25696860337655);
|
||||
|
||||
return List.of(result_1,result_2,result_3);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user