Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,7 @@
- [x] 판매자가 아닌 사용자의 접근 토큰을 사용하면 403 Forbidden 상태코드를 반환한다
- [x] imageUri 속성이 URI 형식을 따르지 않으면 400 Bad Request 상태코드를 반환한다
- [x] 올바르게 요청하면 등록된 상품 정보에 접근하는 Location 헤더를 반환한다
- [x] priceAmount 속성이 0보다 작으면 400 Bad Request 상태코드를 반환한다

### 판매자 상품 조회

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package commerce.commandmodel;

import java.math.BigDecimal;
import java.net.URI;
import java.time.LocalDateTime;
import java.util.UUID;
Expand Down Expand Up @@ -29,7 +30,7 @@ public void execute(
}

private static void validateCommand(RegisterProductCommand command) {
if (isValidUri(command.imageUri()) == false) {
if (command.priceAmount().compareTo(BigDecimal.ZERO) < 0) {
throw new InvalidCommandException();
}
}
Expand Down
12 changes: 12 additions & 0 deletions src/test/java/test/commerce/RegisterProductCommandGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,18 @@ public static RegisterProductCommand generateRegisterProductCommandWithImageUri(
);
}

public static RegisterProductCommand generateRegisterProductCommandWithPriceAmount(
BigDecimal priceAmount
) {
return new RegisterProductCommand(
generateProductName(),
generateProductImageUri(),
generateProductDescription(),
priceAmount,
generateProductStockQuantity()
);
}

private static String generateProductName() {
return "name" + UUID.randomUUID();
}
Expand Down
23 changes: 23 additions & 0 deletions src/test/java/test/commerce/api/seller/products/POST_specs.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package test.commerce.api.seller.products;

import java.math.BigDecimal;
import java.net.URI;
import java.util.UUID;
import java.util.function.Predicate;
Expand All @@ -16,6 +17,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static test.commerce.RegisterProductCommandGenerator.generateRegisterProductCommand;
import static test.commerce.RegisterProductCommandGenerator.generateRegisterProductCommandWithImageUri;
import static test.commerce.RegisterProductCommandGenerator.generateRegisterProductCommandWithPriceAmount;

@CommerceApiTest
@DisplayName("POST /seller/products")
Expand Down Expand Up @@ -116,4 +118,25 @@ private Predicate<? super String> endsWithUUID() {
}
};
}

@ParameterizedTest
@ValueSource(doubles = { -1, -0.1 })
void priceAmount_속성이_0보다_작으면_400_Bad_Request_상태코드를_반환한다(
double priceAmountValue,
@Autowired TestFixture fixture
) {
// Arrange
fixture.createSellerThenSetAsDefaultUser();
BigDecimal priceAmount = new BigDecimal(priceAmountValue);

// Act
ResponseEntity<Void> response = fixture.client().postForEntity(
"/seller/products",
generateRegisterProductCommandWithPriceAmount(priceAmount),
Void.class
);

// Assert
assertThat(response.getStatusCode().value()).isEqualTo(400);
}
}
Loading