use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.
the class InvoiceLinesApiTest method testGetInvoiceLinesByIdValidAdjustments.
@Test
public void testGetInvoiceLinesByIdValidAdjustments() throws Exception {
logger.info("=== Test Get Invoice line By Id, adjustments are re calculated ===");
JsonObject invoiceLinesList = new JsonObject(getMockData(INVOICE_LINES_LIST_PATH));
JsonObject invoiceLine = invoiceLinesList.getJsonArray("invoiceLines").getJsonObject(4);
String id = invoiceLine.getString(ID);
double incorrectAdjustmentTotal = invoiceLine.getDouble("adjustmentsTotal");
logger.info(String.format("using mock datafile: %s%s.json", INVOICE_LINES_LIST_PATH, id));
final InvoiceLine resp = verifySuccessGetById(id, true, true);
logger.info(JsonObject.mapFrom(resp).encodePrettily());
Assertions.assertEquals(id, resp.getId());
assertThat(resp.getAdjustmentsTotal(), not(incorrectAdjustmentTotal));
}
use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.
the class InvoiceLinesProratedAdjustmentsTest method compareRecordWithSentToStorage.
private void compareRecordWithSentToStorage(InvoiceLine invoiceLine) {
// Verify that invoice line sent to storage is the same as in response
assertThat(getInvoiceLineCreations(), Matchers.hasSize(1));
InvoiceLine invoiceLineToStorage = getInvoiceLineCreations().get(0).mapTo(InvoiceLine.class);
assertThat(invoiceLine, equalTo(invoiceLineToStorage));
}
use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.
the class InvoiceLinesProratedAdjustmentsTest method testCreateFirstLineForInvoiceWithOneAdj.
@ParameterizedTest
@CsvSource({ "BY_AMOUNT, AMOUNT", "BY_AMOUNT, PERCENTAGE", "BY_LINE, AMOUNT", "BY_LINE, PERCENTAGE", "BY_QUANTITY, AMOUNT", "BY_QUANTITY, PERCENTAGE" })
public void testCreateFirstLineForInvoiceWithOneAdj(Adjustment.Prorate prorate, Adjustment.Type type) {
logger.info("=== Creating first line for invoice with one prorated adjustment ===");
// Prepare data "from storage"
Invoice invoice = getMockAsJson(OPEN_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withId(randomUUID().toString());
Adjustment invoiceAdjustment = createAdjustment(prorate, type, 15d);
invoice.withAdjustments(Collections.singletonList(invoiceAdjustment));
addMockEntry(INVOICES, invoice);
// Prepare request body
InvoiceLine invoiceLineBody = getMockInvoiceLine(invoice.getId()).withSubTotal(25d).withQuantity(10);
// Send update request
InvoiceLine invoiceLine = verifySuccessPost(INVOICE_LINES_PATH, invoiceLineBody).as(InvoiceLine.class);
// Verification
assertThat(getInvoiceLineUpdates(), Matchers.hasSize(0));
assertThat(getInvoiceUpdates(), Matchers.hasSize(1));
compareRecordWithSentToStorage(invoiceLine);
/*
* Calculated adjustment value depends of type:
* "Amount" - this is the same as adjustment value
* "Percentage" - this is the percentage of subTotal i.e. 15% of 25$ = 3.75$
*/
double expectedAdjTotal = (type == Adjustment.Type.AMOUNT) ? 15d : 3.75d;
double expectedAdjValue = expectedAdjTotal;
assertThat(invoiceLine.getAdjustments(), hasSize(1));
assertThat(invoiceLine.getAdjustmentsTotal(), is(expectedAdjTotal));
Adjustment lineAdjustment = invoiceLine.getAdjustments().get(0);
verifyInvoiceLineAdjustmentCommon(invoiceAdjustment, lineAdjustment);
assertThat(lineAdjustment.getValue(), is(expectedAdjValue));
}
use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.
the class InvoiceLinesProratedAdjustmentsTest method testUpdateLineForInvoiceWithOneAdj.
@ParameterizedTest
@CsvSource({ "BY_AMOUNT, AMOUNT", "BY_AMOUNT, PERCENTAGE", "BY_LINE, AMOUNT", "BY_LINE, PERCENTAGE", "BY_QUANTITY, AMOUNT", "BY_QUANTITY, PERCENTAGE" })
public void testUpdateLineForInvoiceWithOneAdj(Adjustment.Prorate prorate, Adjustment.Type type) {
logger.info("=== Updating line for invoice with only one line and one prorated adjustment ===");
// Prepare data "from storage"
Invoice invoice = getMockAsJson(OPEN_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withId(randomUUID().toString());
Adjustment invoiceAdjustment = createAdjustment(prorate, type, 15d);
invoice.withAdjustments(Collections.singletonList(invoiceAdjustment));
addMockEntry(INVOICES, invoice);
InvoiceLine lineData = getMockInvoiceLine(invoice.getId()).withSubTotal(15d).withQuantity(5);
lineData.setAdjustments(Collections.singletonList(createAdjustment(Adjustment.Prorate.NOT_PRORATED, type, 15d).withAdjustmentId(invoiceAdjustment.getId())));
addMockEntry(INVOICE_LINES, lineData);
// Prepare request body
InvoiceLine invoiceLineBody = copyObject(lineData).withSubTotal(25d).withQuantity(10);
String lineId = invoiceLineBody.getId();
// Send update request
verifySuccessPut(String.format(INVOICE_LINE_ID_PATH, lineId), invoiceLineBody);
// Verification
assertThat(getInvoiceLineUpdates(), Matchers.hasSize(1));
assertThat(getInvoiceUpdates(), Matchers.hasSize(1));
InvoiceLine lineToStorage = getLineToStorageById(lineId);
assertThat(lineToStorage.getAdjustments(), hasSize(1));
/*
* Calculated adjustment value depends of type:
* "Amount" - this is the same as adjustment value
* "Percentage" - this is the percentage of subTotal i.e. 15% of 25$ = 3.75$
*/
double expectedAdjTotal = (type == Adjustment.Type.AMOUNT) ? 15d : 3.75d;
double expectedAdjValue = expectedAdjTotal;
assertThat(lineToStorage.getAdjustments(), hasSize(1));
assertThat(lineToStorage.getAdjustmentsTotal(), is(expectedAdjTotal));
Adjustment lineAdjustment = lineToStorage.getAdjustments().get(0);
verifyInvoiceLineAdjustmentCommon(invoiceAdjustment, lineAdjustment);
assertThat(lineAdjustment.getValue(), is(expectedAdjValue));
}
use of org.folio.rest.jaxrs.model.InvoiceLine in project mod-invoice by folio-org.
the class InvoiceLinesProratedAdjustmentsTest method testDeleteLineForInvoiceWithOneAdj.
@ParameterizedTest
@CsvSource({ "BY_AMOUNT, AMOUNT", "BY_AMOUNT, PERCENTAGE", "BY_LINE, AMOUNT", "BY_LINE, PERCENTAGE", "BY_QUANTITY, AMOUNT", "BY_QUANTITY, PERCENTAGE" })
public void testDeleteLineForInvoiceWithOneAdj(Adjustment.Prorate prorate, Adjustment.Type type) {
logger.info("=== Deleting line for invoice with 2 lines and one prorated adjustment ===");
// Prepare data "from storage"
Invoice invoice = getMockAsJson(OPEN_INVOICE_SAMPLE_PATH).mapTo(Invoice.class).withId(randomUUID().toString());
Adjustment invoiceAdjustment = createAdjustment(prorate, type, 15d);
invoice.withAdjustments(Collections.singletonList(invoiceAdjustment));
addMockEntry(INVOICES, invoice);
InvoiceLine line1 = getMockInvoiceLine(invoice.getId()).withSubTotal(25d).withQuantity(10);
addMockEntry(INVOICE_LINES, line1);
InvoiceLine line2 = getMockInvoiceLine(invoice.getId()).withSubTotal(15d).withQuantity(5);
addMockEntry(INVOICE_LINES, line2);
// Send update request
verifyDeleteResponse(String.format(INVOICE_LINE_ID_PATH, line2.getId()), "", 204);
// Verification
assertThat(getInvoiceLineUpdates(), Matchers.hasSize(1));
assertThat(getInvoiceUpdates(), Matchers.hasSize(1));
InvoiceLine lineToStorage = getLineToStorageById(line1.getId());
assertThat(lineToStorage.getAdjustments(), hasSize(1));
/*
* Calculated adjustment value depends of type:
* "Amount" - this is the same as adjustment value
* "Percentage" - this is the percentage of subTotal i.e. 15% of 25$ = 3.75$
*/
double expectedAdjTotal = (type == Adjustment.Type.AMOUNT) ? 15d : 3.75d;
double expectedAdjValue = expectedAdjTotal;
assertThat(lineToStorage.getAdjustments(), hasSize(1));
assertThat(lineToStorage.getAdjustmentsTotal(), is(expectedAdjTotal));
Adjustment lineAdjustment = lineToStorage.getAdjustments().get(0);
verifyInvoiceLineAdjustmentCommon(invoiceAdjustment, lineAdjustment);
assertThat(lineAdjustment.getValue(), is(expectedAdjValue));
}
Aggregations