-
Notifications
You must be signed in to change notification settings - Fork 0
Enable manual_pending notification handling #6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
164 changes: 164 additions & 0 deletions
164
...test/java/dev/vality/disputes/tg/bot/servlet/impl/DisputesApiNotificationHandlerTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,164 @@ | ||
| package dev.vality.disputes.tg.bot.servlet.impl; | ||
|
|
||
| import dev.vality.damsel.domain.PaymentRoute; | ||
| import dev.vality.damsel.domain.Provider; | ||
| import dev.vality.damsel.domain.ProviderRef; | ||
| import dev.vality.damsel.domain.TerminalRef; | ||
| import dev.vality.damsel.domain.TransactionInfo; | ||
| import dev.vality.damsel.payment_processing.Invoice; | ||
| import dev.vality.damsel.payment_processing.InvoicePayment; | ||
| import dev.vality.disputes.admin.Dispute; | ||
| import dev.vality.disputes.tg.bot.config.ResponseDictionaryConfig; | ||
| import dev.vality.disputes.tg.bot.config.properties.AdminChatProperties; | ||
| import dev.vality.disputes.tg.bot.config.properties.DictionaryProperties; | ||
| import dev.vality.disputes.tg.bot.dao.AdminDisputeReviewDao; | ||
| import dev.vality.disputes.tg.bot.domain.tables.pojos.AdminDisputeReview; | ||
| import dev.vality.disputes.tg.bot.service.Polyglot; | ||
| import dev.vality.disputes.tg.bot.service.TelegramApiService; | ||
| import dev.vality.disputes.tg.bot.service.external.DominantService; | ||
| import dev.vality.disputes.tg.bot.service.external.HellgateService; | ||
| import lombok.extern.slf4j.Slf4j; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
| import org.junit.jupiter.api.extension.ExtendWith; | ||
| import org.mockito.ArgumentCaptor; | ||
| import org.mockito.Captor; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.test.context.ContextConfiguration; | ||
| import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
| import org.springframework.test.context.bean.override.mockito.MockitoBean; | ||
| import org.telegram.telegrambots.meta.api.objects.message.Message; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Optional; | ||
| import java.util.StringJoiner; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.mockito.ArgumentMatchers.*; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| @Slf4j | ||
| @ExtendWith(SpringExtension.class) | ||
| @ContextConfiguration(classes = { | ||
| DisputesApiNotificationHandler.class, | ||
| Polyglot.class, | ||
| ResponseDictionaryConfig.class, | ||
| DisputesApiNotificationHandlerTest.TestConfig.class | ||
| }) | ||
| class DisputesApiNotificationHandlerTest { | ||
|
|
||
| private static final String INVOICE_ID = "invoice-1"; | ||
| private static final String PAYMENT_ID = "payment-1"; | ||
| private static final String PROVIDER_TRX_ID = "trx-1"; | ||
| private static final long TG_MESSAGE_ID = 123L; | ||
|
|
||
| @MockitoBean | ||
| private TelegramApiService telegramApiService; | ||
| @MockitoBean | ||
| private DominantService dominantService; | ||
| @MockitoBean | ||
| private HellgateService hellgateService; | ||
| @MockitoBean | ||
| private AdminDisputeReviewDao adminDisputeReviewDao; | ||
| @Captor | ||
| private ArgumentCaptor<AdminDisputeReview> reviewCaptor; | ||
| @Captor | ||
| private ArgumentCaptor<String> messageCaptor; | ||
|
|
||
| @Autowired | ||
| private AdminChatProperties adminChatProperties; | ||
| @Autowired | ||
| private Polyglot polyglot; | ||
| @Autowired | ||
| private DisputesApiNotificationHandler notificationHandler; | ||
| @MockitoBean | ||
| private DictionaryProperties dictionaryProperties; | ||
| @MockitoBean(name = "providerResponseDictionary") | ||
| private List<?> providerResponseDictionary; | ||
|
|
||
| @Configuration | ||
| static class TestConfig { | ||
| @Bean | ||
| AdminChatProperties adminChatProperties() { | ||
| return new AdminChatProperties(); | ||
| } | ||
| } | ||
|
|
||
| @BeforeEach | ||
| void setUp() { | ||
| adminChatProperties.setId(10L); | ||
| var topics = new AdminChatProperties.Topic(); | ||
| topics.setReviewDisputesProcessing(20); | ||
| adminChatProperties.setTopics(topics); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("notify handles manual_pending disputes and saves review") | ||
| void notifyManualPendingSendsMessageAndPersistsReview() throws Exception { | ||
| var dispute = new Dispute(); | ||
| dispute.setStatus("manual_pending"); | ||
| dispute.setInvoiceId(INVOICE_ID); | ||
| dispute.setPaymentId(PAYMENT_ID); | ||
| dispute.setMapping("code = disputes:unknown, description = Unexpected result, code = disputes:Rejected, " + | ||
| "description = test, state = null"); | ||
|
|
||
| var providerRef = new ProviderRef().setId(1); | ||
| when(hellgateService.getInvoice(INVOICE_ID)).thenReturn(buildInvoice(providerRef)); | ||
| when(dominantService.getProvider(providerRef)).thenReturn(new Provider().setName("Provider")); | ||
|
|
||
| var message = new Message(); | ||
| message.setMessageId((int) TG_MESSAGE_ID); | ||
| when(telegramApiService.sendMessage(anyString(), anyLong(), anyInt())) | ||
| .thenReturn(Optional.of(message)); | ||
|
|
||
| notificationHandler.notify(dispute); | ||
|
|
||
| verify(telegramApiService).sendMessage(messageCaptor.capture(), | ||
| eq(adminChatProperties.getId()), | ||
| eq(adminChatProperties.getTopics().getReviewDisputesProcessing())); | ||
| verify(adminDisputeReviewDao).save(reviewCaptor.capture()); | ||
| var review = reviewCaptor.getValue(); | ||
| assertEquals(INVOICE_ID, review.getInvoiceId()); | ||
| assertEquals(PAYMENT_ID, review.getPaymentId()); | ||
| assertEquals(TG_MESSAGE_ID, review.getTgMessageId()); | ||
| var text = messageCaptor.getValue(); | ||
| log.info("Notification text: {}", text); | ||
| var expectedMessage = polyglot.getText("dispute.support.manual-pending-with-text", | ||
| "(1) Provider", | ||
| "invoice-1.payment-1", | ||
| PROVIDER_TRX_ID, | ||
| "mapping:code = disputes:unknown, description = Unexpected result, code = " + | ||
| "disputes:Rejected, description = test, state = null", | ||
| new StringJoiner("\n")); | ||
| assertEquals(expectedMessage, text); | ||
| } | ||
|
|
||
| private Invoice buildInvoice(ProviderRef providerRef) { | ||
| var invoice = new Invoice(); | ||
| var invoiceInner = new dev.vality.damsel.domain.Invoice(); | ||
| invoiceInner.setId(INVOICE_ID); | ||
| invoice.setInvoice(invoiceInner); | ||
|
|
||
| var payment = new dev.vality.damsel.domain.InvoicePayment(); | ||
| payment.setId(PAYMENT_ID); | ||
|
|
||
| var route = new PaymentRoute(); | ||
| route.setProvider(providerRef); | ||
| route.setTerminal(new TerminalRef().setId(2)); | ||
|
|
||
| var lastTrxInfo = new TransactionInfo(); | ||
| lastTrxInfo.setId(PROVIDER_TRX_ID); | ||
|
|
||
| var processingPayment = new InvoicePayment(); | ||
| processingPayment.setPayment(payment); | ||
| processingPayment.setRoute(route); | ||
| processingPayment.setLastTransactionInfo(lastTrxInfo); | ||
|
|
||
| invoice.setPayments(List.of(processingPayment)); | ||
| return invoice; | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.