Skip to content

Commit 008ff43

Browse files
committed
feat: 포트폴리오 삭제 API 테스트 구현
1 parent dcee3e2 commit 008ff43

File tree

3 files changed

+64
-0
lines changed

3 files changed

+64
-0
lines changed

src/docs/asciidoc/portfolio.adoc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
=== 포트폴리오 생성
44
operation::portfolio/post[snippets="http-request,http-response,request-fields"]
55

6+
=== 포트폴리오 삭제
7+
operation::portfolio/delete[snippetes="http-request,http-response"]
8+
69
=== 내 포트폴리오 조회
710
operation::my-portfolio/get[snippets="http-request,http-response"]
811

src/test/java/com/bigant/gaeme/controller/PortfolioControllerTest.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ RestDocumentationResultHandler getBacktestGetResultHandler() {
171171
requestFields(fieldWithPath("portfolio").type(JsonFieldType.OBJECT).description("포트폴리오"),
172172
fieldWithPath("portfolio.name").type(JsonFieldType.STRING).description("포트폴리오 이름"),
173173
fieldWithPath("portfolio.stocks").type(JsonFieldType.ARRAY).description("보유 주식"),
174+
fieldWithPath("portfolio.deleted").type(JsonFieldType.BOOLEAN).description("삭제 여부"),
174175
fieldWithPath("portfolio.stocks.[].symbol").type(JsonFieldType.STRING).description("주식 심볼"),
175176
fieldWithPath("portfolio.stocks.[].rate").type(JsonFieldType.NUMBER).description("주식 비중"),
176177
fieldWithPath("startDate").type(JsonFieldType.STRING).description("시작 날짜"),
@@ -218,4 +219,35 @@ RestDocumentationResultHandler getMyPortfolioGetHandler() {
218219
);
219220
}
220221

222+
@Test
223+
void delete() throws Exception {
224+
//given
225+
BDDMockito.given(portfolioService.delete(BDDMockito.any(), BDDMockito.any())).willReturn(
226+
PortfolioDto.builder()
227+
.name("test-portfolio")
228+
.stocks(List.of())
229+
.isDeleted(true)
230+
.build()
231+
);
232+
233+
//when
234+
mockMvc.perform(RestDocumentationRequestBuilders.delete("/v1/portfolio?id=1")
235+
.contentType(MediaType.APPLICATION_JSON)
236+
.header(HttpHeaders.AUTHORIZATION, "Bearer token")
237+
.characterEncoding(StandardCharsets.UTF_8))
238+
.andDo(print())
239+
.andExpect(status().isOk())
240+
.andDo(getPortfolioDeleteHandler());
241+
242+
//then
243+
BDDMockito.then(portfolioService).should().delete(BDDMockito.any(), BDDMockito.any());
244+
}
245+
246+
RestDocumentationResultHandler getPortfolioDeleteHandler() {
247+
return document("portfolio/delete",
248+
preprocessRequest(prettyPrint()),
249+
preprocessResponse(prettyPrint())
250+
);
251+
}
252+
221253
}

src/test/java/com/bigant/gaeme/service/PortfolioServiceTest.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -227,4 +227,33 @@ public PortfolioServiceTest(
227227
), result);
228228
}
229229

230+
@Test
231+
void 포트폴리오_삭제_성공() {
232+
//given
233+
User user = TestFixture.getTestUser();
234+
Portfolio portfolio = TestFixture.getTestPortfolio(user);
235+
Stock stock = TestFixture.getTestStock();
236+
237+
userRepository.save(user);
238+
portfolioRepository.save(portfolio);
239+
stockRepository.save(stock);
240+
portfolioStockRepository.save(PortfolioStock.builder()
241+
.rate(100)
242+
.portfolio(portfolio)
243+
.stock(stock)
244+
.build());
245+
246+
//when
247+
PortfolioDto result = portfolioService.delete(user.getId(), portfolio.getId());
248+
249+
//then
250+
Assertions.assertEquals(
251+
PortfolioDto.builder()
252+
.name("test-portfolio")
253+
.stocks(List.of())
254+
.isDeleted(true)
255+
.build(), result
256+
);
257+
}
258+
230259
}

0 commit comments

Comments
 (0)