use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.
the class InvoicesApiTest method testTransitionToApprovedWithFundDistributionsTotalPercentageNot100.
@Test
void testTransitionToApprovedWithFundDistributionsTotalPercentageNot100() {
logger.info("=== Test transition invoice to Approved with Fund Distributions empty will fail ===");
InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class);
Invoice reqData = getMockAsJson(REVIEWED_INVOICE_WITH_EXISTING_VOUCHER_SAMPLE_PATH).mapTo(Invoice.class);
reqData.setStatus(Invoice.Status.APPROVED);
String id = reqData.getId();
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(id);
invoiceLine.getFundDistributions().get(0).setDistributionType(FundDistribution.DistributionType.PERCENTAGE);
invoiceLine.getFundDistributions().get(0).setValue(1d);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
String jsonBody = JsonObject.mapFrom(reqData).encode();
Headers headers = prepareHeaders(X_OKAPI_TENANT, X_OKAPI_TOKEN, X_OKAPI_USER_ID);
Errors errors = verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, headers, APPLICATION_JSON, 400).then().extract().body().as(Errors.class);
assertThat(errors, notNullValue());
assertThat(errors.getErrors(), hasSize(1));
Error error = errors.getErrors().get(0);
assertThat(error.getMessage(), equalTo(LINE_FUND_DISTRIBUTIONS_SUMMARY_MISMATCH.getDescription()));
assertThat(error.getCode(), equalTo(LINE_FUND_DISTRIBUTIONS_SUMMARY_MISMATCH.getCode()));
}
use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.
the class InvoicesApiTest method createMockEntryInStorage.
private Invoice createMockEntryInStorage() {
// Add mock entry in storage with status Paid
Invoice invoice = getMinimalContentInvoice();
String id = invoice.getId();
invoice.setStatus(Invoice.Status.PAID);
MockServer.addMockEntry(INVOICES, invoice);
Invoice reqData = getRqRsEntries(HttpMethod.SEARCH, INVOICES).get(0).mapTo(Invoice.class);
List<InvoiceLine> invoiceLines = getMockAsJson(INVOICE_LINES_LIST_PATH).mapTo(InvoiceLineCollection.class).getInvoiceLines();
invoiceLines.forEach(invoiceLine -> {
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(id);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
});
return reqData;
}
use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.
the class InvoicesApiTest method testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceFalseNoPoLineUpdate.
@Test
void testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceFalseNoPoLineUpdate() {
logger.info("=== Test transition invoice to paid and releaseEncumbrance false for invoice line without poLine update ===");
Invoice reqData = getMockAsJson(APPROVED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withStatus(Invoice.Status.PAID);
String id = reqData.getId();
InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class);
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(id);
invoiceLine.setPoLineId(EXISTENT_PO_LINE_ID);
invoiceLine.setReleaseEncumbrance(false);
// to test credit creation
invoiceLine.setSubTotal(-invoiceLine.getSubTotal());
invoiceLine.setTotal(-invoiceLine.getTotal());
CompositePoLine poLine = getMockAsJson(String.format("%s%s.json", PO_LINE_MOCK_DATA_PATH, EXISTENT_PO_LINE_ID)).mapTo(CompositePoLine.class);
poLine.setId(EXISTENT_PO_LINE_ID);
poLine.setPaymentStatus(CompositePoLine.PaymentStatus.PARTIALLY_PAID);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
addMockEntry(ORDER_LINES, JsonObject.mapFrom(poLine));
prepareMockVoucher(id);
verifyPut(String.format(INVOICE_ID_PATH, id), JsonObject.mapFrom(reqData), "", 204);
assertThat(getRqRsEntries(HttpMethod.PUT, INVOICES).get(0).getString(STATUS), is(Invoice.Status.PAID.value()));
assertThat(getRqRsEntries(HttpMethod.GET, INVOICE_LINES), hasSize(1));
assertThat(getRqRsEntries(HttpMethod.GET, INVOICE_LINES).get(0).mapTo(InvoiceLineCollection.class).getTotalRecords(), equalTo(1));
assertThat(getRqRsEntries(HttpMethod.PUT, ORDER_LINES), empty());
assertThatVoucherPaid();
List<JsonObject> invoiceLinesUpdates = serverRqRs.get(INVOICE_LINES, HttpMethod.PUT);
List<InvoiceLine> lines = invoiceLinesUpdates.stream().map(entry -> entry.mapTo(InvoiceLine.class)).collect(toList());
assertThat(lines, everyItem(hasProperty("invoiceLineStatus", is(InvoiceLine.InvoiceLineStatus.PAID))));
checkCreditsPayments(reqData, Collections.singletonList(invoiceLine));
}
use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.
the class InvoicesApiTest method testTransitionToApprovedWithExistingVoucherAndVoucherLines.
@Test
void testTransitionToApprovedWithExistingVoucherAndVoucherLines() {
logger.info("=== Test transition invoice to Approved with existing voucher and voucherLines ===");
InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class);
Invoice reqData = getMockAsJson(REVIEWED_INVOICE_WITH_EXISTING_VOUCHER_SAMPLE_PATH).mapTo(Invoice.class);
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(reqData.getId());
invoiceLine.getFundDistributions().forEach(fundDistribution -> fundDistribution.setCode(null));
prepareMockVoucher(reqData.getId());
VoucherLine voucherLine = new VoucherLine().withVoucherId(EXISTING_VOUCHER_ID);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
addMockEntry(VOUCHER_LINES, JsonObject.mapFrom(voucherLine));
reqData.setStatus(Invoice.Status.APPROVED);
String id = reqData.getId();
String jsonBody = JsonObject.mapFrom(reqData).encode();
Headers headers = prepareHeaders(X_OKAPI_TENANT, X_OKAPI_USER_ID);
verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, headers, "", 204);
List<JsonObject> vouchersUpdated = serverRqRs.get(VOUCHERS_STORAGE, HttpMethod.PUT);
List<JsonObject> voucherLinesDeletions = serverRqRs.get(VOUCHER_LINES, HttpMethod.DELETE);
List<JsonObject> voucherLinesSearches = serverRqRs.get(VOUCHER_LINES, HttpMethod.GET);
assertThat(vouchersUpdated, notNullValue());
assertThat(vouchersUpdated, hasSize(1));
assertThat(voucherLinesDeletions, notNullValue());
assertThat(voucherLinesSearches, notNullValue());
assertThat(voucherLinesSearches, hasSize(1));
VoucherLineCollection voucherLineCollection = voucherLinesSearches.get(0).mapTo(VoucherLineCollection.class);
assertThat(voucherLinesDeletions, hasSize(voucherLineCollection.getTotalRecords()));
Voucher updatedVoucher = vouchersUpdated.get(0).mapTo(Voucher.class);
Invoice updatedInvoice = serverRqRs.get(INVOICES, HttpMethod.PUT).get(0).mapTo(Invoice.class);
List<JsonObject> fundsSearches = serverRqRs.get(FUNDS, HttpMethod.GET);
List<Fund> funds = fundsSearches.get(0).mapTo(FundCollection.class).getFunds();
verifyTransitionToApproved(updatedVoucher, Collections.singletonList(invoiceLine), updatedInvoice, getExpectedVoucherLinesQuantity(funds));
}
use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.
the class InvoicesApiTest method testTransitionToApprovedFundsNotFound.
@Test
void testTransitionToApprovedFundsNotFound() {
logger.info("=== Test transition invoice to Approved when fund not found ===");
InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class);
Invoice reqData = getMockAsJson(REVIEWED_INVOICE_WITH_EXISTING_VOUCHER_SAMPLE_PATH).mapTo(Invoice.class);
reqData.setStatus(Invoice.Status.APPROVED);
String id = reqData.getId();
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(id);
invoiceLine.getFundDistributions().get(0).setFundId(ID_DOES_NOT_EXIST);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
String jsonBody = JsonObject.mapFrom(reqData).encode();
Headers headers = prepareHeaders(X_OKAPI_USER_ID, X_OKAPI_TENANT);
Errors errors = verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, headers, APPLICATION_JSON, 404).then().extract().body().as(Errors.class);
assertThat(errors, notNullValue());
assertThat(errors.getErrors(), hasSize(1));
Error error = errors.getErrors().get(0);
assertThat(error.getMessage(), equalTo(FUNDS_NOT_FOUND.getDescription()));
assertThat(error.getCode(), equalTo(FUNDS_NOT_FOUND.getCode()));
assertThat(error.getParameters().get(0).getValue(), containsString(ID_DOES_NOT_EXIST));
}
Aggregations