Search in sources :

Example 6 with CreditNoteModel

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) MiraklGetShopsRequest(com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest) CreditNoteModel(com.paypal.invoices.invoicesextract.model.CreditNoteModel) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 7 with CreditNoteModel

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);
}
Also used : LocalDateTime(java.time.LocalDateTime) MiraklGetShopsRequest(com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest) CreditNoteModel(com.paypal.invoices.invoicesextract.model.CreditNoteModel) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 8 with CreditNoteModel

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);
}
Also used : MiraklGetInvoicesRequest(com.mirakl.client.mmp.operator.request.payment.invoice.MiraklGetInvoicesRequest) CreditNoteModel(com.paypal.invoices.invoicesextract.model.CreditNoteModel) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 9 with CreditNoteModel

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)));
}
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) CreditNoteModel(com.paypal.invoices.invoicesextract.model.CreditNoteModel) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 10 with CreditNoteModel

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");
}
Also used : MiraklInvoice(com.mirakl.client.mmp.domain.invoice.MiraklInvoice) CreditNoteModel(com.paypal.invoices.invoicesextract.model.CreditNoteModel) Test(org.junit.jupiter.api.Test)

Aggregations

CreditNoteModel (com.paypal.invoices.invoicesextract.model.CreditNoteModel)12 Test (org.junit.jupiter.api.Test)11 Date (java.util.Date)8 LocalDateTime (java.time.LocalDateTime)6 MiraklGetShopsRequest (com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest)4 HyperwalletPayment (com.hyperwallet.clientsdk.model.HyperwalletPayment)3 MiraklErrorResponseBean (com.mirakl.client.core.error.MiraklErrorResponseBean)2 MiraklApiException (com.mirakl.client.core.exception.MiraklApiException)2 MiraklInvoice (com.mirakl.client.mmp.domain.invoice.MiraklInvoice)2 MiraklGetInvoicesRequest (com.mirakl.client.mmp.operator.request.payment.invoice.MiraklGetInvoicesRequest)2 HyperwalletException (com.hyperwallet.clientsdk.HyperwalletException)1 PENDING (com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentPaymentStatus.PENDING)1 MANUAL_CREDIT (com.mirakl.client.mmp.domain.accounting.document.MiraklAccountingDocumentType.MANUAL_CREDIT)1 MiraklShop (com.mirakl.client.mmp.domain.shop.MiraklShop)1 MiraklShops (com.mirakl.client.mmp.domain.shop.MiraklShops)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 MiraklMarketplacePlatformOperatorApiWrapper (com.paypal.infrastructure.sdk.mirakl.MiraklMarketplacePlatformOperatorApiWrapper)1