Answer what the local client may do from the model
The Swing client menu decided on its own whether a group can be (un)assigned and whether a client's channel can be joined, and the server groups dialog borrowed the menu's check. These are rules about the server, not about menus, so ServerModel answers them now and any frontend asks it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
package com.ts3client.net;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
class ServerModelRulesTest {
|
||||
|
||||
private final ServerModel model = new ServerModel();
|
||||
|
||||
private void grant(String permission, int value) {
|
||||
model.putPermissionName(permission);
|
||||
model.putSelfPermissionValue(permissionId(permission), value);
|
||||
}
|
||||
|
||||
private int permissionId(String name) {
|
||||
for (int id = 0; ; id++) {
|
||||
if (name.equals(model.permissionName(id))) return id;
|
||||
}
|
||||
}
|
||||
|
||||
private static Group group(int addPower, int removePower) {
|
||||
return new Group(9, "Group", 0, 0, 1, addPower, removePower);
|
||||
}
|
||||
|
||||
@Test
|
||||
void groupNeedsEnoughAddPowerAndRemovePowerToTakeAway() {
|
||||
grant("i_group_needed_member_add_power", 50);
|
||||
grant("i_group_needed_member_remove_power", 20);
|
||||
|
||||
assertTrue(model.canToggleGroup(group(50, 0), false));
|
||||
assertFalse(model.canToggleGroup(group(51, 0), false));
|
||||
assertTrue(model.canToggleGroup(group(50, 20), true));
|
||||
assertFalse(model.canToggleGroup(group(50, 21), true));
|
||||
}
|
||||
|
||||
@Test
|
||||
void unlimitedPowerIsMinusOneOnEitherSide() {
|
||||
grant("i_group_needed_member_add_power", 75);
|
||||
grant("i_group_needed_member_remove_power", -1);
|
||||
|
||||
assertFalse(model.canToggleGroup(group(-1, 0), false), "a group needing unlimited power");
|
||||
assertTrue(model.canToggleGroup(group(75, 1000), true), "unlimited remove power");
|
||||
}
|
||||
|
||||
@Test
|
||||
void joiningNeedsAVisibleChannelWithRoom() {
|
||||
ChannelNode channel = model.putChannel(1, "Full", 0, 0);
|
||||
model.putClient(5, "Someone", 1);
|
||||
assertFalse(model.canJoinChannel(1), "not subscribed");
|
||||
|
||||
channel.subscribed = true;
|
||||
assertTrue(model.canJoinChannel(1));
|
||||
channel.maxClients = 1;
|
||||
channel.clients.add(model.getClient(5));
|
||||
assertFalse(model.canJoinChannel(1), "full");
|
||||
assertFalse(model.canJoinChannel(2), "unknown");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user