mirror of
https://github.com/Sheldan/abstracto.git
synced 2026-03-31 15:26:00 +00:00
[AB-128] adding command cooldowns on server/channel group and member level
fixing channel group names being made lower case before storing changing channel group deleted to be sync instead refactoring exceptions and adding exception message to a few fixing channel group incorrect type using the wrong template showing more information in list channel groups command allowing commands to be in any channel group adding concept of channel group types not allowing channels/commands to be in multiple of the same type adding structure to retrieve information about channel groups adding ability to disable channel groups changing loading of member parameter handler to not use cache
This commit is contained in:
@@ -7,6 +7,7 @@ import net.dv8tion.jda.api.entities.Guild;
|
||||
import net.dv8tion.jda.api.entities.Member;
|
||||
import net.dv8tion.jda.api.entities.Message;
|
||||
import net.dv8tion.jda.api.requests.RestAction;
|
||||
import net.dv8tion.jda.internal.utils.concurrent.task.GatewayTask;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
@@ -76,28 +77,33 @@ public class MemberParameterHandlerImplTest extends AbstractParameterHandlerTest
|
||||
Assert.assertEquals(member, parsed.join());
|
||||
}
|
||||
|
||||
@Test(expected = AbstractoTemplatedException.class)
|
||||
@Test
|
||||
public void testNotExistingMember() {
|
||||
String input = "test";
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getMembersByName(input, true)).thenReturn(new ArrayList<>());
|
||||
testUnit.handleAsync(getPieceWithValue(input), null, parameter, message, command);
|
||||
GatewayTask task = new GatewayTask(CompletableFuture.completedFuture(new ArrayList()), () -> {});
|
||||
when(guild.retrieveMembersByPrefix(input, 1)).thenReturn(task);
|
||||
CompletableFuture<Object> future = testUnit.handleAsync(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertTrue(future.isCompletedExceptionally());
|
||||
}
|
||||
|
||||
@Test(expected = AbstractoTemplatedException.class)
|
||||
@Test
|
||||
public void testMultipleFoundMemberByName() {
|
||||
String input = "test";
|
||||
Member secondMember = Mockito.mock(Member.class);
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getMembersByName(input, true)).thenReturn(Arrays.asList(member, secondMember));
|
||||
testUnit.handleAsync(getPieceWithValue(input), null, parameter, message, command);
|
||||
GatewayTask task = new GatewayTask(CompletableFuture.completedFuture(Arrays.asList(member, secondMember)), () -> {});
|
||||
when(guild.retrieveMembersByPrefix(input, 1)).thenReturn(task);
|
||||
CompletableFuture<Object> future = testUnit.handleAsync(getPieceWithValue(input), null, parameter, message, command);
|
||||
Assert.assertTrue(future.isCompletedExceptionally());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFindMemberByName() {
|
||||
String input = "test";
|
||||
when(message.getGuild()).thenReturn(guild);
|
||||
when(guild.getMembersByName(input, true)).thenReturn(Arrays.asList(member));
|
||||
GatewayTask task = new GatewayTask(CompletableFuture.completedFuture(Arrays.asList(member)), () -> {});
|
||||
when(guild.retrieveMembersByPrefix(input, 1)).thenReturn(task);
|
||||
CompletableFuture<Object> future = testUnit.handleAsync(getPieceWithValue(input), null, parameter, message, command);
|
||||
Member returnedMember = (Member) future.join();
|
||||
Assert.assertFalse(future.isCompletedExceptionally());
|
||||
|
||||
@@ -16,6 +16,7 @@ import org.mockito.junit.MockitoJUnitRunner;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
|
||||
import static dev.sheldan.abstracto.core.command.CommandConstants.COMMAND_CHANNEL_GROUP_KEY;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@@ -50,14 +51,15 @@ public class ChannelGroupCommandServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void testNoChannelGroup() {
|
||||
when(channelGroupCommandService.getAllGroupCommandsForCommand(command)).thenReturn(new ArrayList<>());
|
||||
when(channelGroupCommandService.getAllGroupCommandsForCommandWithType(command, COMMAND_CHANNEL_GROUP_KEY)).thenReturn(new ArrayList<>());
|
||||
Assert.assertTrue(testUnit.isCommandEnabled(command, channel));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testOneDisabledChannelGroup() {
|
||||
when(channelGroupCommandService.getAllGroupCommandsForCommand(command)).thenReturn(Arrays.asList(channelGroupCommand));
|
||||
when(channelGroupCommandService.getAllGroupCommandsForCommandWithType(command, COMMAND_CHANNEL_GROUP_KEY)).thenReturn(Arrays.asList(channelGroupCommand));
|
||||
when(channelGroupCommand.getGroup()).thenReturn(channelGroup);
|
||||
when(channelGroup.getEnabled()).thenReturn(true);
|
||||
when(channelGroup.getChannels()).thenReturn(Arrays.asList(channel));
|
||||
when(channelGroupCommand.getEnabled()).thenReturn(false);
|
||||
Assert.assertFalse(testUnit.isCommandEnabled(command, channel));
|
||||
@@ -65,8 +67,9 @@ public class ChannelGroupCommandServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void testOneEnabledChannelGroup() {
|
||||
when(channelGroupCommandService.getAllGroupCommandsForCommand(command)).thenReturn(Arrays.asList(channelGroupCommand));
|
||||
when(channelGroupCommandService.getAllGroupCommandsForCommandWithType(command, COMMAND_CHANNEL_GROUP_KEY)).thenReturn(Arrays.asList(channelGroupCommand));
|
||||
when(channelGroupCommand.getGroup()).thenReturn(channelGroup);
|
||||
when(channelGroup.getEnabled()).thenReturn(true);
|
||||
when(channelGroup.getChannels()).thenReturn(Arrays.asList(channel));
|
||||
when(channelGroupCommand.getEnabled()).thenReturn(true);
|
||||
Assert.assertTrue(testUnit.isCommandEnabled(command, channel));
|
||||
@@ -74,8 +77,9 @@ public class ChannelGroupCommandServiceBeanTest {
|
||||
|
||||
@Test
|
||||
public void testDisabledInOneGroupChannelIsNotPartOf() {
|
||||
when(channelGroupCommandService.getAllGroupCommandsForCommand(command)).thenReturn(Arrays.asList(channelGroupCommand));
|
||||
when(channelGroupCommandService.getAllGroupCommandsForCommandWithType(command, COMMAND_CHANNEL_GROUP_KEY)).thenReturn(Arrays.asList(channelGroupCommand));
|
||||
when(channelGroupCommand.getGroup()).thenReturn(channelGroup);
|
||||
when(channelGroup.getEnabled()).thenReturn(true);
|
||||
when(channelGroup.getChannels()).thenReturn(Arrays.asList(secondChannel));
|
||||
when(channel.getId()).thenReturn(CHANNEL_ID);
|
||||
when(secondChannel.getId()).thenReturn(CHANNEL_ID_2);
|
||||
|
||||
Reference in New Issue
Block a user