Search in sources :

Example 11 with InvoiceModel

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

the class MiraklInvoicesExtractServiceImplTest method extractAccountingDocument_whenSeveralInvoicesPerShopAreExtractedFromMirakl_shouldPopulateInvoicesExcludingInvoicesWithoutDestinationTokenAndHyperwalletProgram.

@Test
void extractAccountingDocument_whenSeveralInvoicesPerShopAreExtractedFromMirakl_shouldPopulateInvoicesExcludingInvoicesWithoutDestinationTokenAndHyperwalletProgram() {
    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).build();
    final InvoiceModel invoiceTwo = InvoiceModel.builder().shopId(SHOP_ID_TWO).destinationToken(TOKEN_2).build();
    final InvoiceModel invoiceThree = InvoiceModel.builder().shopId(SHOP_ID_ONE).destinationToken(TOKEN_1).build();
    doReturn(List.of(invoiceOne, invoiceTwo, invoiceThree)).when(testObj).getAccountingDocuments(nowAsDate);
    when(miraklShopsMock.getShops()).thenReturn(List.of(miraklShopOneMock, miraklShopTwoMock, miraklShopThreeMock));
    when(miraklMarketplacePlatformOperatorApiClientMock.getShops(any(MiraklGetShopsRequest.class))).thenReturn(miraklShopsMock);
    when(miraklShopToAccountingModelConverter.convert(miraklShopOneMock)).thenReturn(invoiceModelConvertedFromShopOneMock);
    when(miraklShopToAccountingModelConverter.convert(miraklShopTwoMock)).thenReturn(invoiceModelConvertedFromShopTwoMock);
    when(miraklShopToAccountingModelConverter.convert(miraklShopThreeMock)).thenReturn(invoiceModelConvertedFromShopThreeMock);
    when(invoiceModelConvertedFromShopOneMock.getShopId()).thenReturn(SHOP_ID_ONE);
    when(invoiceModelConvertedFromShopTwoMock.getShopId()).thenReturn(SHOP_ID_TWO);
    when(invoiceModelConvertedFromShopThreeMock.getShopId()).thenReturn(SHOP_ID_ONE);
    when(invoiceModelConvertedFromShopOneMock.getDestinationToken()).thenReturn(TOKEN_1);
    when(invoiceModelConvertedFromShopTwoMock.getDestinationToken()).thenReturn(TOKEN_2);
    when(invoiceModelConvertedFromShopThreeMock.getDestinationToken()).thenReturn(TOKEN_1);
    when(invoiceModelConvertedFromShopOneMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM);
    when(invoiceModelConvertedFromShopTwoMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM);
    when(invoiceModelConvertedFromShopThreeMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM);
    final List<InvoiceModel> result = testObj.extractAccountingDocument(nowAsDate);
    verify(miraklMarketplacePlatformOperatorApiClientMock).getShops(miraklGetShopsRequestArgumentCaptor.capture());
    assertThat(miraklGetShopsRequestArgumentCaptor.getValue().getShopIds()).containsExactlyInAnyOrder(SHOP_ID_ONE, SHOP_ID_TWO);
    assertThat(result.get(0)).hasFieldOrPropertyWithValue(SHOP_ID_ATTRIBUTE, SHOP_ID_ONE).hasFieldOrPropertyWithValue(DESTINATION_TOKEN_ATTRIBUTE, TOKEN_1);
    assertThat(result.get(1)).hasFieldOrPropertyWithValue(SHOP_ID_ATTRIBUTE, SHOP_ID_TWO).hasFieldOrPropertyWithValue(DESTINATION_TOKEN_ATTRIBUTE, TOKEN_2);
    assertThat(result.get(2)).hasFieldOrPropertyWithValue(SHOP_ID_ATTRIBUTE, SHOP_ID_ONE).hasFieldOrPropertyWithValue(DESTINATION_TOKEN_ATTRIBUTE, TOKEN_1);
}
Also used : LocalDateTime(java.time.LocalDateTime) 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 12 with InvoiceModel

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

the class MiraklInvoicesExtractServiceImplTest method getInvoices_whenNoMiraklInvoicesAreReceived_shouldReturnEmptyList.

@Test
void getInvoices_whenNoMiraklInvoicesAreReceived_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<InvoiceModel> invoices = testObj.getAccountingDocuments(now);
    assertThat(invoices).isEqualTo(Collections.emptyList());
}
Also used : Date(java.util.Date) InvoiceModel(com.paypal.invoices.invoicesextract.model.InvoiceModel) Test(org.junit.jupiter.api.Test)

Example 13 with InvoiceModel

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

the class MiraklInvoicesExtractServiceImplTest method mockAndReturn.

private InvoiceModel mockAndReturn(final HMCMiraklInvoice invoice) {
    final InvoiceModel invoiceModelMock = mock(InvoiceModel.class);
    when(miraklInvoiceToInvoiceModelConverterMock.convert(invoice)).thenReturn(invoiceModelMock);
    return invoiceModelMock;
}
Also used : InvoiceModel(com.paypal.invoices.invoicesextract.model.InvoiceModel)

Example 14 with InvoiceModel

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

the class MiraklInvoicesExtractServiceImplTest method extractAccountingDocument_whenRequestRequiresPagination_shouldRequestAllShops_andPopulateInvoiceModelsWithTheTokensStoredInMirakl.

@Test
void extractAccountingDocument_whenRequestRequiresPagination_shouldRequestAllShops_andPopulateInvoiceModelsWithTheTokensStoredInMirakl() {
    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).build();
    final InvoiceModel invoiceTwo = InvoiceModel.builder().shopId(SHOP_ID_TWO).destinationToken(TOKEN_2).build();
    doReturn(List.of(invoiceOne, invoiceTwo)).when(testObj).getAccountingDocuments(nowAsDate);
    when(miraklShopsMock.getShops()).thenReturn(List.of(miraklShopOneMock, miraklShopTwoMock));
    when(miraklMarketplacePlatformOperatorApiClientMock.getShops(any(MiraklGetShopsRequest.class))).thenReturn(miraklShopsMock);
    when(miraklShopToAccountingModelConverter.convert(miraklShopOneMock)).thenReturn(invoiceModelConvertedFromShopOneMock);
    when(miraklShopToAccountingModelConverter.convert(miraklShopTwoMock)).thenReturn(invoiceModelConvertedFromShopTwoMock);
    when(invoiceModelConvertedFromShopOneMock.getShopId()).thenReturn(SHOP_ID_ONE);
    when(invoiceModelConvertedFromShopTwoMock.getShopId()).thenReturn(SHOP_ID_TWO);
    when(invoiceModelConvertedFromShopOneMock.getDestinationToken()).thenReturn(TOKEN_1);
    when(invoiceModelConvertedFromShopTwoMock.getDestinationToken()).thenReturn(TOKEN_2);
    when(invoiceModelConvertedFromShopOneMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM);
    when(invoiceModelConvertedFromShopTwoMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM);
    final List<InvoiceModel> result = testObj.extractAccountingDocument(nowAsDate);
    verify(miraklMarketplacePlatformOperatorApiClientMock).getShops(miraklGetShopsRequestArgumentCaptor.capture());
    assertThat(miraklGetShopsRequestArgumentCaptor.getValue().getShopIds()).containsExactlyInAnyOrder(SHOP_ID_ONE, SHOP_ID_TWO);
    assertThat(result.get(0)).hasFieldOrPropertyWithValue(SHOP_ID_ATTRIBUTE, SHOP_ID_ONE).hasFieldOrPropertyWithValue(DESTINATION_TOKEN_ATTRIBUTE, TOKEN_1);
    assertThat(result.get(1)).hasFieldOrPropertyWithValue(SHOP_ID_ATTRIBUTE, SHOP_ID_TWO).hasFieldOrPropertyWithValue(DESTINATION_TOKEN_ATTRIBUTE, TOKEN_2);
}
Also used : LocalDateTime(java.time.LocalDateTime) 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 15 with InvoiceModel

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

the class MiraklInvoiceToInvoiceModelConverterTest method convert_shouldConvertMiraklInvoiceIntoInvoiceModel.

@Test
void convert_shouldConvertMiraklInvoiceIntoInvoiceModel() {
    when(miraklInvoiceMock.getId()).thenReturn(INV_NUMBER);
    when(miraklInvoiceMock.getShopId()).thenReturn(SHOP_ID);
    when(miraklInvoiceMock.getCurrencyIsoCode()).thenReturn(MiraklIsoCurrencyCode.EUR);
    when(miraklInvoiceMock.getSummary()).thenReturn(miraklInvoiceSummaryMock);
    when(miraklInvoiceSummaryMock.getAmountTransferred()).thenReturn(TRANSFER_AMOUNT);
    when(miraklInvoiceSummaryMock.getTotalCommissionsIT()).thenReturn(TOTAL_COMMISSION);
    when(miraklInvoiceSummaryMock.getTotalSubscriptionIT()).thenReturn(TOTAL_SUBSCRIPTIONS);
    when(miraklInvoiceSummaryMock.getAmountTransferredToOperator()).thenReturn(BigDecimal.TEN);
    final InvoiceModel result = testObj.convert(miraklInvoiceMock);
    assertThat(result.getInvoiceNumber()).isEqualTo(INV_NUMBER);
    assertThat(result.getCurrencyIsoCode()).isEqualTo(EUR);
    assertThat(result.getTransferAmount()).isEqualTo(TRANSFER_AMOUNT.doubleValue());
    assertThat(result.getSubscriptionAmountVat()).isEqualTo(TOTAL_SUBSCRIPTIONS.doubleValue());
    assertThat(result.getOrderCommissionAmountVat()).isEqualTo(TOTAL_COMMISSION.doubleValue());
    assertThat(result.getShopId()).isEqualTo("2000");
    assertThat(result.getTransferAmountToOperator()).isEqualTo(10D);
}
Also used : 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