Search in sources :

Example 1 with InvoiceModel

use of com.paypal.invoices.invoicesextract.model.InvoiceModel in project mirakl-hyperwallet-connector by paypal.

the class MiraklInvoicesExtractServiceImplTest 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<InvoiceModel> result = testObj.extractAccountingDocument(nowAsDate);
    assertThat(result).isEmpty();
}
Also used : LocalDateTime(java.time.LocalDateTime) Date(java.util.Date) InvoiceModel(com.paypal.invoices.invoicesextract.model.InvoiceModel) Test(org.junit.jupiter.api.Test)

Example 2 with InvoiceModel

use of com.paypal.invoices.invoicesextract.model.InvoiceModel in project mirakl-hyperwallet-connector by paypal.

the class MiraklInvoicesExtractServiceImplTest method extractAccountingDocument_whenMiraklExceptionIsThrown_shouldSendEmailNotification.

@Test
void extractAccountingDocument_whenMiraklExceptionIsThrown_shouldSendEmailNotification() {
    final LocalDateTime now = LocalDateTime.now();
    TimeMachine.useFixedClockAt(now);
    final Date nowAsDate = DateUtil.convertToDate(now, ZoneId.systemDefault());
    final InvoiceModel invoiceOne = InvoiceModel.builder().shopId(SHOP_ID_ONE).destinationToken(TOKEN_1).hyperwalletProgram(HYPERWALLET_PROGRAM).build();
    final List<InvoiceModel> invoiceList = List.of(invoiceOne);
    doReturn(invoiceList).when(testObj).getAccountingDocuments(nowAsDate);
    final MiraklApiException miraklApiException = new MiraklApiException(new MiraklErrorResponseBean(1, "Something went wrong"));
    doThrow(miraklApiException).when(miraklMarketplacePlatformOperatorApiClientMock).getShops(any(MiraklGetShopsRequest.class));
    testObj.extractAccountingDocument(nowAsDate);
    verify(mailNotificationUtilMock).sendPlainTextEmail("Issue detected getting shops in Mirakl", String.format("Something went wrong getting information of " + "shops" + " [2000]%n%s", MiraklLoggingErrorsUtil.stringify(miraklApiException)));
}
Also used : LocalDateTime(java.time.LocalDateTime) MiraklErrorResponseBean(com.mirakl.client.core.error.MiraklErrorResponseBean) MiraklApiException(com.mirakl.client.core.exception.MiraklApiException) MiraklGetShopsRequest(com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest) Date(java.util.Date) InvoiceModel(com.paypal.invoices.invoicesextract.model.InvoiceModel) Test(org.junit.jupiter.api.Test)

Example 3 with InvoiceModel

use of com.paypal.invoices.invoicesextract.model.InvoiceModel in project mirakl-hyperwallet-connector by paypal.

the class MiraklInvoicesExtractServiceImplTest method getInvoices_shouldReturnListOfInvoiceModels.

@Test
void getInvoices_shouldReturnListOfInvoiceModels() {
    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);
    when(miraklInvoicesOneMock.getHmcInvoices()).thenReturn(List.of(miraklInvoiceOneMock, miraklInvoiceTwoMock));
    when(miraklInvoicesOneMock.getTotalCount()).thenReturn(2L);
    when(miraklInvoiceToInvoiceModelConverterMock.convert(miraklInvoiceOneMock)).thenReturn(invoiceModelOneMock);
    when(miraklInvoiceToInvoiceModelConverterMock.convert(miraklInvoiceTwoMock)).thenReturn(invoiceModelTwoMock);
    final List<InvoiceModel> invoices = testObj.getAccountingDocuments(now);
    verify(miraklMarketplacePlatformOperatorApiClientMock).getInvoices(miraklGetInvoicesRequestArgumentCaptor.capture());
    final MiraklGetInvoicesRequest miraklGetInvoicesRequest = miraklGetInvoicesRequestArgumentCaptor.getValue();
    assertThat(miraklGetInvoicesRequest.getStartDate()).isEqualTo(now);
    assertThat(miraklGetInvoicesRequest.getStates()).isEqualTo(List.of(MiraklAccountingDocumentState.COMPLETE));
    assertThat(miraklGetInvoicesRequest.getPaymentStatus()).isEqualTo(MiraklAccountingDocumentPaymentStatus.PENDING);
    assertThat(invoices).containsExactlyInAnyOrder(invoiceModelOneMock, invoiceModelTwoMock);
}
Also used : MiraklGetInvoicesRequest(com.mirakl.client.mmp.operator.request.payment.invoice.MiraklGetInvoicesRequest) Date(java.util.Date) InvoiceModel(com.paypal.invoices.invoicesextract.model.InvoiceModel) Test(org.junit.jupiter.api.Test)

Example 4 with InvoiceModel

use of com.paypal.invoices.invoicesextract.model.InvoiceModel 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);
}
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) LocalDateTime(java.time.LocalDateTime) InvoiceModel(com.paypal.invoices.invoicesextract.model.InvoiceModel) Captor(org.mockito.Captor) AUTO_INVOICE(com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentType.AUTO_INVOICE) 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) MiraklApiException(com.mirakl.client.core.exception.MiraklApiException) MiraklAccountingDocumentState(com.mirakl.client.mmp.request.payment.invoice.MiraklAccountingDocumentState) 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) MiraklAccountingDocumentPaymentStatus(com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentPaymentStatus) Collections(java.util.Collections) HMCMiraklInvoice(com.paypal.infrastructure.sdk.mirakl.domain.invoice.HMCMiraklInvoice) Date(java.util.Date) InvoiceModel(com.paypal.invoices.invoicesextract.model.InvoiceModel) Test(org.junit.jupiter.api.Test)

Example 5 with InvoiceModel

use of com.paypal.invoices.invoicesextract.model.InvoiceModel in project mirakl-hyperwallet-connector by paypal.

the class MiraklInvoiceDTOToInvoiceModelConverterTest method convert_shouldMapEveryAttributeOfMiraklInvoiceMockDTOIntoInvoiceModel.

@SuppressWarnings("java:S5961")
@Test
void convert_shouldMapEveryAttributeOfMiraklInvoiceMockDTOIntoInvoiceModel() {
    TimeMachine.useFixedClockAt(LocalDateTime.of(2000, 11, 5, 12, 30, 22));
    final LocalDateTime now = TimeMachine.now();
    final Date fixedDate = DateUtil.convertToDate(now, ZoneId.systemDefault());
    final MiraklInvoiceMockDTO miraklInvoiceMockDTO = createMiraklInvoiceMockDTO();
    final InvoiceModel result = testObj.convert(miraklInvoiceMockDTO);
    assertThat(result.getShopId()).isEqualTo(SHOP_ID);
    assertThat(result.getShopName()).isEqualTo(SHOP_NAME);
    assertThat(result.getShopCorporateName()).isEqualTo(SHOP_CORPORATE_NAME);
    assertThat(result.getShopAddressLastName()).isEqualTo(SHOP_ADDRESS_LAST_NAME);
    assertThat(result.getShopAddressFirstName()).isEqualTo(SHOP_ADDRESS_FIRST_NAME);
    assertThat(result.getShopAddressStreet1()).isEqualTo(SHOP_ADDRESS_STREET_1);
    assertThat(result.getShopAddressStreet2()).isEqualTo(SHOP_ADDRESS_STREET_2);
    assertThat(result.getShopAddressComplementary()).isEqualTo(SHOP_ADDRESS_COMPLEMENTARY);
    assertThat(result.getShopAddressZipCode()).isEqualTo(SHOP_ADDRESS_ZIP_CODE);
    assertThat(result.getShopAddressCity()).isEqualTo(SHOP_ADDRESS_CITY);
    assertThat(result.getShopAddressCountry()).isEqualTo(SHOP_ADDRESS_COUNTRY);
    assertThat(result.getShopAddressState()).isEqualTo(SHOP_ADDRESS_STATE);
    assertThat(result.getShopEmail()).isEqualTo(SHOP_EMAIL);
    assertThat(result.isShopIsProfessional()).isFalse();
    assertThat(result.getShopVatNumber()).isEqualTo(SHOP_VAT_NUMBER);
    assertThat(result.getDateCreated()).isEqualTo(fixedDate);
    assertThat(result.getStartTime()).isEqualTo(fixedDate);
    assertThat(result.getEndTime()).isEqualTo(fixedDate);
    assertThat(result.getInvoiceNumber()).isEqualTo(INVOICE_NUMBER);
    assertThat(result.getPaymentInfoOwner()).isEqualTo(PAYMENT_INFO_OWNER);
    assertThat(result.getPaymentInfoBankName()).isEqualTo(PAYMENT_INFO_BANK_NAME);
    assertThat(result.getPaymentInfoBankStreet()).isEqualTo(PAYMENT_INFO_BANK_STREET);
    assertThat(result.getPaymentInfoBankZip()).isEqualTo(PAYMENT_INFO_BANK_ZIP);
    assertThat(result.getPaymentInfoBankCity()).isEqualTo(PAYMENT_INFO_BANK_CITY);
    assertThat(result.getPaymentInfoBic()).isEqualTo(PAYMENT_INFO_BIC);
    assertThat(result.getPaymentInfoIban()).isEqualTo(PAYMENT_INFO_IBAN);
    assertThat(result.getOrderAmount()).isEqualTo(100.D);
    assertThat(result.getOrderShippingAmount()).isEqualTo(10.0D);
    assertThat(result.getOrderCommissionAmount()).isEqualTo(1.0D);
    assertThat(result.getOrderCommissionAmountVat()).isEqualTo(2.0D);
    assertThat(result.getRefundAmount()).isEqualTo(3.0D);
    assertThat(result.getRefundShippingAmount()).isEqualTo(4.0D);
    assertThat(result.getRefundCommissionAmount()).isEqualTo(5.0D);
    assertThat(result.getRefundCommissionAmountVat()).isEqualTo(6.0D);
    assertThat(result.getSubscriptionAmount()).isEqualTo(7.0D);
    assertThat(result.getSubscriptionAmountVat()).isEqualTo(8.0D);
    assertThat(result.getTotalChargedAmount()).isEqualTo(9.0D);
    assertThat(result.getTotalChargedAmountVat()).isEqualTo(110.0D);
    assertThat(result.getTransferAmount()).isEqualTo(12.0D);
    assertThat(result.getShopOperatorInternalId()).isEqualTo(SHOP_OPERATOR_INTERNAL_ID);
    assertThat(result.getShopIdentificationNumber()).isEqualTo(SHOP_IDENTIFICATION_NUMBER);
    assertThat(result.getTotalManualInvoiceAmount()).isEqualTo(20.0D);
    assertThat(result.getTotalManualInvoiceAmountVat()).isEqualTo(21.0D);
    assertThat(result.getTotalManualCreditAmount()).isEqualTo(22.0D);
    assertThat(result.getTotalManualCreditAmountVat()).isEqualTo(23.0D);
    assertThat(result.getCurrencyIsoCode()).isEqualTo(CURRENCY_ISO_CODE);
    assertThat(result.getPaymentInfoType()).isEqualTo(PAYMENT_INFO_TYPE);
}
Also used : LocalDateTime(java.time.LocalDateTime) MiraklInvoiceMockDTO(com.paypal.invoices.dto.MiraklInvoiceMockDTO) Date(java.util.Date) InvoiceModel(com.paypal.invoices.invoicesextract.model.InvoiceModel) Test(org.junit.jupiter.api.Test)

Aggregations

InvoiceModel (com.paypal.invoices.invoicesextract.model.InvoiceModel)17 Test (org.junit.jupiter.api.Test)16 Date (java.util.Date)9 LocalDateTime (java.time.LocalDateTime)7 HyperwalletPayment (com.hyperwallet.clientsdk.model.HyperwalletPayment)5 MiraklGetShopsRequest (com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest)4 MiraklErrorResponseBean (com.mirakl.client.core.error.MiraklErrorResponseBean)2 MiraklApiException (com.mirakl.client.core.exception.MiraklApiException)2 MiraklGetInvoicesRequest (com.mirakl.client.mmp.operator.request.payment.invoice.MiraklGetInvoicesRequest)2 HyperwalletException (com.hyperwallet.clientsdk.HyperwalletException)1 MiraklAccountingDocumentPaymentStatus (com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentPaymentStatus)1 PENDING (com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentPaymentStatus.PENDING)1 AUTO_INVOICE (com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentType.AUTO_INVOICE)1 MiraklShop (com.mirakl.client.mmp.domain.shop.MiraklShop)1 MiraklShops (com.mirakl.client.mmp.domain.shop.MiraklShops)1 MiraklAccountingDocumentState (com.mirakl.client.mmp.request.payment.invoice.MiraklAccountingDocumentState)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