use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.
the class InvoicesApiTest method testTransitionFromOpenToApprovedWithRestrictExpenditures.
@Test
void testTransitionFromOpenToApprovedWithRestrictExpenditures() {
Invoice reqData = getMockAsJson(OPEN_INVOICE_SAMPLE_PATH).mapTo(Invoice.class);
String id = reqData.getId();
InvoiceLine invoiceLine = getMinimalContentInvoiceLine(id);
invoiceLine.setSubTotal(50d);
invoiceLine.setId(UUID.randomUUID().toString());
String fundId = UUID.randomUUID().toString();
String ledgerId = UUID.randomUUID().toString();
Budget budget = new Budget().withId(UUID.randomUUID().toString()).withFundId(fundId).withFiscalYearId(FISCAL_YEAR_ID).withAllocated(50d).withAvailable(50d).withBudgetStatus(BudgetStatus.ACTIVE).withUnavailable(0d);
Fund fund = new Fund().withId(fundId).withExternalAccountNo("test").withLedgerId(ledgerId).withCode("FC").withFundStatus(Fund.FundStatus.ACTIVE);
Ledger ledger = new Ledger().withId(ledgerId).withRestrictExpenditures(false);
FundDistribution amountDistribution = new FundDistribution().withFundId(fundId).withDistributionType(AMOUNT).withValue(50d);
invoiceLine.getFundDistributions().add(amountDistribution);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
addMockEntry(BUDGETS, JsonObject.mapFrom(budget));
addMockEntry(FUNDS, JsonObject.mapFrom(fund));
addMockEntry(LEDGERS, JsonObject.mapFrom(ledger));
reqData.setStatus(Invoice.Status.APPROVED);
String jsonBody = JsonObject.mapFrom(reqData).encode();
Headers headers = prepareHeaders(X_OKAPI_URL, X_OKAPI_TENANT, X_OKAPI_TOKEN, X_OKAPI_USER_ID);
verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, headers, "", 204);
}
use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.
the class InvoicesApiTest method testPutInvoiceByIdChangeStatusToPayedGetFundsServerError.
@Test
void testPutInvoiceByIdChangeStatusToPayedGetFundsServerError() {
logger.info("=== Test Put Invoice By Id, get Funds server error ===");
Invoice reqData = getMockAsJson(APPROVED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withStatus(Invoice.Status.PAID);
String id = reqData.getId();
reqData.setStatus(Status.APPROVED);
InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_APPROVED_INVOICE_SAMPLE_PATH).mapTo(InvoiceLine.class);
reqData.setAdjustments(emptyList());
invoiceLine.setId(UUID.randomUUID().toString());
invoiceLine.setInvoiceId(reqData.getId());
invoiceLine.getFundDistributions().get(0).withFundId(ID_FOR_INTERNAL_SERVER_ERROR);
addMockEntry(INVOICES, reqData);
addMockEntry(INVOICE_LINES, invoiceLine);
prepareMockVoucher(id);
reqData.setStatus(Status.PAID);
Errors errors = verifyPut(String.format(INVOICE_ID_PATH, id), JsonObject.mapFrom(reqData), APPLICATION_JSON, 500).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(0));
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(GENERIC_ERROR_CODE.getCode()));
}
use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.
the class InvoicesApiTest method testUpdateValidInvoiceTransitionToPaidWithMissingPoLine.
@Test
void testUpdateValidInvoiceTransitionToPaidWithMissingPoLine() {
logger.info("=== Test transition invoice to paid with deleted associated poLine ===");
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.setInvoiceId(id);
invoiceLine.setPoLineId(ID_DOES_NOT_EXIST);
addMockEntry(INVOICE_LINES, JsonObject.mapFrom(invoiceLine));
prepareMockVoucher(id);
String jsonBody = JsonObject.mapFrom(reqData).encode();
Errors errors = verifyPut(String.format(INVOICE_ID_PATH, id), jsonBody, APPLICATION_JSON, 404).then().extract().body().as(Errors.class);
assertThat(serverRqRs.get(INVOICES, HttpMethod.PUT), nullValue());
assertThat(errors.getErrors(), hasSize(1));
assertThat(errors.getErrors().get(0).getCode(), equalTo(PO_LINE_NOT_FOUND.getCode()));
assertThat(errors.getErrors().get(0).getParameters().get(0).getValue(), equalTo(ID_DOES_NOT_EXIST));
}
use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.
the class InvoicesApiTest method testTransitionToApprovedWithAdjustmentFundDistributionsNotPresent.
@Test
void testTransitionToApprovedWithAdjustmentFundDistributionsNotPresent() {
logger.info("=== Test transition invoice to Approved with adjustment's 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);
Adjustment adjustment = new Adjustment().withProrate(Prorate.NOT_PRORATED).withDescription("Description").withType(Type.AMOUNT).withValue(50d).withRelationToTotal(Adjustment.RelationToTotal.IN_ADDITION_TO);
reqData.getAdjustments().add(adjustment);
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(100d);
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(ADJUSTMENT_FUND_DISTRIBUTIONS_NOT_PRESENT.getDescription()));
assertThat(error.getCode(), equalTo(ADJUSTMENT_FUND_DISTRIBUTIONS_NOT_PRESENT.getCode()));
}
use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.
the class InvoicesApiTest method testTransitionToApprovedWithFundDistributionsTotalAmountNotEqualToLineTotal.
@Test
void testTransitionToApprovedWithFundDistributionsTotalAmountNotEqualToLineTotal() {
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(AMOUNT);
invoiceLine.getFundDistributions().get(0).setValue(100d);
invoiceLine.setSubTotal(300d);
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()));
}
Aggregations