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);
}
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());
}
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;
}
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);
}
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);
}
Aggregations