Skip to content

Commit

Permalink
OAM-200: Added tests and little fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsznaj committed Jun 17, 2024
1 parent e8c8ae0 commit 6476e96
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ public class OrderControllerIntegrationTest extends BaseWebIntegrationTest {
private static final String EXPORT_URL = ID_URL + "/export";
private static final String RETRY_URL = ID_URL + "/retry";
private static final String PRINT_URL = ID_URL + "/print";

private static final String REQUISITION_LESS_URL = RESOURCE_URL + "/requisitionLess";
private static final String SEND_REQUISITION_LESS_URL = ID_URL + "/requisitionLess/send";
private static final String REQUISITION_LESS_URL = RESOURCE_URL + "/requisitionLess";
private static final String NUMBER_OF_ORDERS_URL = RESOURCE_URL + "/numberOfOrdersData";
private static final String STATUSES_STATS_DATA_URL = RESOURCE_URL + "/statusesStatsData";

Expand Down Expand Up @@ -326,8 +325,8 @@ period2Id, program2Id, facility2Id, facility1Id, new BigDecimal(200),
}

private Order createOrder(UUID processingPeriodId, UUID program, UUID facilityId,
UUID supplyingFacilityId, BigDecimal cost,
OrderLineItem... lineItems) {
UUID supplyingFacilityId, BigDecimal cost,
OrderLineItem... lineItems) {
Order order = new OrderDataBuilder()
.withProcessingPeriodId(processingPeriodId)
.withQuotedCost(cost)
Expand Down Expand Up @@ -499,6 +498,34 @@ public void shouldCreateOrder() {
is(firstOrderDto.getExternalId()));
}

@Test
public void shouldDeleteMultipleOrders() {

UUID firstOrderId = firstOrder.getId();
UUID secondOrderId = secondOrder.getId();
given(orderRepository.findById(firstOrderId))
.willReturn(Optional.of(firstOrder));
given(orderRepository.findById(secondOrderId))
.willReturn(Optional.of(secondOrder));
List<UUID> uuids = new ArrayList<>();
uuids.add(firstOrderId);
uuids.add(secondOrderId);

restAssured.given()
.header(HttpHeaders.AUTHORIZATION, getTokenHeader())
.contentType(APPLICATION_JSON_VALUE)
.body(uuids)
.when()
.post(RESOURCE_URL)
.then()
.statusCode(204);

assertThat(RAML_ASSERT_MESSAGE, restAssured.getLastReport(), RamlMatchers.hasNoViolations());

verify(orderRepository).deleteById(firstOrderId);
verify(orderRepository).deleteById(secondOrderId);
}

@Test
public void shouldCreateRequisitionLessOrder() {
given(orderService.createRequisitionLessOrder(any(OrderDto.class), eq(user.getId())))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public class PermissionService {
public static final String PODS_VIEW = "PODS_VIEW";
public static final String ORDERS_VIEW = "ORDERS_VIEW";
public static final String ORDERS_EDIT = "ORDERS_EDIT";
public static final String ORDERS_DELETE = "ORDERS_DELETE";
public static final String ORDER_CREATE = "ORDER_CREATE";
public static final String ORDER_DELETE = "ORDER_DELETE";
public static final String SHIPMENTS_VIEW = "SHIPMENTS_VIEW";
public static final String SHIPMENTS_EDIT = "SHIPMENTS_EDIT";
static final String SYSTEM_SETTINGS_MANAGE = "SYSTEM_SETTINGS_MANAGE";
Expand Down Expand Up @@ -157,11 +157,11 @@ public void canCreateOrder(Order order) {
public void canDeleteOrders(List<UUID> ids) {
for (UUID id : ids) {
if (hasPermission(ORDER_CREATE, id)
|| hasPermission(ORDER_DELETE, id)) {
|| hasPermission(ORDERS_DELETE, id)) {
return;
}

throw new MissingPermissionException(ORDER_CREATE, ORDER_DELETE);
throw new MissingPermissionException(ORDER_CREATE, ORDERS_DELETE);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -506,7 +506,7 @@ public ResultDto<Boolean> retryOrderTransfer(@PathVariable("id") UUID id) {
}

@RequestMapping(value = "/orders", method = RequestMethod.DELETE)
@ResponseStatus(HttpStatus.OK)
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deleteMultipleOrders(@RequestParam(name = "ids") List<UUID> ids) {

if (CollectionUtils.isEmpty(ids)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.openlmis.fulfillment.i18n.MessageKeys.ORDER_NOT_FOUND;
import static org.openlmis.fulfillment.i18n.MessageKeys.PERMISSIONS_MISSING;
import static org.openlmis.fulfillment.i18n.MessageKeys.PERMISSION_MISSING;
import static org.openlmis.fulfillment.service.PermissionService.ORDERS_DELETE;
import static org.openlmis.fulfillment.service.PermissionService.ORDERS_EDIT;
import static org.openlmis.fulfillment.service.PermissionService.ORDERS_TRANSFER;
import static org.openlmis.fulfillment.service.PermissionService.ORDERS_VIEW;
Expand All @@ -37,6 +38,7 @@
import static org.openlmis.fulfillment.testutils.OAuth2AuthenticationDataBuilder.SERVICE_CLIENT_ID;

import com.google.common.collect.ImmutableMap;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -335,6 +337,22 @@ public void cannotCreateOrder() {
permissionService.canCreateOrder(order);
}

@Test
public void canDeleteOrder() {
mockHasRight(ORDERS_DELETE, null, null, order.getReceivingFacilityId());

permissionService.canDeleteOrders(Collections.singletonList(order.getId()));

verifyRight(ORDERS_DELETE, null, null, order.getReceivingFacilityId());
}

@Test
public void cannotDeleteOrder() {
expectException(ORDERS_DELETE);

permissionService.canDeleteOrders(Collections.singletonList(order.getId()));
}

@Test
public void canManageShipment() {
mockHasRight(SHIPMENTS_EDIT, null, null, order.getSupplyingFacilityId());
Expand Down

0 comments on commit 6476e96

Please sign in to comment.