use of org.folio.invoices.utils.ResourcePathResolver.FINANCE_TRANSACTIONS in project mod-invoice by folio-org.
the class InvoicesApiTest method testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceTrue.
@Test
void testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceTrue() {
logger.info("=== Test transition invoice to paid and releaseEncumbrance true for all invoice lines ===");
List<InvoiceLine> invoiceLines = new ArrayList<>();
List<CompositePoLine> poLines = new ArrayList<>();
for (int i = 0; i < 3; i++) {
invoiceLines.add(getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class));
poLines.add(getMockAsJson(String.format("%s%s.json", PO_LINE_MOCK_DATA_PATH, EXISTENT_PO_LINE_ID)).mapTo(CompositePoLine.class));
}
Invoice reqData = getMockAsJson(APPROVED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withStatus(Invoice.Status.PAID);
String id = reqData.getId();
for (int i = 0; i < 3; i++) {
InvoiceLine invoiceLine = invoiceLines.get(i);
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(reqData.getId());
String poLineId = UUID.randomUUID().toString();
invoiceLine.setPoLineId(poLineId);
poLines.get(i).setId(poLineId);
}
invoiceLines.forEach(line -> addMockEntry(INVOICE_LINES, JsonObject.mapFrom(line)));
poLines.forEach(line -> addMockEntry(ORDER_LINES, JsonObject.mapFrom(line)));
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(3));
assertThat(getRqRsEntries(HttpMethod.PUT, ORDER_LINES), hasSize(3));
getRqRsEntries(HttpMethod.PUT, ORDER_LINES).stream().map(entries -> entries.mapTo(CompositePoLine.class)).forEach(compositePoLine -> assertThat(compositePoLine.getPaymentStatus(), equalTo(CompositePoLine.PaymentStatus.FULLY_PAID)));
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))));
assertThat(getRqRsEntries(HttpMethod.GET, FINANCE_TRANSACTIONS), hasSize(2));
assertThat(getRqRsEntries(HttpMethod.POST, FINANCE_PAYMENTS), hasSize(5));
assertThat(getRqRsEntries(HttpMethod.POST, FINANCE_CREDITS), hasSize(0));
checkCreditsPayments(reqData, invoiceLines);
}
use of org.folio.invoices.utils.ResourcePathResolver.FINANCE_TRANSACTIONS in project mod-invoice by folio-org.
the class InvoicesApiTest method testPutInvoiceByIdChangeStatusToPayedActiveBudgetNotFound.
@Test
void testPutInvoiceByIdChangeStatusToPayedActiveBudgetNotFound() {
logger.info("=== Test Put Invoice By Id, Current fiscal year not found ===");
Invoice reqData = getMockAsJson(APPROVED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withStatus(Invoice.Status.PAID);
String id = reqData.getId();
reqData.setStatus(Status.PAID);
InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class);
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(reqData.getId());
invoiceLine.getFundDistributions().get(0).withFundId(FUND_ID_WITH_NOT_ACTIVE_BUDGET);
invoiceLine.getFundDistributions().forEach(fundDistribution -> {
Fund fund = new Fund().withId(fundDistribution.getFundId()).withExternalAccountNo("externalNo").withLedgerId(EXISTING_LEDGER_ID);
addMockEntry(FUNDS, fund);
});
reqData.getAdjustments().stream().flatMap(adjustment -> adjustment.getFundDistributions().stream()).map(FundDistribution::getFundId).distinct().forEach(fundId -> {
Fund fund = new Fund().withId(fundId).withExternalAccountNo("externalNo").withLedgerId(EXISTING_LEDGER_ID);
addMockEntry(FUNDS, fund);
});
addMockEntry(LEDGERS, JsonObject.mapFrom(new Ledger().withId(EXISTING_LEDGER_ID).withRestrictEncumbrance(true)));
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
prepareMockVoucher(id);
Errors errors = verifyPut(String.format(INVOICE_ID_PATH, id), JsonObject.mapFrom(reqData), APPLICATION_JSON, 404).as(Errors.class);
assertThat(getRqRsEntries(HttpMethod.GET, INVOICE_LINES), hasSize(1));
assertThat(getRqRsEntries(HttpMethod.GET, FINANCE_TRANSACTIONS), hasSize(0));
assertThat(getRqRsEntries(HttpMethod.GET, FUNDS), hasSize(1));
assertThat(getRqRsEntries(HttpMethod.POST, FINANCE_PAYMENTS), hasSize(0));
assertThat(getRqRsEntries(HttpMethod.POST, FINANCE_CREDITS), hasSize(0));
assertThat(errors.getErrors(), hasSize(1));
Error error = errors.getErrors().get(0);
assertThat(error.getCode(), equalTo(BUDGET_NOT_FOUND.getCode()));
}
Aggregations