use of com.paypal.invoices.invoicesextract.model.CreditNoteModel in project mirakl-hyperwallet-connector by paypal.
the class MiraklCreditNotesExtractServiceImplTest method mockAndReturn.
private CreditNoteModel mockAndReturn(final HMCMiraklInvoice invoice) {
final CreditNoteModel creditNoteModelMock = mock(CreditNoteModel.class);
when(miraklInvoiceToCreditNoteModelConverter.convert(invoice)).thenReturn(creditNoteModelMock);
return creditNoteModelMock;
}
use of com.paypal.invoices.invoicesextract.model.CreditNoteModel in project mirakl-hyperwallet-connector by paypal.
the class HyperWalletPaymentExtractServiceImplTest method payPayeeCreditNote_shouldReturnOnlyPaymentsSuccessfullyCreatedOnHyperwallet.
@Test
void payPayeeCreditNote_shouldReturnOnlyPaymentsSuccessfullyCreatedOnHyperwallet() {
final List<CreditNoteModel> creditNoteList = List.of(creditNoteModelOneMock, creditNoteModelTwoMock);
when(creditNoteModelHyperwalletPaymentConverterMock.convert(creditNoteModelOneMock)).thenReturn(paymentOneMock);
when(creditNoteModelHyperwalletPaymentConverterMock.convert(creditNoteModelTwoMock)).thenReturn(paymentTwoMock);
when(hyperwalletMock.createPayment(paymentOneMock)).thenReturn(createdPaymentOneMock);
when(paymentOneMock.getProgramToken()).thenReturn(PROGRAM_TOKEN);
when(paymentTwoMock.getProgramToken()).thenReturn(PROGRAM_TOKEN);
when(hyperwalletSDKService.getHyperwalletInstanceWithProgramToken(PROGRAM_TOKEN)).thenReturn(hyperwalletMock);
doThrow(new HyperwalletException("Something went wrong")).when(hyperwalletMock).createPayment(paymentTwoMock);
final List<HyperwalletPayment> result = testObj.payPayeeCreditNote(creditNoteList);
verify(creditNoteModelHyperwalletPaymentConverterMock).convert(creditNoteModelOneMock);
verify(creditNoteModelHyperwalletPaymentConverterMock).convert(creditNoteModelTwoMock);
verify(hyperwalletMock).createPayment(paymentOneMock);
verify(hyperwalletMock).createPayment(paymentTwoMock);
assertThat(result).containsExactlyInAnyOrder(createdPaymentOneMock);
}
use of com.paypal.invoices.invoicesextract.model.CreditNoteModel in project mirakl-hyperwallet-connector by paypal.
the class MiraklCreditNotesExtractServiceImplTest method getAccountingDocuments_whenNoMiraklCreditNotesAreReceived_shouldReturnEmptyList.
@Test
void getAccountingDocuments_whenNoMiraklCreditNotesAreReceived_shouldReturnEmptyList() {
TimeMachine.useFixedClockAt(LocalDateTime.of(2020, 11, 10, 20, 0, 55));
final Date now = DateUtil.convertToDate(TimeMachine.now(), ZoneId.systemDefault());
when(miraklMarketplacePlatformOperatorApiClientMock.getInvoices(any())).thenReturn(miraklInvoicesOneMock);
final List<CreditNoteModel> creditNoteList = testObj.getAccountingDocuments(now);
assertThat(creditNoteList).isEqualTo(Collections.emptyList());
}
use of com.paypal.invoices.invoicesextract.model.CreditNoteModel 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.invoices.invoicesextract.model.CreditNoteModel in project mirakl-hyperwallet-connector by paypal.
the class MiraklCreditNotesExtractServiceImplTest method extractAccountingDocument_whenNoInvoicesAreReturned_shouldReturnEmptyList.
@Test
void extractAccountingDocument_whenNoInvoicesAreReturned_shouldReturnEmptyList() {
final LocalDateTime now = LocalDateTime.now();
TimeMachine.useFixedClockAt(now);
final Date nowAsDate = DateUtil.convertToDate(now, ZoneId.systemDefault());
doReturn(Collections.emptyList()).when(testObj).getAccountingDocuments(nowAsDate);
final List<CreditNoteModel> result = testObj.extractAccountingDocument(nowAsDate);
assertThat(result).isEmpty();
}
Aggregations