Search in sources :

Example 1 with CreditNoteModel

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;
}
Also used : CreditNoteModel(com.paypal.invoices.invoicesextract.model.CreditNoteModel)

Example 2 with CreditNoteModel

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);
}
Also used : HyperwalletPayment(com.hyperwallet.clientsdk.model.HyperwalletPayment) HyperwalletException(com.hyperwallet.clientsdk.HyperwalletException) CreditNoteModel(com.paypal.invoices.invoicesextract.model.CreditNoteModel) Test(org.junit.jupiter.api.Test)

Example 3 with CreditNoteModel

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());
}
Also used : CreditNoteModel(com.paypal.invoices.invoicesextract.model.CreditNoteModel) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 4 with CreditNoteModel

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);
}
Also used : IntStream(java.util.stream.IntStream) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) DateUtil(com.paypal.infrastructure.util.DateUtil) BeforeEach(org.junit.jupiter.api.BeforeEach) Converter(com.paypal.infrastructure.converter.Converter) MIRAKL_MAX_RESULTS_PER_PAGE(com.paypal.infrastructure.constants.HyperWalletConstants.MIRAKL_MAX_RESULTS_PER_PAGE) Mock(org.mockito.Mock) Date(java.util.Date) PENDING(com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentPaymentStatus.PENDING) MiraklGetInvoicesRequest(com.mirakl.client.mmp.operator.request.payment.invoice.MiraklGetInvoicesRequest) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) MiraklInvoice(com.mirakl.client.mmp.domain.invoice.MiraklInvoice) LocalDateTime(java.time.LocalDateTime) Captor(org.mockito.Captor) MiraklMarketplacePlatformOperatorApiWrapper(com.paypal.infrastructure.sdk.mirakl.MiraklMarketplacePlatformOperatorApiWrapper) ArgumentCaptor(org.mockito.ArgumentCaptor) ExtendWith(org.junit.jupiter.api.extension.ExtendWith) AccountingDocumentModel(com.paypal.invoices.invoicesextract.model.AccountingDocumentModel) MANUAL_CREDIT(com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentType.MANUAL_CREDIT) CreditNoteModel(com.paypal.invoices.invoicesextract.model.CreditNoteModel) MiraklApiException(com.mirakl.client.core.exception.MiraklApiException) MockitoExtension(org.mockito.junit.jupiter.MockitoExtension) MiraklShops(com.mirakl.client.mmp.domain.shop.MiraklShops) Set(java.util.Set) MiraklGetShopsRequest(com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest) HMCMiraklInvoice(com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoice) MiraklLoggingErrorsUtil(com.paypal.infrastructure.util.MiraklLoggingErrorsUtil) Collectors(java.util.stream.Collectors) MailNotificationUtil(com.paypal.infrastructure.mail.MailNotificationUtil) ZoneId(java.time.ZoneId) Test(org.junit.jupiter.api.Test) Mockito(org.mockito.Mockito) List(java.util.List) TimeMachine(com.paypal.infrastructure.util.TimeMachine) Stream(java.util.stream.Stream) InvoiceTypeEnum(com.paypal.invoices.invoicesextract.model.InvoiceTypeEnum) MiraklShop(com.mirakl.client.mmp.domain.shop.MiraklShop) MiraklErrorResponseBean(com.mirakl.client.core.error.MiraklErrorResponseBean) COMPLETE(com.mirakl.client.mmp.request.payment.invoice.MiraklAccountingDocumentState.COMPLETE) HMCMiraklInvoices(com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoices) Collections(java.util.Collections) HMCMiraklInvoice(com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoice) CreditNoteModel(com.paypal.invoices.invoicesextract.model.CreditNoteModel) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 5 with CreditNoteModel

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();
}
Also used : LocalDateTime(java.time.LocalDateTime) CreditNoteModel(com.paypal.invoices.invoicesextract.model.CreditNoteModel) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Aggregations

CreditNoteModel (com.paypal.invoices.invoicesextract.model.CreditNoteModel)12 Test (org.junit.jupiter.api.Test)11 Date (java.util.Date)8 LocalDateTime (java.time.LocalDateTime)6 MiraklGetShopsRequest (com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest)4 HyperwalletPayment (com.hyperwallet.clientsdk.model.HyperwalletPayment)3 MiraklErrorResponseBean (com.mirakl.client.core.error.MiraklErrorResponseBean)2 MiraklApiException (com.mirakl.client.core.exception.MiraklApiException)2 MiraklInvoice (com.mirakl.client.mmp.domain.invoice.MiraklInvoice)2 MiraklGetInvoicesRequest (com.mirakl.client.mmp.operator.request.payment.invoice.MiraklGetInvoicesRequest)2 HyperwalletException (com.hyperwallet.clientsdk.HyperwalletException)1 PENDING (com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentPaymentStatus.PENDING)1 MANUAL_CREDIT (com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentType.MANUAL_CREDIT)1 MiraklShop (com.mirakl.client.mmp.domain.shop.MiraklShop)1 MiraklShops (com.mirakl.client.mmp.domain.shop.MiraklShops)1 COMPLETE (com.mirakl.client.mmp.request.payment.invoice.MiraklAccountingDocumentState.COMPLETE)1 MIRAKL_MAX_RESULTS_PER_PAGE (com.paypal.infrastructure.constants.HyperWalletConstants.MIRAKL_MAX_RESULTS_PER_PAGE)1 Converter (com.paypal.infrastructure.converter.Converter)1 MailNotificationUtil (com.paypal.infrastructure.mail.MailNotificationUtil)1 MiraklMarketplacePlatformOperatorApiWrapper (com.paypal.infrastructure.sdk.mirakl.MiraklMarketplacePlatformOperatorApiWrapper)1