[AB-136] replacing some rare occurrences where fake objects where used for actual database operations

replacing a few sync commands with async commands
refactoring parameters in assignable role place service bean
fixing emote parameter handler to also consider default emojis
removing unused description in command
replacing some ARole parameters with Role parameters, so we can be sure they exists
added a few TODOs marking exception changes required
This commit is contained in:
Sheldan
2020-10-03 15:24:52 +02:00
parent 0f6f6a1e49
commit a391381ff6
37 changed files with 230 additions and 115 deletions

View File

@@ -37,6 +37,7 @@ public class DeleteNote extends AbstractConditionableCommand {
if(userNoteManagementService.noteExists(id)) {
userNoteManagementService.deleteNote(id);
} else {
// TODO replace with exception
return CommandResult.fromError(templateService.renderSimpleTemplate(NOTE_NOT_FOUND_EXCEPTION_TEMPLATE));
}
return CommandResult.fromSuccess();

View File

@@ -8,9 +8,11 @@ import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.config.FeatureEnum;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.core.service.management.RoleManagementService;
import dev.sheldan.abstracto.moderation.config.ModerationModule;
import dev.sheldan.abstracto.moderation.config.features.ModerationFeatures;
import dev.sheldan.abstracto.moderation.service.management.MuteRoleManagementService;
import net.dv8tion.jda.api.entities.Role;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
@@ -23,10 +25,14 @@ public class SetMuteRole extends AbstractConditionableCommand {
@Autowired
private MuteRoleManagementService muteRoleManagementService;
@Autowired
private RoleManagementService roleManagementService;
@Override
public CommandResult execute(CommandContext commandContext) {
checkParameters(commandContext);
ARole role = (ARole) commandContext.getParameters().getParameters().get(0);
Role jdaRole = (Role) commandContext.getParameters().getParameters().get(0);
ARole role = roleManagementService.findRole(jdaRole.getIdLong());
muteRoleManagementService.setMuteRoleForServer(commandContext.getUserInitiatedContext().getServer(), role);
return CommandResult.fromSuccess();
}
@@ -34,7 +40,7 @@ public class SetMuteRole extends AbstractConditionableCommand {
@Override
public CommandConfiguration getConfiguration() {
List<Parameter> parameters = new ArrayList<>();
parameters.add(Parameter.builder().name("role").templated(true).type(ARole.class).build());
parameters.add(Parameter.builder().name("role").templated(true).type(Role.class).build());
HelpInfo helpInfo = HelpInfo.builder().templated(true).build();
return CommandConfiguration.builder()
.name("setMuteRole")

View File

@@ -5,13 +5,16 @@ import dev.sheldan.abstracto.core.command.exception.InsufficientParametersExcept
import dev.sheldan.abstracto.core.command.execution.CommandContext;
import dev.sheldan.abstracto.core.command.execution.CommandResult;
import dev.sheldan.abstracto.core.models.database.ARole;
import dev.sheldan.abstracto.core.service.management.RoleManagementService;
import dev.sheldan.abstracto.moderation.service.management.MuteRoleManagementService;
import dev.sheldan.abstracto.test.command.CommandConfigValidator;
import dev.sheldan.abstracto.test.command.CommandTestUtilities;
import net.dv8tion.jda.api.entities.Role;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.Arrays;
@@ -27,12 +30,19 @@ public class SetMuteRoleTest {
@Mock
private MuteRoleManagementService muteRoleManagementService;
@Mock
private RoleManagementService roleManagementService;
@Test
public void testExecuteCommand() {
ARole muteRoleToSet = ARole.builder().build();
CommandContext parameters = CommandTestUtilities.getWithParameters(Arrays.asList(muteRoleToSet));
Role role = Mockito.mock(Role.class);
Long roleId = 5L;
when(role.getIdLong()).thenReturn(roleId);
ARole aRole = Mockito.mock(ARole.class);
when(roleManagementService.findRole(roleId)).thenReturn(aRole);
CommandContext parameters = CommandTestUtilities.getWithParameters(Arrays.asList(role));
CommandResult result = testUnit.execute(parameters);
verify(muteRoleManagementService, times(1)).setMuteRoleForServer(parameters.getUserInitiatedContext().getServer(), muteRoleToSet);
verify(muteRoleManagementService, times(1)).setMuteRoleForServer(parameters.getUserInitiatedContext().getServer(), aRole);
CommandTestUtilities.checkSuccessfulCompletion(result);
}