mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-04-19 05:08:02 +00:00
[AB-215] adding create alias and delete alias commands to create service specific aliases for commands
renaming package in commands package defaulting to latest in docker compose build for deployment container fixing jacoco configuration changing that if there are no parameters required, parameters are accepted
This commit is contained in:
@@ -25,6 +25,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
@@ -149,9 +150,9 @@ public class StarAddedListenerTest {
|
||||
public void testAddingEmoteReachingThreshold() {
|
||||
Long requiredStars = 1L;
|
||||
setupActingAndAuthor();
|
||||
when(starboardService.createStarboardPost(any(CachedMessage.class), anyList(), eq(userInServerActing), eq(userInAServer))).thenReturn(CompletableFuture.completedFuture(null));
|
||||
executeAddingTest(requiredStars, null);
|
||||
verify(metricService, times(2)).incrementCounter(any());
|
||||
verify(starboardService, times(1)).createStarboardPost(any(CachedMessage.class), anyList(), eq(userInServerActing), eq(userInAServer));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -117,6 +117,9 @@ public class StarboardServiceBeanTest {
|
||||
@Mock
|
||||
private AUser aUser;
|
||||
|
||||
@Mock
|
||||
private StarboardPostCreatedListenerManager starboardPostCreatedListenerManager;
|
||||
|
||||
private static final Long STARRED_USER_ID = 5L;
|
||||
private static final Long STARRED_SERVER_USER_ID = 2L;
|
||||
private static final Long SERVER_ID = 6L;
|
||||
@@ -194,13 +197,10 @@ public class StarboardServiceBeanTest {
|
||||
CachedMessage message = Mockito.mock(CachedMessage.class);
|
||||
List<Long> userExceptAuthorIds = Arrays.asList(FIRST_USER_IN_SERVER_ID, SECOND_USER_IN_SERVER_ID);
|
||||
List<CompletableFuture<Message>> futures = Arrays.asList(CompletableFuture.completedFuture(sendPost));
|
||||
when(sendPost.getGuild()).thenReturn(guild);
|
||||
when(sendPost.getChannel()).thenReturn(mockedTextChannel);
|
||||
when(sendPost.getIdLong()).thenReturn(MESSAGE_ID);
|
||||
when(userInServerManagementService.loadUserOptional(STARRED_SERVER_USER_ID)).thenReturn(Optional.of(starredUser));
|
||||
when(userInServerManagementService.loadUserOptional(FIRST_USER_IN_SERVER_ID)).thenReturn(Optional.of(userReacting));
|
||||
when(userReacting.getUserInServerId()).thenReturn(FIRST_USER_IN_SERVER_ID);
|
||||
when(userReacting.getUserReference()).thenReturn(aUser);
|
||||
AChannel channel = Mockito.mock(AChannel.class);
|
||||
when(channelManagementService.loadChannel(CHANNEL_ID)).thenReturn(channel);
|
||||
StarboardPost post = Mockito.mock(StarboardPost.class);
|
||||
@@ -208,13 +208,13 @@ public class StarboardServiceBeanTest {
|
||||
AUserInAServer secondStarrerUserObj = Mockito.mock(AUserInAServer.class);
|
||||
when(userInServerManagementService.loadUserOptional(SECOND_USER_IN_SERVER_ID)).thenReturn(Optional.of(secondStarrerUserObj));
|
||||
when(secondStarrerUserObj.getUserInServerId()).thenReturn(SECOND_USER_IN_SERVER_ID);
|
||||
when(secondStarrerUserObj.getUserReference()).thenReturn(aUser);
|
||||
testUnit.persistPost(message, userExceptAuthorIds, futures, CHANNEL_ID, STARRED_SERVER_USER_ID, STARRING_USER_ID);
|
||||
verify(starboardPostReactorManagementService, times(2)).addReactor(eq(post), userInAServerArgumentCaptor.capture());
|
||||
List<AUserInAServer> addedReactors = userInAServerArgumentCaptor.getAllValues();
|
||||
Assert.assertEquals(FIRST_USER_IN_SERVER_ID, addedReactors.get(0).getUserInServerId());
|
||||
Assert.assertEquals(SECOND_USER_IN_SERVER_ID, addedReactors.get(1).getUserInServerId());
|
||||
Assert.assertEquals(2, addedReactors.size());
|
||||
verify(starboardPostCreatedListenerManager, times(1)).sendStarboardPostCreatedEvent(STARRING_USER_ID, post);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -242,7 +242,7 @@ public class StarboardServiceBeanTest {
|
||||
when(config.getLongValue()).thenReturn(1L);
|
||||
when(defaultConfigManagementService.getDefaultConfig(StarboardFeatureConfig.STAR_LEVELS_CONFIG_KEY)).thenReturn(config);
|
||||
when(defaultConfigManagementService.getDefaultConfig(StarboardFeatureConfig.STAR_LVL_CONFIG_PREFIX + 1)).thenReturn(config);
|
||||
when(starboardPostManagementService.findByStarboardPostMessageId(starboardPostId)).thenReturn(Optional.of(post));
|
||||
when(starboardPostManagementService.findByStarboardPostId(starboardPostId)).thenReturn(Optional.of(post));
|
||||
when(userService.retrieveUserForId(STARRED_USER_ID)).thenReturn(CompletableFuture.completedFuture(starredJdaUser));
|
||||
List<AUserInAServer > userExceptAuthor = new ArrayList<>();
|
||||
CompletableFuture<Void> future = testUnit.updateStarboardPost(post, message, userExceptAuthor);
|
||||
@@ -280,17 +280,16 @@ public class StarboardServiceBeanTest {
|
||||
Integer limit = 3;
|
||||
AChannel channel = Mockito.mock(AChannel.class);
|
||||
when(server.getId()).thenReturn(SERVER_ID);
|
||||
StarboardPostReaction reaction = Mockito.mock(StarboardPostReaction.class);
|
||||
StarboardPost post1 = Mockito.mock(StarboardPost.class);
|
||||
when(post1.getReactions()).thenReturn(Arrays.asList(reaction));
|
||||
when(post1.getPostMessageId()).thenReturn(MESSAGE_ID);
|
||||
when(post1.getServer()).thenReturn(server);
|
||||
when(post1.getStarboardChannel()).thenReturn(channel);
|
||||
StarboardPost post2 = Mockito.mock(StarboardPost.class);
|
||||
when(post2.getPostMessageId()).thenReturn(SECOND_MESSAGE_ID);
|
||||
when(post2.getReactions()).thenReturn(new ArrayList<>());
|
||||
when(post2.getServer()).thenReturn(server);
|
||||
when(post2.getStarboardChannel()).thenReturn(channel);
|
||||
when(starboardPostReactorManagementService.getReactorCountOfPost(post1)).thenReturn(1L);
|
||||
when(starboardPostReactorManagementService.getReactorCountOfPost(post2)).thenReturn(0L);
|
||||
List<StarboardPost> topPosts = Arrays.asList(post1, post2);
|
||||
when(starboardPostManagementService.retrieveTopPosts(SERVER_ID, limit)).thenReturn(topPosts);
|
||||
CompletableFuture<StarStatsUser> statsUser = CompletableFuture.completedFuture(Mockito.mock(StarStatsUser.class));
|
||||
@@ -339,10 +338,9 @@ public class StarboardServiceBeanTest {
|
||||
AServer server = Mockito.mock(AServer.class);
|
||||
when(server.getId()).thenReturn(SERVER_ID);
|
||||
when(post.getServer()).thenReturn(server);
|
||||
StarboardPostReaction reaction = Mockito.mock(StarboardPostReaction.class);
|
||||
when(post.getReactions()).thenReturn(Collections.singletonList(reaction));
|
||||
when(starboardChannel.getId()).thenReturn(STARBOARD_CHANNEL_ID);
|
||||
when(post.getPostMessageId()).thenReturn(MESSAGE_ID);
|
||||
when(starboardPostReactorManagementService.getReactorCountOfPost(post)).thenReturn(1L);
|
||||
when(starboardPostManagementService.retrieveTopPostsForUserInServer(SERVER_ID, STARRED_USER_ID, 3)).thenReturn(Collections.singletonList(post));
|
||||
MemberStarStatsModel returnedModel = testUnit.retrieveStarStatsForMember(starredMember);
|
||||
Assert.assertEquals(receivedStars, returnedModel.getReceivedStars());
|
||||
|
||||
@@ -13,6 +13,7 @@ import dev.sheldan.abstracto.starboard.repository.StarboardPostRepository;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
@@ -67,14 +68,18 @@ public class StarboardPostManagementServiceBeanTest {
|
||||
when(channelManagementService.loadChannel(SOURCE_CHANNEL_ID)).thenReturn(sourceChannel);
|
||||
AUser aUser = Mockito.mock(AUser.class);
|
||||
when(aUserInAServer.getUserReference()).thenReturn(aUser);
|
||||
ArgumentCaptor<StarboardPost> argumentCaptor = ArgumentCaptor.forClass(StarboardPost.class);
|
||||
StarboardPost savedPost = Mockito.mock(StarboardPost.class);
|
||||
when(repository.save(argumentCaptor.capture())).thenReturn(savedPost);
|
||||
StarboardPost createdStarboardPost = testUnit.createStarboardPost(starredMessage, aUserInAServer, postInStarboard);
|
||||
verify(repository, times(1)).save(createdStarboardPost);
|
||||
Assert.assertEquals(starboardChannel, createdStarboardPost.getStarboardChannel());
|
||||
Assert.assertEquals(starboardPostId, createdStarboardPost.getStarboardMessageId());
|
||||
Assert.assertEquals(starredMessageId, createdStarboardPost.getPostMessageId());
|
||||
Assert.assertEquals(aUserInAServer, createdStarboardPost.getAuthor());
|
||||
Assert.assertEquals(sourceChannel, createdStarboardPost.getSourceChannel());
|
||||
Assert.assertFalse(createdStarboardPost.isIgnored());
|
||||
Assert.assertEquals(savedPost, createdStarboardPost);
|
||||
StarboardPost capturedPost = argumentCaptor.getValue();
|
||||
Assert.assertEquals(starboardChannel, capturedPost.getStarboardChannel());
|
||||
Assert.assertEquals(starboardPostId, capturedPost.getStarboardMessageId());
|
||||
Assert.assertEquals(starredMessageId, capturedPost.getPostMessageId());
|
||||
Assert.assertEquals(aUserInAServer, capturedPost.getAuthor());
|
||||
Assert.assertEquals(sourceChannel, capturedPost.getSourceChannel());
|
||||
Assert.assertFalse(capturedPost.isIgnored());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -83,20 +88,21 @@ public class StarboardPostManagementServiceBeanTest {
|
||||
Long messageId = 6L;
|
||||
testUnit.setStarboardPostMessageId(post, messageId);
|
||||
verify(post, times(1)).setStarboardMessageId(messageId);
|
||||
verify(repository, times(1)).save(post);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRetrieveTopPosts() {
|
||||
Integer count = 2;
|
||||
Long postId = 1L;
|
||||
Long postId2 = 3L;
|
||||
StarboardPost starboardPost1 = Mockito.mock(StarboardPost.class);
|
||||
when(starboardPost1.getReactions()).thenReturn(Arrays.asList(Mockito.mock(StarboardPostReaction.class), Mockito.mock(StarboardPostReaction.class)));
|
||||
StarboardPost starboardPost2 = Mockito.mock(StarboardPost.class);
|
||||
when(starboardPost2.getReactions()).thenReturn(Arrays.asList(Mockito.mock(StarboardPostReaction.class)));
|
||||
StarboardPost starboardPost3 = Mockito.mock(StarboardPost.class);
|
||||
when(starboardPost3.getReactions()).thenReturn(new ArrayList<>());
|
||||
List<StarboardPost> posts = Arrays.asList(starboardPost1, starboardPost2, starboardPost3);
|
||||
when(repository.findByServer_Id(SERVER_ID)).thenReturn(posts);
|
||||
List<StarboardPost> posts = Arrays.asList(starboardPost1, starboardPost2);
|
||||
List<Long> postIds = Arrays.asList(postId, postId2);
|
||||
when(repository.getTopStarboardPostsForServer(SERVER_ID, count)).thenReturn(postIds);
|
||||
when(repository.findAllById(postIds)).thenReturn(posts);
|
||||
List<StarboardPost> topPosts = testUnit.retrieveTopPosts(SERVER_ID, count);
|
||||
Assert.assertEquals(count.intValue(), topPosts.size());
|
||||
StarboardPost topMostPost = topPosts.get(0);
|
||||
@@ -109,6 +115,9 @@ public class StarboardPostManagementServiceBeanTest {
|
||||
@Test
|
||||
public void testRetrieveMoreThanAvailable() {
|
||||
Integer count = 5;
|
||||
Long postId = 1L;
|
||||
Long postId2 = 2L;
|
||||
Long postId3 = 3L;
|
||||
StarboardPost starboardPost1 = Mockito.mock(StarboardPost.class);
|
||||
when(starboardPost1.getReactions()).thenReturn(Arrays.asList(Mockito.mock(StarboardPostReaction.class), Mockito.mock(StarboardPostReaction.class)));
|
||||
StarboardPost starboardPost2 = Mockito.mock(StarboardPost.class);
|
||||
@@ -116,7 +125,9 @@ public class StarboardPostManagementServiceBeanTest {
|
||||
StarboardPost starboardPost3 = Mockito.mock(StarboardPost.class);
|
||||
when(starboardPost3.getReactions()).thenReturn(new ArrayList<>());
|
||||
List<StarboardPost> posts = Arrays.asList(starboardPost1, starboardPost2, starboardPost3);
|
||||
when(repository.findByServer_Id(SERVER_ID)).thenReturn(posts);
|
||||
List<Long> postIds = Arrays.asList(postId, postId2, postId3);
|
||||
when(repository.getTopStarboardPostsForServer(SERVER_ID, 5)).thenReturn(postIds);
|
||||
when(repository.findAllById(postIds)).thenReturn(posts);
|
||||
List<StarboardPost> topPosts = testUnit.retrieveTopPosts(SERVER_ID, count);
|
||||
StarboardPost topMostPost = topPosts.get(0);
|
||||
StarboardPost secondTop = topPosts.get(1);
|
||||
@@ -194,11 +205,9 @@ public class StarboardPostManagementServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void testRetrievePostCount() {
|
||||
StarboardPost starboardPost1 = Mockito.mock(StarboardPost.class);
|
||||
StarboardPost starboardPost2 = Mockito.mock(StarboardPost.class);
|
||||
List<StarboardPost> posts = Arrays.asList(starboardPost1, starboardPost2);
|
||||
when(repository.findByServer_Id(SERVER_ID)).thenReturn(posts);
|
||||
Long expectedCount = 2L;
|
||||
when(repository.countByServer_Id(SERVER_ID)).thenReturn(expectedCount);
|
||||
Long retrievedPostCount = testUnit.getPostCount(SERVER_ID);
|
||||
Assert.assertEquals(posts.size(), retrievedPostCount.intValue());
|
||||
Assert.assertEquals(expectedCount, retrievedPostCount);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user