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);
}
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);
}
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()));
}
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));
}
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));
}
Aggregations