Skip to content

Commit

Permalink
Fix failing test and add some more
Browse files Browse the repository at this point in the history
  • Loading branch information
A248 committed Aug 18, 2023
1 parent a97dcce commit 541eadc
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ public void optimizedApplicabilityQuery(AddressStrictness strictness) {
private String expectedSql(AddressStrictness strictness) {
return switch (strictness) {
case LENIENT -> """
select "libertybans_simple_bans"."victim_type", \
"libertybans_simple_bans"."victim_uuid", "libertybans_simple_bans"."victim_address", \
"libertybans_simple_bans"."operator", "libertybans_simple_bans"."reason", "libertybans_simple_bans"."scope", \
select "libertybans_simple_bans"."victim_type", "libertybans_simple_bans"."victim_uuid", \
"libertybans_simple_bans"."victim_address", "libertybans_simple_bans"."operator", \
"libertybans_simple_bans"."reason", "libertybans_simple_bans"."scope_type", "libertybans_simple_bans"."scope", \
"libertybans_simple_bans"."start", "libertybans_simple_bans"."end", "libertybans_simple_bans"."track", \
"libertybans_simple_bans"."id" \
from "libertybans_simple_bans" where \
Expand All @@ -86,7 +86,7 @@ private String expectedSql(AddressStrictness strictness) {
select "libertybans_applicable_bans"."victim_type", \
"libertybans_applicable_bans"."victim_uuid", "libertybans_applicable_bans"."victim_address", \
"libertybans_applicable_bans"."operator", "libertybans_applicable_bans"."reason", \
"libertybans_applicable_bans"."scope", "libertybans_applicable_bans"."start", \
"libertybans_applicable_bans"."scope_type", "libertybans_applicable_bans"."scope", "libertybans_applicable_bans"."start", \
"libertybans_applicable_bans"."end", "libertybans_applicable_bans"."track", "libertybans_applicable_bans"."id" \
from "libertybans_applicable_bans" where \
(("libertybans_applicable_bans"."end" = 0 or "libertybans_applicable_bans"."end" > cast(? as bigint)) \
Expand All @@ -98,7 +98,7 @@ private String expectedSql(AddressStrictness strictness) {
select "libertybans_applicable_bans"."victim_type", \
"libertybans_applicable_bans"."victim_uuid", "libertybans_applicable_bans"."victim_address", \
"libertybans_applicable_bans"."operator", "libertybans_applicable_bans"."reason", \
"libertybans_applicable_bans"."scope", "libertybans_applicable_bans"."start", \
"libertybans_applicable_bans"."scope_type", "libertybans_applicable_bans"."scope", "libertybans_applicable_bans"."start", \
"libertybans_applicable_bans"."end", "libertybans_applicable_bans"."track", "libertybans_applicable_bans"."id" \
from "libertybans_applicable_bans" \
join "libertybans_strict_links" on "libertybans_applicable_bans"."uuid" = "libertybans_strict_links"."uuid1" \
Expand All @@ -112,7 +112,7 @@ private String expectedSql(AddressStrictness strictness) {
select "libertybans_applicable_bans"."victim_type", \
"libertybans_applicable_bans"."victim_uuid", "libertybans_applicable_bans"."victim_address", \
"libertybans_applicable_bans"."operator", "libertybans_applicable_bans"."reason", \
"libertybans_applicable_bans"."scope", "libertybans_applicable_bans"."start", \
"libertybans_applicable_bans"."scope_type", "libertybans_applicable_bans"."scope", "libertybans_applicable_bans"."start", \
"libertybans_applicable_bans"."end", "libertybans_applicable_bans"."track", "libertybans_applicable_bans"."id" \
from "libertybans_applicable_bans" \
join "libertybans_strict_links" on "libertybans_applicable_bans"."uuid" = "libertybans_strict_links"."uuid1" \
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import space.arim.libertybans.api.punish.Punishment;
import space.arim.libertybans.api.punish.PunishmentDrafter;
import space.arim.libertybans.api.scope.ScopeManager;
import space.arim.libertybans.api.scope.ServerScope;
import space.arim.libertybans.api.select.PunishmentSelector;
import space.arim.libertybans.api.select.SelectionOrderBuilder;
import space.arim.libertybans.api.select.SelectionPredicate;
Expand All @@ -57,6 +58,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static space.arim.libertybans.api.select.SelectionPredicate.matchingNone;

@ExtendWith(InjectionInvocationContextProvider.class)
@ExtendWith({RandomPunishmentTypeResolver.class, RandomOperatorResolver.class, RandomVictimResolver.class})
Expand Down Expand Up @@ -247,7 +249,7 @@ public void selectVictimsBySelfOrType() {
assertEquals(
List.of(banAddress1, muteAddress2),
getPunishments(selector.selectionBuilder().victimTypes(
SelectionPredicate.matchingNone(Victim.VictimType.PLAYER)
matchingNone(Victim.VictimType.PLAYER)
)),
"Should be identical to previous assertion");
assertEquals(
Expand All @@ -261,7 +263,7 @@ public void selectVictimsBySelfOrType() {
getPunishments(selector.selectionBuilder().victims(SelectionPredicate.matchingAnyOf(uuid2, address1))));
assertEquals(
List.of(warnUuid2, banAddress1),
getPunishments(selector.selectionBuilder().victims(SelectionPredicate.matchingNone(uuid1, address2))),
getPunishments(selector.selectionBuilder().victims(matchingNone(uuid1, address2))),
"Should be identical to previous assertion (in context)");
}

Expand Down Expand Up @@ -330,4 +332,71 @@ public void selectByTrackOrItsInexistence() {
)));
}

@TestTemplate
public void selectScopes(@DontInject Victim victim1, @DontInject Victim victim2, @DontInject Victim victim3) {
ServerScope globalScope = scopeManager.globalScope();
ServerScope kitpvpScope = scopeManager.specificScope("kitpvp");
ServerScope tntpvpScope = scopeManager.specificScope("tntpvp");
ServerScope pvpScope = scopeManager.category("pvp");
ServerScope creativeServerScope = scopeManager.specificScope("creative");
ServerScope creativeCategoryScope = scopeManager.category("creative");

Punishment banGlobal = getPunishment(
draftBuilder(PunishmentType.BAN, victim1, "global ban"));

Punishment muteKitpvp = getPunishment(
draftBuilder(PunishmentType.MUTE, victim1, "mute on kitpvp").scope(kitpvpScope));
Punishment warnKitpvp = getPunishment(
draftBuilder(PunishmentType.WARN, victim2, "warn on kitpvp").scope(kitpvpScope));
Punishment warnTntpvp = getPunishment(
draftBuilder(PunishmentType.WARN, victim2, "warn on tntpvp").scope(tntpvpScope));
Punishment banPvp = getPunishment(
draftBuilder(PunishmentType.BAN, victim2, "banned on pvp servers").scope(pvpScope));

Punishment muteCreativeServer = getPunishment(
draftBuilder(PunishmentType.MUTE, victim2, "mute on creative server").scope(creativeServerScope));
Punishment muteCreativeCategory = getPunishment(
draftBuilder(PunishmentType.MUTE, victim3, "mute on creative category").scope(creativeCategoryScope));

assertEmpty(selector.selectionBuilder().selectAll().scope(scopeManager.specificScope("nonexistent")));
assertEmpty(selector.selectionBuilder().selectAll().scope(scopeManager.category("nonexistent")));

assertEquals(
List.of(banGlobal, muteKitpvp, warnKitpvp, warnTntpvp, banPvp, muteCreativeServer, muteCreativeCategory),
getPunishments(selector.selectionBuilder())
);
assertEquals(
List.of(banGlobal, muteKitpvp),
getPunishments(selector.selectionBuilder().victim(victim1))
);
assertEquals(
List.of(muteKitpvp, warnKitpvp, warnTntpvp, banPvp, muteCreativeServer, muteCreativeCategory),
getPunishments(selector.selectionBuilder().scopes(matchingNone(globalScope)))
);
assertEquals(
List.of(banGlobal),
getPunishments(selector.selectionBuilder().scope(globalScope))
);
assertEquals(
List.of(muteKitpvp, warnKitpvp),
getPunishments(selector.selectionBuilder().scope(kitpvpScope))
);
assertEquals(
List.of(warnTntpvp),
getPunishments(selector.selectionBuilder().scope(tntpvpScope))
);
assertEquals(
List.of(banPvp),
getPunishments(selector.selectionBuilder().scope(pvpScope))
);
assertEquals(
List.of(muteCreativeServer),
getPunishments(selector.selectionBuilder().scope(creativeServerScope))
);
assertEquals(
List.of(muteCreativeCategory),
getPunishments(selector.selectionBuilder().scope(creativeCategoryScope))
);
}

}

0 comments on commit 541eadc

Please sign in to comment.