Skip to content

Commit

Permalink
Fix a test I broke again
Browse files Browse the repository at this point in the history
  • Loading branch information
A248 committed Aug 19, 2023
1 parent fdfd08e commit f01997b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,16 +184,18 @@ private MessagesConfig.All.NotFound notFound() {
}
return how.defaultValue(scopeManager);
}
String permissionSuffix = scopeManager.deconstruct(explicitScope, (type, value) -> {
return switch (type) {
case GLOBAL -> "global";
case SERVER -> "server." + value;
case CATEGORY -> "category." + value;
};
});
if (requirePermissions && !sender.hasPermission("libertybans.scope." + permissionSuffix)) {
sender.sendMessage(all().scopes().noPermission().replaceText("%SCOPE%", formatter.formatScope(explicitScope)));
return null;
if (requirePermissions) {
String permissionSuffix = scopeManager.deconstruct(explicitScope, (type, value) -> {
return switch (type) {
case GLOBAL -> "global";
case SERVER -> "server." + value;
case CATEGORY -> "category." + value;
};
});
if (!sender.hasPermission("libertybans.scope." + permissionSuffix)) {
sender.sendMessage(all().scopes().noPermission().replaceText("%SCOPE%", formatter.formatScope(explicitScope)));
return null;
}
}
return how.explicitScope(explicitScope);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@
import space.arim.libertybans.core.commands.ComponentMatcher;
import space.arim.libertybans.core.config.Configs;
import space.arim.libertybans.core.config.MessagesConfig;
import space.arim.libertybans.core.config.ScopeConfig;
import space.arim.libertybans.core.env.CmdSender;
import space.arim.libertybans.core.env.UUIDAndAddress;
import space.arim.libertybans.core.scope.InternalScopeManager;
import space.arim.libertybans.core.scope.ScopeParsing;
import space.arim.libertybans.core.scope.ScopeType;
import space.arim.libertybans.core.uuid.UUIDManager;
import space.arim.libertybans.it.util.RandomUtil;
import space.arim.omnibus.util.concurrent.CentralisedFuture;
Expand All @@ -56,7 +56,6 @@
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.function.BiFunction;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
Expand Down Expand Up @@ -310,7 +309,7 @@ public void unknownAddressVictimForName() {
public class ParseScopeFromCommand {

@BeforeEach
public void setup() {
public void setup(@Mock ScopeConfig scopeConfig) {
lenient().when(scopeManager.parseFrom(any())).thenAnswer((invocation) -> {
return new ScopeParsing() {
@Override
Expand All @@ -329,11 +328,8 @@ public ServerScope globalScope() {
}
}.parseInputOptionally(invocation.getArgument(0));
});
lenient().when(scopeManager.deconstruct(any(), any())).thenAnswer((invocation) -> {
BiFunction<ScopeType, String, String> computeResult = invocation.getArgument(1);
return computeResult.apply(ScopeType.GLOBAL, "");
});
when(sender.hasPermission(any())).thenReturn(true);
when(configs.getScopeConfig()).thenReturn(scopeConfig);
when(scopeConfig.requirePermissions()).thenReturn(false);
}

@Test
Expand Down

0 comments on commit f01997b

Please sign in to comment.