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