use of com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoice in project mirakl-hyperwallet-connector by paypal.
the class MiraklInvoicesExtractServiceImplTest method getAccountingDocument_whenRequestNeedsPagination_shouldRepeatRequestAndReturnAllInvoices.
@Test
void getAccountingDocument_whenRequestNeedsPagination_shouldRepeatRequestAndReturnAllInvoices() {
TimeMachine.useFixedClockAt(LocalDateTime.of(2020, 11, 10, 20, 0, 55));
final Date now = DateUtil.convertToDate(TimeMachine.now(), ZoneId.systemDefault());
final List<HMCMiraklInvoice> firstPageResponseInvoices = getListOfHMCMiraklInvoiceMocks(MIRAKL_MAX_RESULTS_PER_PAGE);
final List<HMCMiraklInvoice> secondPageResponseInvoices = getListOfHMCMiraklInvoiceMocks(MIRAKL_MAX_RESULTS_PER_PAGE / 2);
final long totalResponseInvoices = firstPageResponseInvoices.size() + secondPageResponseInvoices.size();
when(miraklMarketplacePlatformOperatorApiClientMock.getInvoices(argThat(request -> request != null && request.getOffset() == 0))).thenReturn(miraklInvoicesOneMock);
when(miraklMarketplacePlatformOperatorApiClientMock.getInvoices(argThat(request -> request != null && request.getOffset() == MIRAKL_MAX_RESULTS_PER_PAGE))).thenReturn(miraklInvoicesTwoMock);
when(miraklInvoicesOneMock.getTotalCount()).thenReturn(totalResponseInvoices);
when(miraklInvoicesOneMock.getHmcInvoices()).thenReturn(firstPageResponseInvoices);
when(miraklInvoicesTwoMock.getTotalCount()).thenReturn(totalResponseInvoices);
when(miraklInvoicesTwoMock.getHmcInvoices()).thenReturn(secondPageResponseInvoices);
final List<InvoiceModel> expectedCreditNotes = Stream.concat(firstPageResponseInvoices.stream(), secondPageResponseInvoices.stream()).map(invoice -> mockAndReturn(invoice)).collect(Collectors.toList());
final List<InvoiceModel> result = testObj.getAccountingDocuments(now);
assertThat(result).containsExactlyElementsOf(expectedCreditNotes);
}
use of com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoice in project mirakl-hyperwallet-connector by paypal.
the class MiraklCreditNotesExtractServiceImplTest method getAccountingDocuments_whenRequestNeedsPagination_shouldRepeatRequestAndReturnAllInvoices.
@Test
void getAccountingDocuments_whenRequestNeedsPagination_shouldRepeatRequestAndReturnAllInvoices() {
TimeMachine.useFixedClockAt(LocalDateTime.of(2020, 11, 10, 20, 0, 55));
final Date now = DateUtil.convertToDate(TimeMachine.now(), ZoneId.systemDefault());
final List<HMCMiraklInvoice> firstPageResponseInvoices = getListOfHMCMiraklInvoiceMocks(MIRAKL_MAX_RESULTS_PER_PAGE);
final List<HMCMiraklInvoice> secondPageResponseInvoices = getListOfHMCMiraklInvoiceMocks(MIRAKL_MAX_RESULTS_PER_PAGE / 2);
final long totalResponseInvoices = firstPageResponseInvoices.size() + secondPageResponseInvoices.size();
when(miraklMarketplacePlatformOperatorApiClientMock.getInvoices(argThat(request -> request != null && request.getOffset() == 0))).thenReturn(miraklInvoicesOneMock);
when(miraklMarketplacePlatformOperatorApiClientMock.getInvoices(argThat(request -> request != null && request.getOffset() == MIRAKL_MAX_RESULTS_PER_PAGE))).thenReturn(miraklInvoicesTwoMock);
when(miraklInvoicesOneMock.getTotalCount()).thenReturn(totalResponseInvoices);
when(miraklInvoicesOneMock.getHmcInvoices()).thenReturn(firstPageResponseInvoices);
when(miraklInvoicesTwoMock.getTotalCount()).thenReturn(totalResponseInvoices);
when(miraklInvoicesTwoMock.getHmcInvoices()).thenReturn(secondPageResponseInvoices);
final List<CreditNoteModel> expectedCreditNotes = Stream.concat(firstPageResponseInvoices.stream(), secondPageResponseInvoices.stream()).map(invoice -> mockAndReturn(invoice)).collect(Collectors.toList());
final List<CreditNoteModel> result = testObj.getAccountingDocuments(now);
assertThat(result).containsExactlyElementsOf(expectedCreditNotes);
}
use of com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoice in project mirakl-hyperwallet-connector by paypal.
the class AbstractAccountingDocumentsExtractServiceImpl method getInvoicesForDateAndType.
protected List<HMCMiraklInvoice> getInvoicesForDateAndType(final Date delta, final InvoiceTypeEnum invoiceType) {
final List<HMCMiraklInvoice> invoices = new ArrayList<>();
int offset = 0;
final MiraklGetInvoicesRequest accountingDocumentRequest = createAccountingDocumentRequest(delta, invoiceType);
while (true) {
accountingDocumentRequest.setOffset(offset);
final HMCMiraklInvoices receivedInvoices = miraklMarketplacePlatformOperatorApiClient.getInvoices(accountingDocumentRequest);
invoices.addAll(receivedInvoices.getHmcInvoices());
if (receivedInvoices.getTotalCount() <= invoices.size()) {
break;
}
offset += MIRAKL_MAX_RESULTS_PER_PAGE;
}
return invoices;
}
Aggregations