Search in sources :

Example 96 with Invoice

use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.

the class InvoicesApiTest method testShouldAlwaysRecalculateTotalAndSubTotalWhenGetInvoicingInvoicesById.

@Test
void testShouldAlwaysRecalculateTotalAndSubTotalWhenGetInvoicingInvoicesById() {
    logger.info("=== Test Get Invoice By Id ===");
    final Invoice resp = verifySuccessGet(String.format(INVOICE_ID_PATH, APPROVED_INVOICE_ID), Invoice.class);
    logger.info(JsonObject.mapFrom(resp).encodePrettily());
    assertThat(resp.getId(), equalTo(APPROVED_INVOICE_ID));
    // Verify that expected number of external calls made
    assertThat(getInvoiceRetrievals(), hasSize(1));
    assertThat(getInvoiceLineSearches(), hasSize(1));
    verifyInvoiceUpdateCalls(0);
}
Also used : Invoice(org.folio.rest.jaxrs.model.Invoice) Test(org.junit.jupiter.api.Test)

Example 97 with Invoice

use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.

the class InvoicesApiTest method testTransitionToApprovedWithEmptyConfig.

@Test
void testTransitionToApprovedWithEmptyConfig() {
    logger.info("=== Test transition invoice to Approved with empty config ===");
    Invoice reqData = getMockAsJson(REVIEWED_INVOICE_SAMPLE_PATH).mapTo(Invoice.class);
    reqData.setStatus(Invoice.Status.APPROVED);
    String id = reqData.getId();
    String jsonBody = JsonObject.mapFrom(reqData).encode();
    Headers nonExistConfigHeaders = prepareHeaders(X_OKAPI_URL, NON_EXIST_CONFIG_X_OKAPI_TENANT, X_OKAPI_TOKEN, X_OKAPI_USER_ID);
    verifySuccessfulPut(prepareInvoiceLines(reqData), reqData, id, jsonBody, nonExistConfigHeaders);
    MockServer.release();
    Headers nonExistValueConfigHeaders = prepareHeaders(X_OKAPI_URL, PREFIX_CONFIG_WITHOUT_VALUE_X_OKAPI_TENANT, X_OKAPI_TOKEN, X_OKAPI_USER_ID);
    verifySuccessfulPut(prepareInvoiceLines(reqData), reqData, id, jsonBody, nonExistValueConfigHeaders);
    MockServer.release();
    Headers nonExistNeededValueConfigHeaders = prepareHeaders(X_OKAPI_URL, PREFIX_CONFIG_WITH_NON_EXISTING_VALUE_X_OKAPI_TENANT, X_OKAPI_TOKEN, X_OKAPI_USER_ID);
    verifySuccessfulPut(prepareInvoiceLines(reqData), reqData, id, jsonBody, nonExistNeededValueConfigHeaders);
}
Also used : Invoice(org.folio.rest.jaxrs.model.Invoice) Headers(io.restassured.http.Headers) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 98 with Invoice

use of org.folio.rest.jaxrs.model.Invoice 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()));
}
Also used : Errors(org.folio.rest.jaxrs.model.Errors) Invoice(org.folio.rest.jaxrs.model.Invoice) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) Error(org.folio.rest.jaxrs.model.Error) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 99 with Invoice

use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.

the class InvoicesApiTest method testTransitionToApprovedWithoutInvoiceLines.

@Test
void testTransitionToApprovedWithoutInvoiceLines() {
    logger.info("=== Test transition invoice to Approved without invoiceLines should fail ===");
    Invoice reqData = getMockAsJson(REVIEWED_INVOICE_WITH_EXISTING_VOUCHER_SAMPLE_PATH).mapTo(Invoice.class);
    reqData.setStatus(Invoice.Status.APPROVED);
    String id = reqData.getId();
    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, 500).then().extract().body().as(Errors.class);
    assertThat(errors, notNullValue());
    assertThat(errors.getErrors(), hasSize(1));
    assertThat(errors.getErrors().get(0).getMessage(), equalTo(NO_INVOICE_LINES_ERROR_MSG));
}
Also used : Errors(org.folio.rest.jaxrs.model.Errors) Invoice(org.folio.rest.jaxrs.model.Invoice) Headers(io.restassured.http.Headers) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 100 with Invoice

use of org.folio.rest.jaxrs.model.Invoice 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));
}
Also used : Errors(org.folio.rest.jaxrs.model.Errors) Invoice(org.folio.rest.jaxrs.model.Invoice) InvoiceLine(org.folio.rest.jaxrs.model.InvoiceLine) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Aggregations

Invoice (org.folio.rest.jaxrs.model.Invoice)128 Test (org.junit.jupiter.api.Test)99 InvoiceLine (org.folio.rest.jaxrs.model.InvoiceLine)87 Matchers.containsString (org.hamcrest.Matchers.containsString)56 Adjustment (org.folio.rest.jaxrs.model.Adjustment)47 JsonObject (io.vertx.core.json.JsonObject)43 Headers (io.restassured.http.Headers)40 Errors (org.folio.rest.jaxrs.model.Errors)37 Error (org.folio.rest.jaxrs.model.Error)32 FundDistribution (org.folio.rest.jaxrs.model.FundDistribution)29 InvoiceLineCollection (org.folio.rest.jaxrs.model.InvoiceLineCollection)29 List (java.util.List)28 Voucher (org.folio.rest.jaxrs.model.Voucher)28 RequestContext (org.folio.rest.core.models.RequestContext)27 HashMap (java.util.HashMap)24 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)24 Vertx (io.vertx.core.Vertx)23 Fund (org.folio.rest.acq.model.finance.Fund)23 ArrayList (java.util.ArrayList)22 Collections (java.util.Collections)21