use of org.folio.rest.impl.InvoiceLinesApiTest.INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH 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.rest.impl.InvoiceLinesApiTest.INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH in project mod-invoice by folio-org.
the class InvoicesApiTest method testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceFalse.
@Test
void testUpdateValidInvoiceTransitionToPaidReleaseEncumbranceFalse() {
logger.info("=== Test transition invoice to paid and releaseEncumbrance false for all invoice lines ===");
Invoice reqData = getMockAsJson(APPROVED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withStatus(Invoice.Status.PAID);
String id = reqData.getId();
List<InvoiceLine> invoiceLines = new ArrayList<>();
// Prepare invoice lines
for (int i = 0; i < 3; i++) {
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);
invoiceLines.add(invoiceLine);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
}
prepareMockVoucher(id);
verifyPut(String.format(INVOICE_ID_PATH, id), JsonObject.mapFrom(reqData), "", 204);
assertThat(serverRqRs.get(INVOICES, HttpMethod.PUT).get(0).getString(STATUS), is(Invoice.Status.PAID.value()));
assertThat(serverRqRs.get(INVOICE_LINES, HttpMethod.GET), notNullValue());
assertThat(serverRqRs.get(INVOICE_LINES, HttpMethod.GET).get(0).mapTo(InvoiceLineCollection.class).getTotalRecords(), equalTo(3));
assertThat(serverRqRs.get(ORDER_LINES, HttpMethod.PUT), notNullValue());
assertThat(serverRqRs.get(ORDER_LINES, HttpMethod.PUT), hasSize(1));
assertThat(serverRqRs.get(ORDER_LINES, HttpMethod.PUT).get(0).mapTo(CompositePoLine.class).getPaymentStatus(), equalTo(CompositePoLine.PaymentStatus.PARTIALLY_PAID));
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, invoiceLines);
}
use of org.folio.rest.impl.InvoiceLinesApiTest.INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH 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.impl.InvoiceLinesApiTest.INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH in project mod-invoice by folio-org.
the class InvoicesApiTest method testTransitionToApprovedWithFundDistrEncumbranceId.
@Test
void testTransitionToApprovedWithFundDistrEncumbranceId() {
logger.info("=== Test transition invoice to Approved with links to encumbrances ===");
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);
reqData.setCurrency("GBP");
reqData.setExchangeRate(1.5d);
String id = reqData.getId();
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(id);
invoiceLine.setAdjustmentsTotal(0d);
invoiceLine.setAdjustments(emptyList());
invoiceLine.setSubTotal(10d);
FundDistribution fd1 = new FundDistribution().withDistributionType(FundDistribution.DistributionType.PERCENTAGE).withFundId(EXISTING_FUND_ID).withValue(50d).withEncumbrance(UUID.randomUUID().toString());
FundDistribution fd2 = new FundDistribution().withDistributionType(AMOUNT).withFundId(EXISTING_FUND_ID).withValue(3d).withEncumbrance(UUID.randomUUID().toString());
FundDistribution fd3 = new FundDistribution().withDistributionType(AMOUNT).withFundId(EXISTING_FUND_ID).withValue(2d).withEncumbrance(UUID.randomUUID().toString());
List<FundDistribution> fundDistributions = Arrays.asList(fd1, fd2, fd3);
invoiceLine.setFundDistributions(fundDistributions);
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);
verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, headers, "", 204);
List<JsonObject> invoiceSummariesCreated = serverRqRs.get(INVOICE_TRANSACTION_SUMMARIES, HttpMethod.POST);
List<JsonObject> pendingPaymesCreated = serverRqRs.get(FINANCE_PENDING_PAYMENTS, HttpMethod.POST);
assertThat(invoiceSummariesCreated, hasSize(1));
InvoiceTransactionSummary transactionSummary = invoiceSummariesCreated.get(0).mapTo(InvoiceTransactionSummary.class);
assertThat(transactionSummary.getNumPendingPayments(), is(invoiceLine.getFundDistributions().size()));
assertThat(transactionSummary.getNumPaymentsCredits(), is(invoiceLine.getFundDistributions().size()));
assertThat(pendingPaymesCreated, hasSize(invoiceLine.getFundDistributions().size()));
Map<String, Transaction> pendingPaymentMap = pendingPaymesCreated.stream().map(entries -> entries.mapTo(Transaction.class)).collect(toMap((transaction) -> transaction.getAwaitingPayment().getEncumbranceId(), Function.identity()));
ConversionQuery conversionQuery = ConversionQueryBuilder.of().setTermCurrency(DEFAULT_SYSTEM_CURRENCY).set(RATE_KEY, 1.5).build();
ExchangeRateProvider exchangeRateProvider = new ExchangeRateProviderResolver().resolve(conversionQuery, new RequestContext(Vertx.currentContext(), Collections.emptyMap()));
// currency from MockServer
CurrencyConversion conversion = exchangeRateProvider.getCurrencyConversion(conversionQuery);
fundDistributions.forEach(fundDistribution -> {
MonetaryAmount amount = getFundDistributionAmount(fundDistribution, 10d, reqData.getCurrency()).with(conversion);
assertThat(convertToDoubleWithRounding(amount), is(pendingPaymentMap.get(fundDistribution.getEncumbrance()).getAmount()));
});
}
use of org.folio.rest.impl.InvoiceLinesApiTest.INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH 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