[AB-234] allow templates have individual (additional) allowed mention configurations

adding primary keys to command disabled and command cooldown group
exposing service method to retrieve the channel for a post target
This commit is contained in:
Sheldan
2021-04-24 02:05:15 +02:00
parent 49a9598062
commit fa4c455ca2
14 changed files with 106 additions and 41 deletions

View File

@@ -16,6 +16,7 @@ import org.mockito.junit.MockitoJUnitRunner;
import java.util.List;
import java.util.Optional;
import java.util.Set;
import static org.mockito.Mockito.*;
@@ -68,7 +69,7 @@ public class AllowedMentionServiceBeanTest {
public void getAllowedMentionTypesForServerEmpty() {
allDefaultConfigAllowed();
when(allowedMentionManagementService.getCustomAllowedMentionFor(SERVER_ID)).thenReturn(Optional.empty());
List<Message.MentionType> allowedMentions = testUnit.getAllowedMentionTypesForServer(SERVER_ID);
Set<Message.MentionType> allowedMentions = testUnit.getAllowedMentionTypesForServer(SERVER_ID);
Assert.assertNull(allowedMentions);
}
@@ -78,9 +79,9 @@ public class AllowedMentionServiceBeanTest {
when(allowedMentionConfig.getRole()).thenReturn(false);
when(allowedMentionConfig.getUser()).thenReturn(false);
when(allowedMentionManagementService.getCustomAllowedMentionFor(SERVER_ID)).thenReturn(Optional.empty());
List<Message.MentionType> allowedMentions = testUnit.getAllowedMentionTypesForServer(SERVER_ID);
Set<Message.MentionType> allowedMentions = testUnit.getAllowedMentionTypesForServer(SERVER_ID);
Assert.assertEquals(1, allowedMentions.size());
Assert.assertEquals(Message.MentionType.EVERYONE, allowedMentions.get(0));
Assert.assertEquals(Message.MentionType.EVERYONE, allowedMentions.iterator().next());
}
@Test
@@ -89,7 +90,7 @@ public class AllowedMentionServiceBeanTest {
when(allowedMentionConfig.getRole()).thenReturn(false);
when(allowedMentionConfig.getUser()).thenReturn(false);
when(allowedMentionManagementService.getCustomAllowedMentionFor(SERVER_ID)).thenReturn(Optional.empty());
List<Message.MentionType> allowedMentions = testUnit.getAllowedMentionTypesForServer(SERVER_ID);
Set<Message.MentionType> allowedMentions = testUnit.getAllowedMentionTypesForServer(SERVER_ID);
Assert.assertEquals(0, allowedMentions.size());
}

View File

@@ -99,9 +99,11 @@ public class TemplateServiceBeanTest {
when(configService.getLongValueOrConfigDefault(CoreFeatureConfig.MAX_MESSAGES_KEY, SERVER_ID)).thenReturn(5L);
String templateContent = String.format("{ \"additionalMessage\": \"%s\"}", additionalMessage);
EmbedConfiguration config = Mockito.mock(EmbedConfiguration.class);
when(config.getAdditionalMessageLengthLimit()).thenReturn(2000L);
MetaEmbedConfiguration metaConfig = Mockito.mock(MetaEmbedConfiguration.class);
when(config.getMetaConfig()).thenReturn(metaConfig);
when(metaConfig.getAdditionalMessageLengthLimit()).thenReturn(2000L);
when(config.getAdditionalMessage()).thenReturn(additionalMessage);
when(config.getMessageLimit()).thenReturn(5L);
when(metaConfig.getMessageLimit()).thenReturn(5L);
when(configuration.getTemplate(getEmbedTemplateKey(), null, SERVER_ID, null, true, false)).thenReturn(new Template(getEmbedTemplateKey(), templateContent, getNonMockedConfiguration()));
when(gson.fromJson(templateContent, EmbedConfiguration.class)).thenReturn(config);
MessageToSend messageToSend = templateServiceBean.renderEmbedTemplate(TEMPLATE_KEY, new Object());
@@ -117,9 +119,11 @@ public class TemplateServiceBeanTest {
when(configService.getLongValueOrConfigDefault(CoreFeatureConfig.MAX_MESSAGES_KEY, SERVER_ID)).thenReturn(5L);
String templateContent = String.format("{ \"additionalMessage\": \"%s\", \"messageLimit\": 1}", additionalMessage);
EmbedConfiguration config = Mockito.mock(EmbedConfiguration.class);
when(config.getAdditionalMessageLengthLimit()).thenReturn(2000L);
MetaEmbedConfiguration metaConfig = Mockito.mock(MetaEmbedConfiguration.class);
when(config.getMetaConfig()).thenReturn(metaConfig);
when(metaConfig.getAdditionalMessageLengthLimit()).thenReturn(2000L);
when(config.getAdditionalMessage()).thenReturn(additionalMessage);
when(config.getMessageLimit()).thenReturn(1L);
when(metaConfig.getMessageLimit()).thenReturn(1L);
when(configuration.getTemplate(getEmbedTemplateKey(), null, SERVER_ID, null, true, false)).thenReturn(new Template(getEmbedTemplateKey(), templateContent, getNonMockedConfiguration()));
when(gson.fromJson(templateContent, EmbedConfiguration.class)).thenReturn(config);
MessageToSend messageToSend = templateServiceBean.renderEmbedTemplate(TEMPLATE_KEY, new Object());
@@ -134,8 +138,10 @@ public class TemplateServiceBeanTest {
when(configService.getLongValueOrConfigDefault(CoreFeatureConfig.MAX_MESSAGES_KEY, SERVER_ID)).thenReturn(5L);
String templateContent = String.format("{ \"additionalMessage\": \"%s\"}", additionalMessage);
EmbedConfiguration config = Mockito.mock(EmbedConfiguration.class);
when(config.getAdditionalMessageLengthLimit()).thenReturn(500L);
when(config.getMessageLimit()).thenReturn(5L);
MetaEmbedConfiguration metaConfig = Mockito.mock(MetaEmbedConfiguration.class);
when(config.getMetaConfig()).thenReturn(metaConfig);
when(metaConfig.getAdditionalMessageLengthLimit()).thenReturn(500L);
when(metaConfig.getMessageLimit()).thenReturn(5L);
when(config.getAdditionalMessage()).thenReturn(additionalMessage);
when(configuration.getTemplate(getEmbedTemplateKey(), null, SERVER_ID, null, true, false)).thenReturn(new Template(getEmbedTemplateKey(), templateContent, getNonMockedConfiguration()));
when(gson.fromJson(templateContent, EmbedConfiguration.class)).thenReturn(config);