use of com.paypal.invoices.invoicesextract.model.CreditNoteModel in project mirakl-hyperwallet-connector by paypal.
the class MiraklCreditNotesExtractServiceImplTest method extractAccountingDocument_whenSeveralCreditNotesPerShopAreExtractedFromMirakl_shouldPopulateTheCreditNotes.
@Test
void extractAccountingDocument_whenSeveralCreditNotesPerShopAreExtractedFromMirakl_shouldPopulateTheCreditNotes() {
final LocalDateTime now = LocalDateTime.now();
TimeMachine.useFixedClockAt(now);
final Date nowAsDate = DateUtil.convertToDate(now, ZoneId.systemDefault());
final CreditNoteModel creditNoteOne = CreditNoteModel.builder().shopId(SHOP_ID_ONE).destinationToken(TOKEN_1).build();
final CreditNoteModel creditNoteTwo = CreditNoteModel.builder().shopId(SHOP_ID_TWO).destinationToken(TOKEN_2).build();
final CreditNoteModel creditNoteThree = CreditNoteModel.builder().shopId(SHOP_ID_ONE).destinationToken(TOKEN_1).build();
doReturn(List.of(creditNoteOne, creditNoteTwo, creditNoteThree)).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(creditNoteModelModelConvertedFromShopOneMock);
when(miraklShopToAccountingModelConverter.convert(miraklShopTwoMock)).thenReturn(creditNoteModelConvertedFromShopTwoMock);
when(miraklShopToAccountingModelConverter.convert(miraklShopThreeMock)).thenReturn(creditNoteModelConvertedFromShopThreeMock);
when(creditNoteModelModelConvertedFromShopOneMock.getShopId()).thenReturn(SHOP_ID_ONE);
when(creditNoteModelConvertedFromShopTwoMock.getShopId()).thenReturn(SHOP_ID_TWO);
when(creditNoteModelConvertedFromShopThreeMock.getShopId()).thenReturn(SHOP_ID_ONE);
when(creditNoteModelModelConvertedFromShopOneMock.getDestinationToken()).thenReturn(TOKEN_1);
when(creditNoteModelConvertedFromShopTwoMock.getDestinationToken()).thenReturn(TOKEN_2);
when(creditNoteModelConvertedFromShopThreeMock.getDestinationToken()).thenReturn(TOKEN_1);
when(creditNoteModelModelConvertedFromShopOneMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM);
when(creditNoteModelConvertedFromShopTwoMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM);
when(creditNoteModelConvertedFromShopThreeMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM);
final List<CreditNoteModel> 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.CreditNoteModel in project mirakl-hyperwallet-connector by paypal.
the class MiraklCreditNotesExtractServiceImplTest method extractAccountingDocument_whenRequestRequiresPagination_shouldRequestAllShops_AndPopulateCreditNotesModelWithTheTokensStoredInMirakl.
@Test
void extractAccountingDocument_whenRequestRequiresPagination_shouldRequestAllShops_AndPopulateCreditNotesModelWithTheTokensStoredInMirakl() {
final LocalDateTime now = LocalDateTime.now();
TimeMachine.useFixedClockAt(now);
final Date nowAsDate = DateUtil.convertToDate(now, ZoneId.systemDefault());
final CreditNoteModel creditNoteOne = CreditNoteModel.builder().shopId(SHOP_ID_ONE).destinationToken(TOKEN_1).build();
final CreditNoteModel creditNoteTwo = CreditNoteModel.builder().shopId(SHOP_ID_TWO).destinationToken(TOKEN_2).build();
doReturn(List.of(creditNoteOne, creditNoteTwo)).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(creditNoteModelModelConvertedFromShopOneMock);
when(miraklShopToAccountingModelConverter.convert(miraklShopTwoMock)).thenReturn(creditNoteModelConvertedFromShopTwoMock);
when(creditNoteModelModelConvertedFromShopOneMock.getShopId()).thenReturn(SHOP_ID_ONE);
when(creditNoteModelConvertedFromShopTwoMock.getShopId()).thenReturn(SHOP_ID_TWO);
when(creditNoteModelModelConvertedFromShopOneMock.getDestinationToken()).thenReturn(TOKEN_1);
when(creditNoteModelConvertedFromShopTwoMock.getDestinationToken()).thenReturn(TOKEN_2);
when(creditNoteModelModelConvertedFromShopOneMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM);
when(creditNoteModelConvertedFromShopTwoMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM);
final List<CreditNoteModel> 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.CreditNoteModel in project mirakl-hyperwallet-connector by paypal.
the class MiraklCreditNotesExtractServiceImplTest method getAccountingDocuments_shouldReturnListOfCreditNoteModels.
@Test
void getAccountingDocuments_shouldReturnListOfCreditNoteModels() {
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(miraklInvoiceToCreditNoteModelConverter.convert(miraklInvoiceOneMock)).thenReturn(creditNoteOneMock);
when(miraklInvoiceToCreditNoteModelConverter.convert(miraklInvoiceTwoMock)).thenReturn(creditNoteTwoMock);
final List<CreditNoteModel> creditNoteList = testObj.getAccountingDocuments(now);
verify(miraklMarketplacePlatformOperatorApiClientMock).getInvoices(miraklGetInvoicesRequestArgumentCaptor.capture());
final MiraklGetInvoicesRequest miraklGetInvoicesRequest = miraklGetInvoicesRequestArgumentCaptor.getValue();
assertThat(miraklGetInvoicesRequest.getStartDate()).isEqualTo(now);
assertThat(miraklGetInvoicesRequest.getStates()).isEqualTo(List.of(COMPLETE));
assertThat(miraklGetInvoicesRequest.getPaymentStatus()).isEqualTo(PENDING);
assertThat(creditNoteList).containsExactlyInAnyOrder(creditNoteOneMock, creditNoteTwoMock);
}
use of com.paypal.invoices.invoicesextract.model.CreditNoteModel in project mirakl-hyperwallet-connector by paypal.
the class MiraklCreditNotesExtractServiceImplTest method getAccountingDocuments_whenMiraklExceptionIsThrown_shouldSendEmailNotification.
@Test
void getAccountingDocuments_whenMiraklExceptionIsThrown_shouldSendEmailNotification() {
final LocalDateTime now = LocalDateTime.now();
TimeMachine.useFixedClockAt(now);
final Date nowAsDate = DateUtil.convertToDate(now, ZoneId.systemDefault());
final CreditNoteModel creditNoteOne = CreditNoteModel.builder().shopId(SHOP_ID_ONE).destinationToken(TOKEN_1).hyperwalletProgram(HYPERWALLET_PROGRAM).build();
final List<CreditNoteModel> creditNoteList = List.of(creditNoteOne);
doReturn(creditNoteList).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.CreditNoteModel in project mirakl-hyperwallet-connector by paypal.
the class MiraklInvoiceToCreditNoteModelConverterTest method convert_shouldConvertFromMiraklInvoiceToCreditNoteModel.
@Test
void convert_shouldConvertFromMiraklInvoiceToCreditNoteModel() {
final MiraklInvoice miraklInvoiceStub = new MiraklInvoice();
miraklInvoiceStub.setId("2000050");
miraklInvoiceStub.setShopId(2000L);
miraklInvoiceStub.setTotalChargedAmount(BigDecimal.valueOf(20.00D));
miraklInvoiceStub.setCurrencyIsoCode(MiraklIsoCurrencyCode.EUR);
final CreditNoteModel result = testObj.convert(miraklInvoiceStub);
assertThat(result.getInvoiceNumber()).isEqualTo("2000050");
assertThat(result.getShopId()).isEqualTo("2000");
assertThat(result.getCreditAmount()).isEqualTo(20.00D);
assertThat(result.getCurrencyIsoCode()).isEqualTo("EUR");
}
Aggregations