generated from ita-social-projects/DevTemplate
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UBS] - Exception occurs when we try to update order page admin info …
…#6128 (#1213) * update order * update order and save reason * formatter * tests * formatting * code refactoring * code smells * suggested changes * required fields * changed required fields for updating order * desc * formatter * tests * formatter * tests * desc
- Loading branch information
Showing
9 changed files
with
163 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
service-api/src/main/java/greencity/dto/order/NotTakenOutReasonDto.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package greencity.dto.order; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
import lombok.ToString; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Getter | ||
@Setter | ||
@ToString | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
@Builder | ||
public class NotTakenOutReasonDto { | ||
private String description; | ||
private MultipartFile[] images; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2891,9 +2891,115 @@ void saveOrderIdForRefundThrowsNotFoundExceptionTest() { | |
@Test | ||
void updateOrderAdminPageInfoAndSaveReasonTest() { | ||
var dto = updateOrderPageAdminDto(); | ||
MockMultipartFile[] multipartFiles = new MockMultipartFile[0]; | ||
Order order = getOrder(); | ||
|
||
TariffsInfo tariffsInfo = getTariffsInfo(); | ||
order.setOrderDate(LocalDateTime.now()).setTariffsInfo(tariffsInfo); | ||
|
||
Employee employee = getEmployee(); | ||
|
||
when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); | ||
when(employeeRepository.findByEmail("[email protected]")).thenReturn(Optional.of(employee)); | ||
when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(1L, 1L)) | ||
.thenReturn(Optional.of(tariffsInfo)); | ||
when(paymentRepository.findAllByOrderId(1L)).thenReturn(List.of(getPayment())); | ||
|
||
when(orderAddressRepository.findById(1L)).thenReturn(Optional.of(getOrderAddress())); | ||
when(receivingStationRepository.findAll()).thenReturn(List.of(getReceivingStation())); | ||
|
||
var receivingStation = getReceivingStation(); | ||
|
||
when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); | ||
when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); | ||
|
||
ubsManagementService.updateOrderAdminPageInfoAndSaveReason(1L, dto, "en", "[email protected]"); | ||
|
||
verify(orderRepository).findById(1L); | ||
verify(employeeRepository).findByEmail("[email protected]"); | ||
verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(1L, 1L); | ||
verify(paymentRepository).findAllByOrderId(1L); | ||
|
||
verify(orderAddressRepository).findById(1L); | ||
verify(receivingStationRepository).findAll(); | ||
|
||
verify(receivingStationRepository).findById(1L); | ||
verify(orderRepository).getOrderDetails(1L); | ||
} | ||
|
||
@Test | ||
void updateOrderAdminPageInfoAndSaveReasonThrowsBadRequestExceptionWithEmptyDescFieldTest() { | ||
var dto = updateOrderPageAdminDto(); | ||
Order order = getOrder(); | ||
dto.getGeneralOrderInfo().setOrderStatus(OrderStatus.NOT_TAKEN_OUT.name()); | ||
TariffsInfo tariffsInfo = getTariffsInfo(); | ||
order.setOrderDate(LocalDateTime.now()).setTariffsInfo(tariffsInfo); | ||
|
||
when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); | ||
assertThrows(BadRequestException.class, | ||
() -> ubsManagementService.updateOrderAdminPageInfoAndSaveReason(1L, dto, "en", "[email protected]")); | ||
verify(orderRepository).findById(1L); | ||
} | ||
|
||
@Test | ||
void updateOrderAdminPageInfoAndSaveReasonThrowsBadRequestExceptionWithNullDescFieldTest() { | ||
var dto = updateOrderPageAdminDto(); | ||
Order order = getOrder(); | ||
dto.getGeneralOrderInfo().setOrderStatus(OrderStatus.NOT_TAKEN_OUT.name()); | ||
dto.getNotTakenOutReasonDto().setDescription(null); | ||
TariffsInfo tariffsInfo = getTariffsInfo(); | ||
order.setOrderDate(LocalDateTime.now()).setTariffsInfo(tariffsInfo); | ||
|
||
when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); | ||
assertThrows(BadRequestException.class, | ||
() -> ubsManagementService.updateOrderAdminPageInfoAndSaveReason(1L, dto, "en", "[email protected]")); | ||
verify(orderRepository).findById(1L); | ||
} | ||
|
||
@Test | ||
void updateOrderAdminPageInfoAndSaveReasonWithImagesTest() { | ||
var dto = updateOrderPageAdminDto(); | ||
Order order = getOrder(); | ||
dto.getNotTakenOutReasonDto().setImages(new MultipartFile[2]); | ||
|
||
TariffsInfo tariffsInfo = getTariffsInfo(); | ||
order.setOrderDate(LocalDateTime.now()).setTariffsInfo(tariffsInfo); | ||
|
||
Employee employee = getEmployee(); | ||
|
||
when(orderRepository.findById(1L)).thenReturn(Optional.of(order)); | ||
when(employeeRepository.findByEmail("[email protected]")).thenReturn(Optional.of(employee)); | ||
when(tariffsInfoRepository.findTariffsInfoByIdForEmployee(1L, 1L)) | ||
.thenReturn(Optional.of(tariffsInfo)); | ||
when(paymentRepository.findAllByOrderId(1L)).thenReturn(List.of(getPayment())); | ||
|
||
when(orderAddressRepository.findById(1L)).thenReturn(Optional.of(getOrderAddress())); | ||
when(receivingStationRepository.findAll()).thenReturn(List.of(getReceivingStation())); | ||
|
||
var receivingStation = getReceivingStation(); | ||
|
||
when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); | ||
when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); | ||
|
||
ubsManagementService.updateOrderAdminPageInfoAndSaveReason(1L, dto, "en", "[email protected]"); | ||
|
||
verify(orderRepository).findById(1L); | ||
verify(employeeRepository).findByEmail("[email protected]"); | ||
verify(tariffsInfoRepository).findTariffsInfoByIdForEmployee(1L, 1L); | ||
verify(paymentRepository).findAllByOrderId(1L); | ||
|
||
verify(orderAddressRepository).findById(1L); | ||
verify(receivingStationRepository).findAll(); | ||
|
||
verify(receivingStationRepository).findById(1L); | ||
verify(orderRepository).getOrderDetails(1L); | ||
} | ||
|
||
@Test | ||
void updateOrderAdminPageInfoAndSaveReasonWithReasonDescTest() { | ||
var dto = updateOrderPageAdminDto(); | ||
Order order = getOrder(); | ||
dto.getGeneralOrderInfo().setOrderStatus(OrderStatus.NOT_TAKEN_OUT.name()); | ||
dto.getNotTakenOutReasonDto().setDescription("desc"); | ||
|
||
TariffsInfo tariffsInfo = getTariffsInfo(); | ||
order.setOrderDate(LocalDateTime.now()).setTariffsInfo(tariffsInfo); | ||
|
@@ -2914,8 +3020,7 @@ void updateOrderAdminPageInfoAndSaveReasonTest() { | |
when(receivingStationRepository.findById(1L)).thenReturn(Optional.of(receivingStation)); | ||
when(orderRepository.getOrderDetails(1L)).thenReturn(Optional.ofNullable(getOrdersStatusFormedDto())); | ||
|
||
ubsManagementService.updateOrderAdminPageInfoAndSaveReason(1L, dto, "en", "[email protected]", "desc", | ||
multipartFiles); | ||
ubsManagementService.updateOrderAdminPageInfoAndSaveReason(1L, dto, "en", "[email protected]"); | ||
|
||
verify(orderRepository).findById(1L); | ||
verify(employeeRepository).findByEmail("[email protected]"); | ||
|