use of org.folio.rest.jaxrs.model.CloseReason in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testPutOrderWithoutPoLinesToChangeStatusFromOpenToClosedItemsHaveToBeUpdate.
@Test
void testPutOrderWithoutPoLinesToChangeStatusFromOpenToClosedItemsHaveToBeUpdate() {
logger.info("=== Test case when order status updated from Open to Closed no PO Lines in payload - related items have to be updated ===");
CompositePurchaseOrder reqData = getMockAsJson(COMP_ORDER_MOCK_DATA_PATH, PO_ID_OPEN_TO_BE_CLOSED).mapTo(CompositePurchaseOrder.class);
List<CompositePoLine> poLines = reqData.getCompositePoLines();
poLines.forEach(line -> {
line.setPurchaseOrderId(PO_ID_OPEN_TO_BE_CLOSED);
line.setReceiptStatus(ReceiptStatus.AWAITING_RECEIPT);
addMockEntry(PO_LINES_STORAGE, line);
});
MockServer.addMockTitles(poLines);
reqData.setCompositePoLines(Collections.emptyList());
reqData.setVendor(ACTIVE_VENDOR_ID);
reqData.setWorkflowStatus(CompositePurchaseOrder.WorkflowStatus.CLOSED);
reqData.setCloseReason(new CloseReason().withReason("Test"));
reqData.setReEncumber(false);
verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getId()), JsonObject.mapFrom(reqData), EMPTY, 204);
PurchaseOrder purchaseOrder = getPurchaseOrderUpdates().get(0).mapTo(PurchaseOrder.class);
assertThat(purchaseOrder.getWorkflowStatus(), is(PurchaseOrder.WorkflowStatus.CLOSED));
assertThat(purchaseOrder.getCloseReason(), notNullValue());
assertThat(purchaseOrder.getCloseReason().getReason(), equalTo("Test"));
assertThat(getItemsSearches(), notNullValue());
assertThat(getItemsSearches(), hasSize(1));
assertThat(getItemUpdates(), notNullValue());
assertThat(getItemUpdates(), hasSize(getItemsSearches().get(0).getJsonArray(ITEMS).size()));
assertThat(getQueryParams(ITEM_RECORDS), hasSize(1));
assertThat(getQueryParams(ITEM_RECORDS).get(0), containsAny("status.name==On order", poLines.get(0).getId()));
}
use of org.folio.rest.jaxrs.model.CloseReason in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testUpdateOrderWithProtectedFieldsChangingForClosedOrder.
@Test
void testUpdateOrderWithProtectedFieldsChangingForClosedOrder() {
logger.info("=== Test case when closed order errors if protected fields are changed ===");
JsonObject reqData = getMockAsJson(COMP_ORDER_MOCK_DATA_PATH, PO_ID_CLOSED_STATUS);
assertThat(reqData.getString("workflowStatus"), is(CompositePurchaseOrder.WorkflowStatus.CLOSED.value()));
Map<String, Object> allProtectedFieldsModification = new HashMap<>();
allProtectedFieldsModification.put(POProtectedFields.APPROVED.getFieldName(), false);
allProtectedFieldsModification.put(POProtectedFields.PO_NUMBER.getFieldName(), "testPO");
allProtectedFieldsModification.put(POProtectedFields.MANUAL_PO.getFieldName(), true);
allProtectedFieldsModification.put(POProtectedFields.RE_ENCUMBER.getFieldName(), true);
allProtectedFieldsModification.put(POProtectedFields.ORDER_TYPE.getFieldName(), CompositePurchaseOrder.OrderType.ONE_TIME.value());
allProtectedFieldsModification.put(POProtectedFields.ONGOING.getFieldName(), null);
CloseReason closeReason = new CloseReason();
closeReason.setNote("testing reason on Closed Order");
closeReason.setReason("Complete");
allProtectedFieldsModification.put(POProtectedFields.CLOSE_REASON.getFieldName(), JsonObject.mapFrom(closeReason));
checkPreventProtectedFieldsModificationRule(COMPOSITE_ORDERS_BY_ID_PATH, reqData, allProtectedFieldsModification);
}
use of org.folio.rest.jaxrs.model.CloseReason in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testCancelOrder.
@Test
void testCancelOrder() {
logger.info("=== Test case: Cancel order ===");
JsonObject reqData = getMockAsJson(COMP_ORDER_MOCK_DATA_PATH, PO_ID_OPEN_TO_CANCEL);
assertThat(reqData.getString("workflowStatus"), is(CompositePurchaseOrder.WorkflowStatus.OPEN.value()));
reqData.put("workflowStatus", "Closed");
CloseReason closeReason = new CloseReason();
closeReason.setReason("Cancelled");
reqData.put("closeReason", JsonObject.mapFrom(closeReason));
reqData.remove("compositePoLines");
verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getString("id")), JsonObject.mapFrom(reqData), "", 204);
assertThat(getPurchaseOrderUpdates().get(0).mapTo(PurchaseOrder.class).getWorkflowStatus(), is(PurchaseOrder.WorkflowStatus.CLOSED));
List<JsonObject> polUpdates = MockServer.getPoLineUpdates();
assertNotNull(polUpdates);
// check the payment and receipt status of the last 3 updated polines
JsonObject line1 = polUpdates.get(polUpdates.size() - 3);
assertEquals(ReceiptStatus.CANCELLED.value(), line1.getString(RECEIPT_STATUS));
assertEquals(PaymentStatus.CANCELLED.value(), line1.getString(PAYMENT_STATUS));
JsonObject line2 = polUpdates.get(polUpdates.size() - 2);
assertEquals(ReceiptStatus.CANCELLED.value(), line2.getString(RECEIPT_STATUS));
assertEquals(PaymentStatus.PAYMENT_NOT_REQUIRED.value(), line2.getString(PAYMENT_STATUS));
JsonObject line3 = polUpdates.get(polUpdates.size() - 1);
assertEquals(ReceiptStatus.FULLY_RECEIVED.value(), line3.getString(RECEIPT_STATUS));
assertEquals(PaymentStatus.CANCELLED.value(), line3.getString(PAYMENT_STATUS));
}
use of org.folio.rest.jaxrs.model.CloseReason in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testUpdateOrderCloseOrderWithCloseReasonAndFundDistribution.
@Test
void testUpdateOrderCloseOrderWithCloseReasonAndFundDistribution() {
logger.info("=== Test case: Able to Close Order with close Reason and fund distribution ===");
JsonObject reqData = getMockAsJson(COMP_ORDER_MOCK_DATA_PATH, PO_WFD_ID_OPEN_STATUS);
assertThat(reqData.getString("workflowStatus"), is(CompositePurchaseOrder.WorkflowStatus.OPEN.value()));
reqData.put("workflowStatus", "Closed");
// close reason must not be checked if the Order is in OPEN status in storage
CloseReason closeReason = new CloseReason();
closeReason.setNote("can set close reason");
closeReason.setReason("Complete");
reqData.put("closeReason", JsonObject.mapFrom(closeReason));
verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getString("id")), JsonObject.mapFrom(reqData), "", 204);
}
use of org.folio.rest.jaxrs.model.CloseReason in project mod-orders by folio-org.
the class PurchaseOrdersApiTest method testUpdateOrderCloseOrderWithCloseReason.
@Test
void testUpdateOrderCloseOrderWithCloseReason() {
logger.info("=== Test case: Able to Close Order with close Reason ===");
JsonObject reqData = getMockAsJson(COMP_ORDER_MOCK_DATA_PATH, PO_ID_OPEN_STATUS);
assertThat(reqData.getString("workflowStatus"), is(CompositePurchaseOrder.WorkflowStatus.OPEN.value()));
reqData.put("workflowStatus", "Closed");
// close reason must not be checked if the Order is in OPEN status in storage
CloseReason closeReason = new CloseReason();
closeReason.setNote("can set close reason");
closeReason.setReason("Complete");
reqData.put("closeReason", JsonObject.mapFrom(closeReason));
verifyPut(String.format(COMPOSITE_ORDERS_BY_ID_PATH, reqData.getString("id")), JsonObject.mapFrom(reqData), "", 204);
}
Aggregations