Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: elevando a cobertura de testes unitários #42

Merged
merged 1 commit into from
Jul 15, 2024
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.produtopedidoitens.api.application.mapper.OrderConverter;
import com.produtopedidoitens.api.application.validators.OrderValidator;
import com.produtopedidoitens.api.utils.MessagesConstants;
import com.querydsl.core.types.Predicate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand Down Expand Up @@ -60,6 +61,7 @@ void setUp() {
orderResponse = OrderResponse.builder()
.id(UUID.fromString("f47b3b2b-4b0b-4b7e-8b3e-3b3e4b7b2b4f"))
.orderDate(LocalDate.now())
.orderNumber("PED-123-2024")
.status("Aberto")
.discount(BigDecimal.valueOf(0.00))
.version(0L)
Expand All @@ -68,6 +70,7 @@ void setUp() {
orderProjection = OrderProjection.builder()
.id(UUID.fromString("f47b3b2b-4b0b-4b7e-8b3e-3b3e4b7b2b4f"))
.orderDate(LocalDate.now())
.orderNumber("PED-123-2024")
.status("Aberto")
.items(new ArrayList<>())
.grossTotal(BigDecimal.valueOf(100.00))
Expand All @@ -78,6 +81,7 @@ void setUp() {
orderEntity = OrderEntity.builder()
.id(UUID.fromString("f47b3b2b-4b0b-4b7e-8b3e-3b3e4b7b2b4f"))
.orderDate(LocalDate.now())
.orderNumber("PED-123-2024")
.status(EnumOrderStatus.OPEN)
.items(new ArrayList<>())
.grossTotal(BigDecimal.valueOf(100.00))
Expand Down Expand Up @@ -227,4 +231,24 @@ void testDeleteError() {
exception = assertThrows(Exception.class, () -> orderServiceImpl.deleteOrder(orderEntity.getId()));
assertEquals(MessagesConstants.ERROR_DELETE_ORDER, exception.getMessage());
}

@Test
@DisplayName("Deve buscar pedidos por filtro")
void testSearchOrders() {
List<OrderEntity> orderEntityList = List.of(orderEntity);
List<OrderProjection> expectedProjectionList = List.of(orderProjection);

when(orderRepository.findAll(any(Predicate.class))).thenReturn(orderEntityList);
when(orderConverter.toProjection(orderEntity)).thenReturn(orderProjection);

List<OrderProjection> result = orderServiceImpl.searchOrders("PED-123-2024", EnumOrderStatus.OPEN);

assertNotNull(result);
assertEquals(expectedProjectionList.size(), result.size());
assertEquals(expectedProjectionList.get(0), result.get(0));

verify(orderRepository).findAll(any(Predicate.class));
verify(orderConverter, times(orderEntityList.size())).toProjection(orderEntity);

}
}
Loading