polishing the workspace migration
This commit is contained in:
@@ -26,6 +26,8 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.UUID;
|
||||
|
||||
import static java.util.UUID.randomUUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.Mockito.*;
|
||||
@@ -55,7 +57,7 @@ class TransactionServiceTest {
|
||||
void setUp() {
|
||||
transaction = new Transaction();
|
||||
transaction.setId(txId);
|
||||
transaction.setUserId("user-1");
|
||||
transaction.setWorkspaceId(randomUUID());
|
||||
transaction.setAmount(new BigDecimal("100.00"));
|
||||
transaction.setDebitCurrency(CurrencyType.USD);
|
||||
transaction.setCreditCurrency(CurrencyType.ZWL);
|
||||
@@ -142,15 +144,17 @@ class TransactionServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisplayName("Should reassign transactions from old user to new user")
|
||||
@DisplayName("Should reassign transactions from old workspace to new workspace")
|
||||
void shouldReassignTransactions() {
|
||||
UUID oldWs = randomUUID();
|
||||
UUID newWs = randomUUID();
|
||||
List<Transaction> transactions = List.of(transaction);
|
||||
when(transactionRepository.findAllByUserId("old-user")).thenReturn(transactions);
|
||||
when(transactionRepository.findAllByWorkspaceId(oldWs)).thenReturn(transactions);
|
||||
when(transactionRepository.save(any(Transaction.class))).thenReturn(transaction);
|
||||
|
||||
transactionService.reassignTransactions("old-user", "new-user");
|
||||
transactionService.reassignTransactions(oldWs, newWs);
|
||||
|
||||
assertEquals("new-user", transaction.getUserId());
|
||||
assertEquals(newWs, transaction.getWorkspaceId());
|
||||
verify(transactionRepository).save(transaction);
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,9 @@ import zw.qantra.tm.domain.models.Transaction;
|
||||
import zw.qantra.tm.domain.services.RecipientService;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static java.util.UUID.randomUUID;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.*;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
@@ -34,7 +37,7 @@ class RecipientsUpdateHandlerTest {
|
||||
transaction = new Transaction();
|
||||
transaction.setStatus(Status.SUCCESS);
|
||||
transaction.setCreditAccount("ACC-123");
|
||||
transaction.setUserId("user-1");
|
||||
transaction.setWorkspaceId(randomUUID());
|
||||
transaction.setProviderLabel("econet");
|
||||
transaction.setCreditName("John Doe");
|
||||
transaction.setCreditEmail("john@example.com");
|
||||
@@ -47,10 +50,10 @@ class RecipientsUpdateHandlerTest {
|
||||
void shouldUpdateExistingRecipient() {
|
||||
Recipient existingRecipient = new Recipient();
|
||||
existingRecipient.setAccount("ACC-123");
|
||||
existingRecipient.setUserId("user-1");
|
||||
existingRecipient.setWorkspaceId(randomUUID());
|
||||
existingRecipient.setName("Old Name");
|
||||
|
||||
when(recipientService.getRecipient("ACC-123", "user-1"))
|
||||
when(recipientService.getRecipient("ACC-123", transaction.getWorkspaceId()))
|
||||
.thenReturn(List.of(existingRecipient));
|
||||
when(recipientService.save(any(Recipient.class))).thenReturn(existingRecipient);
|
||||
|
||||
@@ -68,7 +71,7 @@ class RecipientsUpdateHandlerTest {
|
||||
@Test
|
||||
@DisplayName("Should create new recipient when not found")
|
||||
void shouldCreateNewRecipient() {
|
||||
when(recipientService.getRecipient("ACC-123", "user-1"))
|
||||
when(recipientService.getRecipient("ACC-123", transaction.getWorkspaceId()))
|
||||
.thenReturn(List.of());
|
||||
when(recipientService.save(any(Recipient.class))).thenAnswer(i -> i.getArgument(0));
|
||||
|
||||
@@ -94,7 +97,7 @@ class RecipientsUpdateHandlerTest {
|
||||
void shouldUseBillNameForInitials() {
|
||||
transaction.setCreditName(null);
|
||||
|
||||
when(recipientService.getRecipient("ACC-123", "user-1"))
|
||||
when(recipientService.getRecipient("ACC-123", transaction.getWorkspaceId()))
|
||||
.thenReturn(List.of());
|
||||
when(recipientService.save(any(Recipient.class))).thenAnswer(i -> i.getArgument(0));
|
||||
|
||||
@@ -106,7 +109,7 @@ class RecipientsUpdateHandlerTest {
|
||||
@Test
|
||||
@DisplayName("Should handle exception gracefully without throwing")
|
||||
void shouldHandleExceptionGracefully() {
|
||||
when(recipientService.getRecipient("ACC-123", "user-1"))
|
||||
when(recipientService.getRecipient("ACC-123", transaction.getWorkspaceId()))
|
||||
.thenThrow(new RuntimeException("DB error"));
|
||||
|
||||
assertDoesNotThrow(() -> handler.process(transaction));
|
||||
@@ -121,9 +124,9 @@ class RecipientsUpdateHandlerTest {
|
||||
|
||||
Recipient existingRecipient = new Recipient();
|
||||
existingRecipient.setAccount("ACC-123");
|
||||
existingRecipient.setUserId("user-1");
|
||||
existingRecipient.setWorkspaceId(randomUUID());
|
||||
|
||||
when(recipientService.getRecipient("ACC-123", "user-1"))
|
||||
when(recipientService.getRecipient("ACC-123", transaction.getWorkspaceId()))
|
||||
.thenReturn(List.of(existingRecipient));
|
||||
when(recipientService.save(any(Recipient.class))).thenReturn(existingRecipient);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user