use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.
the class InvoiceLinesApiTest method testPutInvoiceLineUpdateTotalAndInvoice.
@Test
public void testPutInvoiceLineUpdateTotalAndInvoice() {
logger.info("=== Test case when invoice line updates triggers also invoice update ===");
InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_OUTDATED_TOTAL_PATH).mapTo(InvoiceLine.class);
addMockEntry(INVOICE_LINES, invoiceLine);
invoiceLine.setSubTotal(100.500d);
verifyPut(invoiceLine.getId(), JsonObject.mapFrom(invoiceLine), "", 204);
MatcherAssert.assertThat(getInvoiceLineRetrievals(), hasSize(1));
MatcherAssert.assertThat(getInvoiceRetrievals(), hasSize(1));
MatcherAssert.assertThat(getInvoiceLineUpdates(), hasSize(1));
InvoiceLine updatedInvoiceLine = getInvoiceLineUpdates().get(0).mapTo(InvoiceLine.class);
Assertions.assertEquals(100.5d, updatedInvoiceLine.getSubTotal());
Assertions.assertEquals(10.15d, updatedInvoiceLine.getAdjustmentsTotal());
Assertions.assertEquals(110.65d, updatedInvoiceLine.getTotal());
MatcherAssert.assertThat(getInvoiceUpdates(), hasSize(1));
Invoice updatedInvoice = getInvoiceUpdates().get(0).mapTo(Invoice.class);
// invoice totals are using the line totals pre-update because the mock server is not actually modifying the line,
// but we can check the total was correctly updated
Assertions.assertEquals(4.2d, updatedInvoice.getSubTotal());
Assertions.assertEquals(0.42d, updatedInvoice.getAdjustmentsTotal());
Assertions.assertEquals(4.62d, updatedInvoice.getTotal());
}
use of org.folio.rest.jaxrs.model.Invoice in project mod-invoice by folio-org.
the class InvoiceLinesApiTest method checkInvoiceLineUpdateUpdatesInvoicePoNumbers.
@Test
public void checkInvoiceLineUpdateUpdatesInvoicePoNumbers() {
logger.info("=== Check an invoice line update triggers the update of the invoice's poNumbers field ===");
InvoiceLine invoiceLine = getMockAsJson(INVOICE_LINE_WITH_PO_NUMBER_PATH).mapTo(InvoiceLine.class);
invoiceLine.setInvoiceId(OPEN_INVOICE_ID);
addMockEntry(INVOICE_LINES, invoiceLine);
verifyPut(INVOICE_LINE_WITH_PO_NUMBER, JsonObject.mapFrom(invoiceLine), "", 204);
List<JsonObject> objects = serverRqRs.get(INVOICES, HttpMethod.PUT);
assertThat(objects, notNullValue());
Invoice updatedInvoice = objects.get(0).mapTo(Invoice.class);
List<String> poNumbers = updatedInvoice.getPoNumbers();
// that invoice already had a poNumber, it gets another one
assertThat(poNumbers, hasSize(2));
assertThat(poNumbers.get(1), equalTo("AB268758XYZ"));
}
use of org.folio.rest.jaxrs.model.Invoice 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.Invoice 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.Invoice 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