Skip to content

Commit

Permalink
feat: add validation and test code
Browse files Browse the repository at this point in the history
  • Loading branch information
songyi00 committed Feb 11, 2024
1 parent 36fdb93 commit 5cfe621
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package nexters.payout.apiserver.stock.application.dto.request;

import jakarta.validation.Valid;
import jakarta.validation.constraints.Size;

import java.util.List;

public record SectorRatioRequest(
@Valid
@Size(min = 1)
List<TickerShare> tickerShares
) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package nexters.payout.apiserver.stock.application.dto.request;

import jakarta.validation.constraints.Min;

public record TickerShare(
String ticker,

@Min(value = 1)
Integer share
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
class StockControllerTest extends IntegrationTest {

@Test
void 티커가_1개_미만일_경우_예외가_발생한다() {
void 빈_리스트로_요청한_경우_예외가_발생한다() {
// given
SectorRatioRequest request = new SectorRatioRequest(List.of());

Expand All @@ -44,6 +44,25 @@ class StockControllerTest extends IntegrationTest {
.as(ErrorResponse.class);
}

@Test
void 종목_소유_개수가_0개인_경우_예외가_발생한다() {
// given
SectorRatioRequest request = new SectorRatioRequest(List.of(new TickerShare(AAPL, 0)));

// when, then
RestAssured
.given()
.log().all()
.contentType(ContentType.JSON)
.body(request)
.when().post("stocks/api/sector-ratio")
.then().log().all()
.statusCode(400)
.extract()
.as(ErrorResponse.class);
}


@Test
void 티커가_1개_이상일_경우_정상적으로_동작한다() {
// given
Expand Down

0 comments on commit 5cfe621

Please sign in to comment.