summaryrefslogtreecommitdiff
path: root/server/test/command
diff options
context:
space:
mode:
Diffstat (limited to 'server/test/command')
-rw-r--r--server/test/command/action_log_rollback_test.dart52
-rw-r--r--server/test/command/activate_monster_type_command_test.dart138
-rw-r--r--server/test/command/add_character_command_test.dart51
-rw-r--r--server/test/command/add_condition_command_test.dart167
-rw-r--r--server/test/command/add_cs_party_card_command_test.dart80
-rw-r--r--server/test/command/add_faction_card_command_test.dart100
-rw-r--r--server/test/command/add_loot_card_command_test.dart55
-rw-r--r--server/test/command/add_monster_command_test.dart95
-rw-r--r--server/test/command/add_perk_command_test.dart84
-rw-r--r--server/test/command/add_special_loot_card_command_test.dart100
-rw-r--r--server/test/command/add_standee_command_test.dart121
-rw-r--r--server/test/command/amd_add_minus_one_command_test.dart116
-rw-r--r--server/test/command/amd_cassandra_special_command_test.dart63
-rw-r--r--server/test/command/amd_imbue1_command_test.dart47
-rw-r--r--server/test/command/amd_imbue2_command_test.dart66
-rw-r--r--server/test/command/amd_remove_imbue_command_test.dart105
-rw-r--r--server/test/command/amd_remove_minus_1_command_test.dart157
-rw-r--r--server/test/command/amd_remove_minus_2_command_test.dart112
-rw-r--r--server/test/command/amd_remove_plus_0_command_test.dart119
-rw-r--r--server/test/command/amd_reveal_command_test.dart50
-rw-r--r--server/test/command/bad_omen_command_test.dart124
-rw-r--r--server/test/command/change_name_command_test.dart58
-rw-r--r--server/test/command/change_stat_commands/change_bless_command_test.dart175
-rw-r--r--server/test/command/change_stat_commands/change_curse_command_test.dart175
-rw-r--r--server/test/command/change_stat_commands/change_empower_command_test.dart240
-rw-r--r--server/test/command/change_stat_commands/change_enfeeble_command_test.dart145
-rw-r--r--server/test/command/change_stat_commands/change_health_command_test.dart193
-rw-r--r--server/test/command/change_stat_commands/change_max_health_command_test.dart183
-rw-r--r--server/test/command/change_stat_commands/change_stat_command_test.dart294
-rw-r--r--server/test/command/change_stat_commands/change_xp_command_test.dart103
-rw-r--r--server/test/command/clear_unlocked_classes_command_test.dart52
-rw-r--r--server/test/command/command_registry_test.dart144
-rw-r--r--server/test/command/corrosive_spew_command_test.dart31
-rw-r--r--server/test/command/donate_cs_sanctuary_command_test.dart77
-rw-r--r--server/test/command/draw_ability_card_command_test.dart51
-rw-r--r--server/test/command/draw_command_test.dart46
-rw-r--r--server/test/command/draw_loot_card_command_test.dart87
-rw-r--r--server/test/command/draw_modifier_card_command_test.dart42
-rw-r--r--server/test/command/enhance_loot_card_command_test.dart82
-rw-r--r--server/test/command/ice_wraith_change_form_command_test.dart97
-rw-r--r--server/test/command/imbue_element_command_test.dart44
-rw-r--r--server/test/command/load_save_command_test.dart96
-rw-r--r--server/test/command/mutable_game_methods_test.dart1488
-rw-r--r--server/test/command/next_round_command_test.dart174
-rw-r--r--server/test/command/next_turn_command_test.dart56
-rw-r--r--server/test/command/note_row_command_test.dart142
-rw-r--r--server/test/command/note_row_standee_death_test.dart81
-rw-r--r--server/test/command/remove_amd_card_command_test.dart75
-rw-r--r--server/test/command/remove_character_command_test.dart30
-rw-r--r--server/test/command/remove_condition_command_test.dart129
-rw-r--r--server/test/command/remove_cs_party_card_command_test.dart54
-rw-r--r--server/test/command/remove_monster_command_test.dart74
-rw-r--r--server/test/command/remove_special_loot_card_command_test.dart76
-rw-r--r--server/test/command/reorder_list_command_test.dart124
-rw-r--r--server/test/command/return_modifier_card_command_test.dart33
-rw-r--r--server/test/command/set_ally_deck_in_og_gloom_command_test.dart66
-rw-r--r--server/test/command/set_as_summon_command_test.dart90
-rw-r--r--server/test/command/set_auto_level_adjust_command_test.dart51
-rw-r--r--server/test/command/set_campaign_command_test.dart33
-rw-r--r--server/test/command/set_character_level_command_test.dart48
-rw-r--r--server/test/command/set_difficulty_command_test.dart35
-rw-r--r--server/test/command/set_figure_note_command_test.dart78
-rw-r--r--server/test/command/set_init_command_test.dart53
-rw-r--r--server/test/command/set_level_command_test.dart55
-rw-r--r--server/test/command/set_loot_owner_command_test.dart48
-rw-r--r--server/test/command/set_scenario_command_test.dart714
-rw-r--r--server/test/command/set_solo_command_test.dart39
-rw-r--r--server/test/command/show_ally_deck_command_test.dart45
-rw-r--r--server/test/command/shuffle_ability_card_command_test.dart93
-rw-r--r--server/test/command/test_helpers.dart56
-rw-r--r--server/test/command/track_standees_command_test.dart97
-rw-r--r--server/test/command/use_element_command_test.dart40
-rw-r--r--server/test/command/use_fh_perks_command_test.dart50
73 files changed, 8644 insertions, 0 deletions
diff --git a/server/test/command/action_log_rollback_test.dart b/server/test/command/action_log_rollback_test.dart
new file mode 100644
index 0000000..a3bf806
--- /dev/null
+++ b/server/test/command/action_log_rollback_test.dart
@@ -0,0 +1,52 @@
+// ignore_for_file: no-magic-number, avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ GameState gs() => getIt<GameState>();
+
+ // The tap-to-rollback in ActionLogMenu rolls back to a chosen entry by calling
+ // undo (currentIndex - targetIndex) times. This verifies that semantics: the
+ // chosen action stays, later ones are undone, and everything stays redoable.
+ test('rolling back to an action undoes only the later ones (redoable)', () {
+ gs().clearList();
+ final startMonsters = gs().currentList.whereType<Monster>().length;
+
+ gs().action(AddMonsterCommand("Zealot", 1, false, gameState: gs()));
+ final afterZealotIndex = gs().commandIndex; // the entry we roll back to
+ gs().action(
+ AddMonsterCommand("Ancient Artillery (FH)", 1, false, gameState: gs()),
+ );
+
+ expect(gs().currentList.whereType<Monster>().length, startMonsters + 2);
+
+ // Roll back to "after Zealot": undo (current - target) times.
+ final count = gs().commandIndex - afterZealotIndex;
+ expect(count, 1);
+ for (int k = 0; k < count; k++) {
+ gs().undo();
+ }
+
+ // Zealot remains; the later add is undone.
+ expect(gs().currentList.any((e) => e.id == "Zealot"), true);
+ expect(
+ gs().currentList.any((e) => e.id == "Ancient Artillery (FH)"),
+ false,
+ );
+
+ // Still redoable until a new action is taken.
+ for (int k = 0; k < count; k++) {
+ gs().redo();
+ }
+ expect(gs().currentList.any((e) => e.id == "Ancient Artillery (FH)"), true);
+ });
+}
diff --git a/server/test/command/activate_monster_type_command_test.dart b/server/test/command/activate_monster_type_command_test.dart
new file mode 100644
index 0000000..06d82f6
--- /dev/null
+++ b/server/test/command/activate_monster_type_command_test.dart
@@ -0,0 +1,138 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/activate_monster_type_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/draw_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() async {
+ await setUpGame();
+
+ group('ActivateMonsterTypeCommand', () {
+ test('should activate a monster', () {
+ // Arrange
+ getIt<GameState>().clearList();
+ AddMonsterCommand(
+ 'Zealot',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final monster =
+ getIt<GameState>().currentList.firstWhere((m) => m.id == 'Zealot')
+ as Monster;
+
+ expect(monster.isActive, isFalse);
+
+ final command = ActivateMonsterTypeCommand(
+ 'Zealot',
+ true,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(monster.isActive, isTrue);
+ checkSaveState();
+ });
+
+ test('should deactivate a monster', () {
+ // Arrange
+ getIt<GameState>().clearList();
+ AddMonsterCommand(
+ 'Zealot',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final monster =
+ getIt<GameState>().currentList.firstWhere((m) => m.id == 'Zealot')
+ as Monster;
+
+ final command = ActivateMonsterTypeCommand(
+ 'Zealot',
+ false,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(monster.isActive, isFalse);
+ checkSaveState();
+ });
+
+ test('describe should return correct string for activation', () {
+ // Arrange
+ final command = ActivateMonsterTypeCommand(
+ 'Zealot',
+ true,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Activate Zealot');
+ checkSaveState();
+ });
+
+ test('describe should return correct string for deactivation', () {
+ // Arrange
+ final command = ActivateMonsterTypeCommand(
+ 'Zealot',
+ false,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Deactivate Zealot');
+ checkSaveState();
+ });
+
+ test('undo does not throw', () {
+ getIt<GameState>().clearList();
+ AddMonsterCommand(
+ 'Zealot',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final gs = getIt<GameState>();
+ gs.action(
+ ActivateMonsterTypeCommand(
+ 'Zealot',
+ true,
+ gameState: getIt<GameState>(),
+ ),
+ );
+ expect(() => gs.undo(), returnsNormally);
+ });
+
+ test('activate in RoundState.playTurns draws ability card and sorts', () {
+ getIt<GameState>().clearList();
+ AddMonsterCommand(
+ 'Zealot',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ // Enter playTurns state via DrawCommand
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ expect(getIt<GameState>().roundState, RoundState.playTurns);
+ // Activate should not throw even in playTurns state
+ expect(
+ () => ActivateMonsterTypeCommand(
+ 'Zealot',
+ true,
+ gameState: getIt<GameState>(),
+ ).execute(),
+ returnsNormally,
+ );
+ });
+ });
+}
diff --git a/server/test/command/add_character_command_test.dart b/server/test/command/add_character_command_test.dart
new file mode 100644
index 0000000..4fe9f1c
--- /dev/null
+++ b/server/test/command/add_character_command_test.dart
@@ -0,0 +1,51 @@
+// ignore_for_file: no-magic-number
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/game_methods.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+
+import 'test_helpers.dart';
+
+void _tests() {
+ String oldState = gameState.toString();
+ AddCharacterCommand command = AddCharacterCommand(
+ "Hatchet",
+ "Jaws of the Lion",
+ "Arnold",
+ 9,
+ );
+ command.execute();
+
+ test("added ok", () {
+ expect(gameState.currentList.first is Character, true);
+ expect(
+ (gameState.currentList.first as Character).characterState.display,
+ "Arnold",
+ );
+ expect(gameState.currentList.first.id, "Hatchet");
+ expect(
+ (gameState.currentList.first as Character).characterClass.name,
+ "Hatchet",
+ );
+ expect(gameState.currentList.length, 1);
+ Character brute = GameMethods.getCurrentCharacters().first;
+ expect(brute.characterState.display, "Arnold");
+ expect(brute.characterState.level, 9);
+ expect(gameState.unlockedClasses.first, "Hatchet");
+ checkNoSideEffects(["currentList", "unlockedClasses"], oldState);
+ checkSaveState();
+ });
+
+ test("description is ok", () {
+ expect(command.describe(), "Add Hatchet");
+ //assert(_gameState.commands.last?.describe() == "Add Hatchet");
+ });
+
+ //todo: test objective/escort/2-mini
+}
+
+Future<void> main() async {
+ await setUpGame();
+ _tests();
+}
diff --git a/server/test/command/add_condition_command_test.dart b/server/test/command/add_condition_command_test.dart
new file mode 100644
index 0000000..4e5eac2
--- /dev/null
+++ b/server/test/command/add_condition_command_test.dart
@@ -0,0 +1,167 @@
+// ignore_for_file: no-magic-number, avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_condition_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+ late Monster monster;
+ late MonsterInstance monsterInstance;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ AddMonsterCommand(
+ "Ancient Artillery (FH)",
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ "Ancient Artillery (FH)",
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ monsterInstance = monster.monsterInstances.first;
+ });
+
+ group('AddConditionCommand', () {
+ test('should add a condition to a character', () {
+ // Arrange
+ final command = AddConditionCommand(
+ Condition.poison,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(character.characterState.conditions, contains(Condition.poison));
+ });
+
+ test('should add a condition to a monster instance', () {
+ // Arrange
+ final command = AddConditionCommand(
+ Condition.wound,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(monsterInstance.conditions, contains(Condition.wound));
+ });
+
+ test('should increment chill counter when adding CHILL condition', () {
+ // Arrange
+ final command1 = AddConditionCommand(
+ Condition.chill,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+ final command2 = AddConditionCommand(
+ Condition.chill,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command1.execute();
+ command2.execute();
+
+ // Assert
+ expect(character.characterState.chill, 2);
+ // The list will contain two chill entries
+ expect(
+ character.characterState.conditions
+ .where((c) => c == Condition.chill)
+ .length,
+ 2,
+ );
+ });
+
+ test('should not add a duplicate non-stacking condition', () {
+ // Arrange
+ final command1 = AddConditionCommand(
+ Condition.poison,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+ final command2 = AddConditionCommand(
+ Condition.poison,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command1.execute();
+ command2.execute();
+
+ // Assert
+ expect(
+ character.characterState.conditions
+ .where((c) => c == Condition.poison)
+ .length,
+ 1,
+ );
+ });
+
+ test('describe should return correct string for character', () {
+ // Arrange
+ final command = AddConditionCommand(
+ Condition.muddle,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Add condition: muddle');
+ });
+
+ test('describe should return correct string for monster', () {
+ // Arrange
+ final command = AddConditionCommand(
+ Condition.stun,
+ monster.id,
+ monsterInstance.getId(),
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Add condition: stun');
+ });
+ });
+}
diff --git a/server/test/command/add_cs_party_card_command_test.dart b/server/test/command/add_cs_party_card_command_test.dart
new file mode 100644
index 0000000..c954be6
--- /dev/null
+++ b/server/test/command/add_cs_party_card_command_test.dart
@@ -0,0 +1,80 @@
+// ignore_for_file: no-magic-number, avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_cs_party_card_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ // Using a non-CS character is fine for testing the command's logic
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ });
+
+ group('AddCSPartyCardCommand', () {
+ test('should add a CS party card to a character deck', () {
+ // Arrange
+ final command = AddCSPartyCardCommand(
+ character.id,
+ 1,
+ gameState: getIt<GameState>(),
+ );
+ final modifierDeck = character.characterState.modifierDeck;
+ final initialCardCount = modifierDeck.drawPileSize;
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalCardCount = modifierDeck.drawPileSize;
+ expect(finalCardCount, initialCardCount + 1);
+ expect(modifierDeck.hasCard('party/1'), isTrue);
+ checkSaveState();
+ });
+
+ test('should add a different CS party card to a character deck', () {
+ // Arrange
+ final command = AddCSPartyCardCommand(
+ character.id,
+ 2,
+ gameState: getIt<GameState>(),
+ );
+ final modifierDeck = character.characterState.modifierDeck;
+ final initialCardCount = modifierDeck.drawPileSize;
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalCardCount = modifierDeck.drawPileSize;
+ expect(finalCardCount, initialCardCount + 1);
+ expect(modifierDeck.hasCard('party/2'), isTrue);
+ checkSaveState();
+ });
+
+ test('describe should return correct string', () {
+ // Arrange
+ final command = AddCSPartyCardCommand(
+ 'Blinkblade',
+ 1,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Blinkblade add party card 1');
+ });
+ });
+}
diff --git a/server/test/command/add_faction_card_command_test.dart b/server/test/command/add_faction_card_command_test.dart
new file mode 100644
index 0000000..e5fa382
--- /dev/null
+++ b/server/test/command/add_faction_card_command_test.dart
@@ -0,0 +1,100 @@
+// ignore_for_file: avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_faction_card_command.dart';
+import 'package:x_haven_server/core/game_methods.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+ late String factionCardId;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ // Get a valid faction card ID to use in tests
+ factionCardId = GameMethods.getFactionCards('Military').first.gfx;
+ });
+
+ group('AddFactionCardCommand', () {
+ test('should add a faction card to a character deck', () {
+ // Arrange
+ final command = AddFactionCardCommand(
+ character.id,
+ factionCardId,
+ true,
+ gameState: getIt<GameState>(),
+ );
+ final modifierDeck = character.characterState.modifierDeck;
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(modifierDeck.hasCard(factionCardId), isTrue);
+ });
+
+ test('should remove a faction card from a character deck', () {
+ // Arrange
+ final modifierDeck = character.characterState.modifierDeck;
+ // Add the card first
+ AddFactionCardCommand(
+ character.id,
+ factionCardId,
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(modifierDeck.hasCard(factionCardId), isTrue);
+
+ final command = AddFactionCardCommand(
+ character.id,
+ factionCardId,
+ false,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(modifierDeck.hasCard(factionCardId), isFalse);
+ });
+
+ test('describe should return correct string for adding a card', () {
+ // Arrange
+ final command = AddFactionCardCommand(
+ 'Blinkblade',
+ factionCardId,
+ true,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Blinkblade add faction card');
+ });
+
+ test('describe should return correct string for removing a card', () {
+ // Arrange
+ final command = AddFactionCardCommand(
+ 'Blinkblade',
+ factionCardId,
+ false,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Blinkblade remove faction card');
+ });
+ });
+}
diff --git a/server/test/command/add_loot_card_command_test.dart b/server/test/command/add_loot_card_command_test.dart
new file mode 100644
index 0000000..7ff8c0d
--- /dev/null
+++ b/server/test/command/add_loot_card_command_test.dart
@@ -0,0 +1,55 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_loot_card_command.dart';
+import 'package:x_haven_server/core/commands/set_campaign_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ // A scenario is needed to initialize the loot deck
+ SetCampaignCommand("Frosthaven").execute();
+ SetScenarioCommand(
+ '#0 Howling in the Snow',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ });
+
+ group('AddLootCardCommand', () {
+ test('should add a specified loot card to the deck', () {
+ // Arrange
+ final command = AddLootCardCommand(
+ 'lumber',
+ gameState: getIt<GameState>(),
+ );
+ final lootDeck = getIt<GameState>().lootDeck;
+ final initialCardCount = lootDeck.drawPileSize;
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(lootDeck.drawPileSize, initialCardCount + 1);
+ checkSaveState();
+ });
+
+ test('describe should return the correct string', () {
+ // Arrange
+ final command = AddLootCardCommand(
+ 'hides',
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Add hides Loot Card');
+ });
+ });
+}
diff --git a/server/test/command/add_monster_command_test.dart b/server/test/command/add_monster_command_test.dart
new file mode 100644
index 0000000..783346f
--- /dev/null
+++ b/server/test/command/add_monster_command_test.dart
@@ -0,0 +1,95 @@
+// ignore_for_file: no-magic-number
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/set_level_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ });
+
+ group('AddMonsterCommand', () {
+ test('should add a monster to the game', () {
+ // Arrange
+ final command = AddMonsterCommand(
+ "Ancient Artillery (FH)",
+ 2,
+ false,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ expect(getIt<GameState>().currentList, contains(monster));
+ expect(monster.id, "Ancient Artillery (FH)");
+ expect(monster.level, 2);
+ expect(monster.isAlly, isFalse);
+ });
+
+ test('should add an allied monster', () {
+ // Arrange
+ final command = AddMonsterCommand(
+ "Ancient Artillery (FH)",
+ 2,
+ true,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ expect(monster.isAlly, isTrue);
+ });
+
+ test('should use game level if monster level is null', () {
+ // Arrange
+ SetLevelCommand(3, null).execute();
+ final command = AddMonsterCommand(
+ "Ancient Artillery (FH)",
+ null,
+ false,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ expect(monster.level, 3);
+ });
+
+ test('describe should return correct string', () {
+ // Arrange
+ final command = AddMonsterCommand(
+ "Ancient Artillery (FH)",
+ 2,
+ false,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Add Ancient Artillery');
+ });
+ });
+}
diff --git a/server/test/command/add_perk_command_test.dart b/server/test/command/add_perk_command_test.dart
new file mode 100644
index 0000000..3cac038
--- /dev/null
+++ b/server/test/command/add_perk_command_test.dart
@@ -0,0 +1,84 @@
+// ignore_for_file: avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_perk_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ });
+
+ group('AddPerkCommand', () {
+ test('should add a perk to a character', () {
+ // Arrange
+ final perkIndex = 0;
+ final command = AddPerkCommand(character.id, perkIndex);
+ final initialPerkState = character.characterState.perkList[perkIndex];
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalPerkState = character.characterState.perkList[perkIndex];
+ expect(initialPerkState, isFalse);
+ expect(finalPerkState, isTrue);
+ checkSaveState();
+ });
+
+ test('should remove an already added perk from a character', () {
+ // Arrange
+ final perkIndex = 0;
+ // Add the perk first
+ AddPerkCommand(character.id, perkIndex).execute();
+ final initialPerkState = character.characterState.perkList[perkIndex];
+ final command = AddPerkCommand(character.id, perkIndex);
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalPerkState = character.characterState.perkList[perkIndex];
+ expect(initialPerkState, isTrue);
+ expect(finalPerkState, isFalse);
+ checkSaveState();
+ });
+
+ test('describe should return "Remove" when adding a perk (due to bug)', () {
+ // Arrange
+ // The perk is not yet added, so perkList[index] is false.
+ final command = AddPerkCommand(character.id, 0);
+ expect(character.characterState.perkList[0], isFalse);
+
+ // Act & Assert
+ // The describe method has a bug: it says "Remove" when it should say "Add".
+ expect(command.describe(), "Remove '${character.id}' Perk 0");
+ });
+
+ test('describe should return "Add" when removing a perk (due to bug)', () {
+ // Arrange
+ // Add the perk first so perkList[index] is true.
+ AddPerkCommand(character.id, 0).execute();
+ expect(character.characterState.perkList[0], isTrue);
+ final command = AddPerkCommand(character.id, 0);
+
+ // Act & Assert
+ // The describe method has a bug: it says "Add" when it should say "Remove".
+ expect(command.describe(), "Add '${character.id}' Perk 0");
+ });
+ });
+}
diff --git a/server/test/command/add_special_loot_card_command_test.dart b/server/test/command/add_special_loot_card_command_test.dart
new file mode 100644
index 0000000..39439b7
--- /dev/null
+++ b/server/test/command/add_special_loot_card_command_test.dart
@@ -0,0 +1,100 @@
+// ignore_for_file: no-magic-number
+
+import 'package:collection/collection.dart';
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_special_loot_card_command.dart';
+import 'package:x_haven_server/core/commands/set_campaign_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ //getIt<GameState>().reset();
+ // A scenario is needed to initialize the loot deck
+ SetCampaignCommand("Frosthaven").execute();
+ SetScenarioCommand(
+ '#0 Howling in the Snow',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ });
+
+ group('AddSpecialLootCardCommand', () {
+ test('should add special loot card 1418', () {
+ // Arrange
+ final command = AddSpecialLootCardCommand(
+ 1418,
+ gameState: getIt<GameState>(),
+ );
+ final lootDeck = getIt<GameState>().lootDeck;
+ final initialCardCount = lootDeck.drawPileSize;
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(lootDeck.drawPileSize, initialCardCount + 1);
+ final card = lootDeck.drawPileContents.firstWhereOrNull(
+ (card) => card.id == 1418,
+ );
+ expect(card?.gfx, 'special 1418');
+ checkSaveState();
+ });
+
+ test('should add special loot card 1419', () {
+ // Arrange
+ final command = AddSpecialLootCardCommand(
+ 1419,
+ gameState: getIt<GameState>(),
+ );
+ final lootDeck = getIt<GameState>().lootDeck;
+ final initialCardCount = lootDeck.drawPileSize;
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(lootDeck.drawPileSize, initialCardCount + 1);
+ final card = lootDeck.drawPileContents.firstWhereOrNull(
+ (card) => card.id == 1419,
+ );
+ expect(card?.gfx, 'special 1419');
+ checkSaveState();
+ });
+
+ test('should not add other cards', () {
+ // Arrange
+ final command = AddSpecialLootCardCommand(
+ 9999,
+ gameState: getIt<GameState>(),
+ );
+ final lootDeck = getIt<GameState>().lootDeck;
+ final initialCardCount = lootDeck.drawPileSize;
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(lootDeck.drawPileSize, initialCardCount);
+ // Since no change is expected, we don't call checkSaveState()
+ });
+
+ test('describe should return correct string', () {
+ // Arrange
+ final command = AddSpecialLootCardCommand(
+ 1418,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Add Special loot card 1418');
+ });
+ });
+}
diff --git a/server/test/command/add_standee_command_test.dart b/server/test/command/add_standee_command_test.dart
new file mode 100644
index 0000000..63b0618
--- /dev/null
+++ b/server/test/command/add_standee_command_test.dart
@@ -0,0 +1,121 @@
+// ignore_for_file: no-magic-number, avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+ late Monster monster;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ AddMonsterCommand(
+ "Ancient Artillery (FH)",
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ });
+
+ group('AddStandeeCommand', () {
+ test('should add a standee to a monster', () {
+ // Arrange
+ final command = AddStandeeCommand(
+ 1,
+ null,
+ monster.id,
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final updatedMonster =
+ getIt<GameState>().currentList.firstWhere((m) => m.id == monster.id)
+ as Monster;
+ expect(updatedMonster.monsterInstances.length, 1);
+ expect(updatedMonster.monsterInstances.first.standeeNr, 1);
+ checkSaveState();
+ });
+
+ test('should add a summon to a character', () {
+ // Arrange
+ final summonData = SummonData(1, 'Test Summon', 10, 2, 2, 0, 'test_gfx');
+ final command = AddStandeeCommand(
+ 1,
+ summonData,
+ character.id,
+ MonsterType.summon,
+ true,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final updatedCharacter =
+ getIt<GameState>().currentList.firstWhere((c) => c.id == character.id)
+ as Character;
+ expect(updatedCharacter.characterState.summonList.length, 1);
+ expect(
+ updatedCharacter.characterState.summonList.first.name,
+ 'Test Summon',
+ );
+ checkSaveState();
+ });
+
+ test('describe should return correct string for a monster standee', () {
+ // Arrange
+ final command = AddStandeeCommand(
+ 1,
+ null,
+ monster.id,
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Add Ancient Artillery (FH) 1');
+ });
+
+ test('describe should return correct string for a summon', () {
+ // Arrange
+ final summonData = SummonData(1, 'Test Summon', 10, 2, 2, 0, 'test_gfx');
+ final command = AddStandeeCommand(
+ 1,
+ summonData,
+ character.id,
+ MonsterType.summon,
+ true,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Add Test Summon 1');
+ });
+ });
+}
diff --git a/server/test/command/amd_add_minus_one_command_test.dart b/server/test/command/amd_add_minus_one_command_test.dart
new file mode 100644
index 0000000..4a354c8
--- /dev/null
+++ b/server/test/command/amd_add_minus_one_command_test.dart
@@ -0,0 +1,116 @@
+// ignore_for_file: avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/amd_add_minus_one_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ });
+
+ group('AmdAddMinusOneCommand', () {
+ test('should add a minus one card to a character deck', () {
+ // Arrange
+ final command = AmdAddMinusOneCommand(
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+ final modifierDeck = character.characterState.modifierDeck;
+ int initialCount = 0;
+ modifierDeck.drawPileContents.toList().forEach((element) {
+ if (element.gfx == 'minus1') {
+ initialCount++;
+ }
+ });
+
+ // Act
+ command.execute();
+
+ // Assert
+ int finalCount = 0;
+ modifierDeck.drawPileContents.toList().forEach((element) {
+ if (element.gfx == 'minus1') {
+ finalCount++;
+ }
+ });
+ expect(finalCount, initialCount + 1);
+ });
+
+ test('should add a minus one card to the monster deck', () {
+ // Arrange
+ final command = AmdAddMinusOneCommand('', gameState: getIt<GameState>());
+ final modifierDeck = getIt<GameState>().modifierDeck;
+ int initialCount = 0;
+ modifierDeck.drawPileContents.toList().forEach((element) {
+ if (element.gfx == 'minus1') {
+ initialCount++;
+ }
+ });
+
+ // Act
+ command.execute();
+
+ // Assert
+ int finalCount = 0;
+ modifierDeck.drawPileContents.toList().forEach((element) {
+ if (element.gfx == 'minus1') {
+ finalCount++;
+ }
+ });
+ expect(finalCount, initialCount + 1);
+ });
+
+ test('should add a minus one card to the allies deck', () {
+ // Arrange
+ final command = AmdAddMinusOneCommand(
+ 'allies',
+ gameState: getIt<GameState>(),
+ );
+ final modifierDeck = getIt<GameState>().modifierDeckAllies;
+ int initialCount = 0;
+ modifierDeck.drawPileContents.toList().forEach((element) {
+ if (element.gfx == 'minus1') {
+ initialCount++;
+ }
+ });
+
+ // Act
+ command.execute();
+
+ // Assert
+ int finalCount = 0;
+ modifierDeck.drawPileContents.toList().forEach((element) {
+ if (element.gfx == 'minus1') {
+ finalCount++;
+ }
+ });
+ expect(finalCount, initialCount + 1);
+ });
+
+ test('describe should return correct string', () {
+ // Arrange
+ final command = AmdAddMinusOneCommand(
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Add minus one');
+ });
+ });
+}
diff --git a/server/test/command/amd_cassandra_special_command_test.dart b/server/test/command/amd_cassandra_special_command_test.dart
new file mode 100644
index 0000000..19fde22
--- /dev/null
+++ b/server/test/command/amd_cassandra_special_command_test.dart
@@ -0,0 +1,63 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/amd_cassandra_special_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ group('AMDCassandraSpecialCommand', () {
+ test('should set cassandraSpecial to true on main deck', () {
+ AMDCassandraSpecialCommand(
+ '',
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().modifierDeck.cassandraSpecial, isTrue);
+ checkSaveState();
+ });
+
+ test('should set cassandraSpecial to false on main deck', () {
+ AMDCassandraSpecialCommand(
+ '',
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AMDCassandraSpecialCommand(
+ '',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().modifierDeck.cassandraSpecial, isFalse);
+ checkSaveState();
+ });
+
+ test('describe when on returns leave-revealed string', () {
+ final command = AMDCassandraSpecialCommand(
+ 'Blinkblade',
+ true,
+ gameState: getIt<GameState>(),
+ );
+ expect(
+ command.describe(),
+ 'Leave revealed cards on top of Blinkblade deck',
+ );
+ });
+
+ test('describe when off returns turned-off string', () {
+ final command = AMDCassandraSpecialCommand(
+ 'Blinkblade',
+ false,
+ gameState: getIt<GameState>(),
+ );
+ expect(
+ command.describe(),
+ 'Cassandra Special turned off for Blinkblade deck',
+ );
+ });
+ });
+}
diff --git a/server/test/command/amd_imbue1_command_test.dart b/server/test/command/amd_imbue1_command_test.dart
new file mode 100644
index 0000000..6d1166e
--- /dev/null
+++ b/server/test/command/amd_imbue1_command_test.dart
@@ -0,0 +1,47 @@
+// ignore_for_file: no-magic-number
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/amd_imbue1_command.dart';
+import 'package:x_haven_server/core/commands/amd_remove_imbue_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ AMDRemoveImbueCommand(gameState: getIt<GameState>()).execute();
+ });
+
+ group('AMDImbue1Command', () {
+ test('should set imbue1 on the monster modifier deck', () {
+ // Arrange
+ final command = AMDImbue1Command(gameState: getIt<GameState>());
+ final monsterDeck = getIt<GameState>().modifierDeck;
+ expect(monsterDeck.imbuement, 0);
+
+ expect(monsterDeck.drawPileSize, 20);
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(monsterDeck.imbuement, 1);
+ expect(monsterDeck.drawPileSize, 22);
+ //todo: check the cards in the deck
+ checkSaveState();
+ });
+
+ test('describe should return correct string', () {
+ // Arrange
+ final command = AMDImbue1Command(gameState: getIt<GameState>());
+
+ // Act & Assert
+ expect(command.describe(), 'Imbue Monster Deck');
+ });
+ });
+}
diff --git a/server/test/command/amd_imbue2_command_test.dart b/server/test/command/amd_imbue2_command_test.dart
new file mode 100644
index 0000000..0e96a35
--- /dev/null
+++ b/server/test/command/amd_imbue2_command_test.dart
@@ -0,0 +1,66 @@
+// ignore_for_file: no-magic-number
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/amd_imbue1_command.dart';
+import 'package:x_haven_server/core/commands/amd_imbue2_command.dart';
+import 'package:x_haven_server/core/commands/amd_remove_imbue_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ AMDRemoveImbueCommand(gameState: getIt<GameState>()).execute();
+ });
+
+ group('AMDImbue2Command', () {
+ test('should set imbue2 on the monster modifier deck', () {
+ // Arrange
+ final command = AMDImbue2Command(gameState: getIt<GameState>());
+ final monsterDeck = getIt<GameState>().modifierDeck;
+ expect(monsterDeck.imbuement, 0);
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(monsterDeck.imbuement, 2);
+ expect(monsterDeck.drawPileSize, 24);
+ //todo: check actual cards
+ checkSaveState();
+ });
+
+ test(
+ 'should set imbue2 on the monster modifier deck after imbue 1 set',
+ () {
+ // Arrange
+ AMDImbue1Command(gameState: getIt<GameState>()).execute();
+ final command = AMDImbue2Command(gameState: getIt<GameState>());
+ final monsterDeck = getIt<GameState>().modifierDeck;
+ expect(monsterDeck.imbuement, 1);
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(monsterDeck.imbuement, 2);
+ expect(monsterDeck.drawPileSize, 24);
+ //todo: check actual cards
+ checkSaveState();
+ },
+ );
+
+ test('describe should return correct string', () {
+ // Arrange
+ final command = AMDImbue2Command(gameState: getIt<GameState>());
+
+ // Act & Assert
+ expect(command.describe(), 'Advanced Imbue Monster Deck');
+ });
+ });
+}
diff --git a/server/test/command/amd_remove_imbue_command_test.dart b/server/test/command/amd_remove_imbue_command_test.dart
new file mode 100644
index 0000000..7af6095
--- /dev/null
+++ b/server/test/command/amd_remove_imbue_command_test.dart
@@ -0,0 +1,105 @@
+// ignore_for_file: no-magic-number, no-empty-block
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_perk_command.dart';
+import 'package:x_haven_server/core/commands/amd_imbue1_command.dart';
+import 'package:x_haven_server/core/commands/amd_imbue2_command.dart';
+import 'package:x_haven_server/core/commands/amd_remove_imbue_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {});
+
+ group('AMDRemoveImbueCommand', () {
+ test('should remove imbuement from the monster modifier deck', () {
+ // Arrange
+ final monsterDeck = getIt<GameState>().modifierDeck;
+ // Add imbuement first to ensure there is something to remove.
+ AMDImbue1Command(gameState: getIt<GameState>()).execute();
+ expect(monsterDeck.imbuement, 1);
+
+ final command = AMDRemoveImbueCommand(gameState: getIt<GameState>());
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(monsterDeck.imbuement, 0);
+ expect(monsterDeck.drawPileSize, 20);
+ checkSaveState();
+ });
+
+ test('should remove imbuement from the monster modifier deck 2', () {
+ // Arrange
+ final monsterDeck = getIt<GameState>().modifierDeck;
+ // Add imbuement first to ensure there is something to remove.
+ AMDImbue2Command(gameState: getIt<GameState>()).execute();
+ expect(monsterDeck.imbuement, 2);
+
+ final command = AMDRemoveImbueCommand(gameState: getIt<GameState>());
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(monsterDeck.imbuement, 0);
+ expect(monsterDeck.drawPileSize, 20);
+ checkSaveState();
+ });
+
+ test('should remove imbuement from the monster modifier deck both', () {
+ // Arrange
+ final monsterDeck = getIt<GameState>().modifierDeck;
+ // Add imbuement first to ensure there is something to remove.
+ AMDImbue1Command(gameState: getIt<GameState>()).execute();
+ AMDImbue2Command(gameState: getIt<GameState>()).execute();
+ expect(monsterDeck.imbuement, 2);
+
+ final command = AMDRemoveImbueCommand(gameState: getIt<GameState>());
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(monsterDeck.imbuement, 0);
+ expect(monsterDeck.drawPileSize, 20);
+ checkSaveState();
+ });
+
+ test('should not remove hail special', () {
+ // Arrange
+ final monsterDeck = getIt<GameState>().modifierDeck;
+ // Add imbuement first to ensure there is something to remove.
+ AddCharacterCommand("Hail", "Mercenary Packs", "Hail", 1).execute();
+ AddPerkCommand("Hail", 17).execute();
+ AMDImbue2Command(gameState: getIt<GameState>()).execute();
+ expect(monsterDeck.imbuement, 2);
+
+ final command = AMDRemoveImbueCommand(gameState: getIt<GameState>());
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(monsterDeck.imbuement, 0);
+ expect(monsterDeck.drawPileSize, 21);
+ checkSaveState();
+ });
+
+ test('describe should return correct string', () {
+ // Arrange
+ final command = AMDRemoveImbueCommand(gameState: getIt<GameState>());
+
+ // Act & Assert
+ expect(command.describe(), 'Remove Imbuement');
+ });
+ });
+}
diff --git a/server/test/command/amd_remove_minus_1_command_test.dart b/server/test/command/amd_remove_minus_1_command_test.dart
new file mode 100644
index 0000000..715dc1d
--- /dev/null
+++ b/server/test/command/amd_remove_minus_1_command_test.dart
@@ -0,0 +1,157 @@
+// ignore_for_file: no-magic-number, avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/amd_add_minus_one_command.dart';
+import 'package:x_haven_server/core/commands/amd_remove_minus_1_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+int _getMinusOnes(ModifierDeck deck) {
+ int count = 0;
+ for (var item in deck.drawPileContents.toList()) {
+ if (item.gfx == "minus1") {
+ count++;
+ }
+ }
+ return count;
+}
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+
+ setUp(() {
+ //getIt<GameState>().reset();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ });
+
+ group('AMDRemoveMinus1Command', () {
+ test('should remove a minus one card from a character deck', () {
+ // Arrange
+ final modifierDeck = character.characterState.modifierDeck;
+ int initialCount = _getMinusOnes(modifierDeck);
+ expect(initialCount, 5);
+
+ final command = AMDRemoveMinus1Command(
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalCount = _getMinusOnes(modifierDeck);
+ expect(finalCount, initialCount - 1);
+ });
+
+ test('should remove a minus one card from a character deck', () {
+ // Arrange
+ final modifierDeck = character.characterState.modifierDeck;
+ AmdAddMinusOneCommand(
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute(); // Add one first
+ int initialCount = _getMinusOnes(modifierDeck);
+ expect(initialCount, 6);
+
+ final command = AMDRemoveMinus1Command(
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalCount = _getMinusOnes(modifierDeck);
+ expect(finalCount, initialCount - 1);
+ });
+
+ test('should remove a minus one card from a character deck', () {
+ // Arrange
+ final modifierDeck = character.characterState.modifierDeck;
+ AmdAddMinusOneCommand(
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute(); // Add one first
+ int initialCount = _getMinusOnes(modifierDeck);
+ expect(initialCount, 6);
+
+ final command = AMDRemoveMinus1Command(
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+ command.execute();
+ command.execute();
+ command.execute();
+ command.execute();
+ command.execute();
+ command.execute();
+ command.execute();
+ command.execute();
+ command.execute();
+
+ // Assert
+ final finalCount = _getMinusOnes(modifierDeck);
+ expect(finalCount, 0);
+ });
+
+ test('should remove a minus one card from the monster deck', () {
+ // Arrange
+ final modifierDeck = getIt<GameState>().modifierDeck;
+ //AmdAddMinusOneCommand('', gameState: getIt<GameState>()).execute(); // Add one first
+ final initialCount = _getMinusOnes(modifierDeck);
+ final command = AMDRemoveMinus1Command('', gameState: getIt<GameState>());
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalCount = _getMinusOnes(modifierDeck);
+ expect(finalCount, initialCount - 1);
+ });
+
+ test('should remove a minus one card from the allies deck', () {
+ // Arrange
+ final modifierDeck = getIt<GameState>().modifierDeckAllies;
+ //AmdAddMinusOneCommand('allies', gameState: getIt<GameState>()).execute(); // Add one first
+ final initialCount = _getMinusOnes(modifierDeck);
+ final command = AMDRemoveMinus1Command(
+ 'allies',
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalCount = _getMinusOnes(modifierDeck);
+ expect(finalCount, initialCount - 1);
+ });
+
+ test('describe should return correct string', () {
+ // Arrange
+ final command = AMDRemoveMinus1Command(
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+ command.execute();
+
+ // Act & Assert
+ expect(command.describe(), 'Remove minus one');
+ });
+ });
+}
diff --git a/server/test/command/amd_remove_minus_2_command_test.dart b/server/test/command/amd_remove_minus_2_command_test.dart
new file mode 100644
index 0000000..49963e9
--- /dev/null
+++ b/server/test/command/amd_remove_minus_2_command_test.dart
@@ -0,0 +1,112 @@
+// ignore_for_file: avoid-non-null-assertion
+
+import 'package:collection/collection.dart';
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/amd_remove_minus_2_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ final command = SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ); //setting scenario resets the decks
+ // Act
+ command.execute();
+ });
+
+ group('AMDRemoveMinus2Command', () {
+ test('should remove a minus two card from the monster deck', () {
+ // Arrange
+ final modifierDeck = getIt<GameState>().modifierDeck;
+ final command = AMDRemoveMinus2Command(
+ false,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ final card = modifierDeck.drawPileContents.toList().firstWhereOrNull((
+ it,
+ ) {
+ return it.gfx == 'minus2';
+ });
+ // Assert
+ expect(card, null);
+ });
+
+ test('should add back a removed minus two card from the monster deck', () {
+ // Arrange
+ final modifierDeck = getIt<GameState>().modifierDeck;
+ final command = AMDRemoveMinus2Command(
+ false,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ final card = modifierDeck.drawPileContents.toList().firstWhereOrNull((
+ it,
+ ) {
+ return it.gfx == 'minus2';
+ });
+ // Assert
+ expect(card, null);
+
+ //add back
+ AMDRemoveMinus2Command(false, gameState: getIt<GameState>()).execute();
+ final card2 = modifierDeck.drawPileContents.toList().firstWhereOrNull((
+ it,
+ ) {
+ return it.gfx == 'minus2';
+ });
+ // Assert
+ expect(card2 == null, false);
+ expect(card2!.gfx, 'minus2');
+ });
+
+ test('should remove a minus two card from the allies deck', () {
+ // Arrange
+ final modifierDeck = getIt<GameState>().modifierDeckAllies;
+ final command = AMDRemoveMinus2Command(
+ true,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ final card = modifierDeck.drawPileContents.toList().firstWhereOrNull((
+ it,
+ ) {
+ return it.gfx == 'minus2';
+ });
+
+ // Assert
+ expect(card, null);
+ });
+
+ test('describe should return correct string', () {
+ // Arrange
+ final command = AMDRemoveMinus2Command(
+ false,
+ gameState: getIt<GameState>(),
+ );
+ command.execute();
+
+ // Act & Assert
+ expect(command.describe(), 'Remove minus two');
+ });
+ });
+}
diff --git a/server/test/command/amd_remove_plus_0_command_test.dart b/server/test/command/amd_remove_plus_0_command_test.dart
new file mode 100644
index 0000000..3cc5360
--- /dev/null
+++ b/server/test/command/amd_remove_plus_0_command_test.dart
@@ -0,0 +1,119 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/amd_remove_plus_0_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ // Setting a scenario resets the modifier decks to their default state.
+ final command = SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ );
+ command.execute();
+ });
+
+ group('AmdRemovePlus0Command', () {
+ test('should remove a plus zero card from the monster deck', () {
+ // Arrange
+ final modifierDeck = getIt<GameState>().modifierDeck;
+ final initialCount = modifierDeck.drawPileContents
+ .toList()
+ .where((c) => c.gfx == 'plus0')
+ .length;
+ final command = AmdRemovePlus0Command(
+ "",
+ true,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalCount = modifierDeck.drawPileContents
+ .toList()
+ .where((c) => c.gfx == 'plus0')
+ .length;
+ expect(finalCount, initialCount - 1);
+ });
+
+ test('should add back a removed plus zero card to the monster deck', () {
+ // Arrange
+ final modifierDeck = getIt<GameState>().modifierDeck;
+ final initialCount = modifierDeck.drawPileContents
+ .toList()
+ .where((c) => c.gfx == 'plus0')
+ .length;
+ final command = AmdRemovePlus0Command(
+ "",
+ true,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute(); // Remove one card
+
+ // Assert
+ final countAfterRemove = modifierDeck.drawPileContents
+ .toList()
+ .where((c) => c.gfx == 'plus0')
+ .length;
+ expect(countAfterRemove, initialCount - 1);
+
+ // Act: Add the card back
+ AmdRemovePlus0Command("", false, gameState: getIt<GameState>()).execute();
+
+ // Assert
+ final countAfterAdd = modifierDeck.drawPileContents
+ .toList()
+ .where((c) => c.gfx == 'plus0')
+ .length;
+ expect(countAfterAdd, initialCount);
+ });
+
+ test('should remove a plus zero card from the allies deck', () {
+ // Arrange
+ final modifierDeck = getIt<GameState>().modifierDeckAllies;
+ final initialCount = modifierDeck.drawPileContents
+ .toList()
+ .where((c) => c.gfx == 'plus0')
+ .length;
+ final command = AmdRemovePlus0Command(
+ "allies",
+ true,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalCount = modifierDeck.drawPileContents
+ .toList()
+ .where((c) => c.gfx == 'plus0')
+ .length;
+ expect(finalCount, initialCount - 1);
+ });
+
+ test('describe should return correct string', () {
+ // Arrange
+ final command = AmdRemovePlus0Command(
+ "",
+ true,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Remove plus zero');
+ });
+ });
+}
diff --git a/server/test/command/amd_reveal_command_test.dart b/server/test/command/amd_reveal_command_test.dart
new file mode 100644
index 0000000..98fdb8d
--- /dev/null
+++ b/server/test/command/amd_reveal_command_test.dart
@@ -0,0 +1,50 @@
+// ignore_for_file: no-magic-number
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/amd_reveal_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ group('AMDRevealCommand', () {
+ test('should set revealedCount on the main modifier deck', () {
+ final command = AMDRevealCommand(
+ amount: 2,
+ name: 'Monsters',
+ gameState: getIt<GameState>(),
+ );
+ command.execute();
+ expect(getIt<GameState>().modifierDeck.revealedCount, 2);
+ checkSaveState();
+ });
+
+ test('should set revealedCount to zero when amount is 0', () {
+ AMDRevealCommand(
+ amount: 3,
+ name: 'Monsters',
+ gameState: getIt<GameState>(),
+ ).execute();
+ AMDRevealCommand(
+ amount: 0,
+ name: 'Monsters',
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().modifierDeck.revealedCount, 0);
+ });
+
+ test('describe should include the amount', () {
+ final command = AMDRevealCommand(
+ amount: 3,
+ name: 'Monsters',
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Reveal 3 modifier cards');
+ });
+ });
+}
diff --git a/server/test/command/bad_omen_command_test.dart b/server/test/command/bad_omen_command_test.dart
new file mode 100644
index 0000000..1741099
--- /dev/null
+++ b/server/test/command/bad_omen_command_test.dart
@@ -0,0 +1,124 @@
+// ignore_for_file: no-magic-number
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/bad_omen_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_curse_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ // Setting a scenario resets the modifier decks to their default state.
+ final command = SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ );
+ command.execute();
+ });
+
+ group('BadOmenCommand', () {
+ test('should increase badOmen value for monster deck', () {
+ // Arrange
+ final command = BadOmenCommand(false, gameState: getIt<GameState>());
+ final monsterDeck = getIt<GameState>().modifierDeck;
+ final initialBadOmenValue = monsterDeck.badOmen;
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(monsterDeck.badOmen, initialBadOmenValue + 6);
+ checkSaveState();
+ });
+
+ test('should increase badOmen value for allies deck', () {
+ // Arrange
+ final command = BadOmenCommand(true, gameState: getIt<GameState>());
+ final alliesDeck = getIt<GameState>().modifierDeckAllies;
+ final initialBadOmenValue = alliesDeck.badOmen;
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(alliesDeck.badOmen, initialBadOmenValue + 6);
+ checkSaveState();
+ });
+
+ test('should add curses on top', () {
+ // Arrange
+ final command = BadOmenCommand(false, gameState: getIt<GameState>());
+ final monsterDeck = getIt<GameState>().modifierDeck;
+ final initialBadOmenValue = monsterDeck.badOmen;
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(monsterDeck.badOmen, initialBadOmenValue + 6);
+
+ ChangeCurseCommand(
+ 1,
+ "Zealot",
+ "Zealot",
+ gameState: getIt<GameState>(),
+ ).execute(); // Add a curse first
+ expect(monsterDeck.drawPileContents.toList()[15].gfx, "curse");
+ expect(monsterDeck.badOmen, initialBadOmenValue + 5);
+
+ ChangeCurseCommand(
+ 1,
+ "Zealot",
+ "Zealot",
+ gameState: getIt<GameState>(),
+ ).execute(); // Add a curse first
+ expect(monsterDeck.drawPileContents.toList()[15].gfx, "curse");
+ expect(monsterDeck.badOmen, initialBadOmenValue + 4);
+
+ ChangeCurseCommand(
+ 1,
+ "Zealot",
+ "Zealot",
+ gameState: getIt<GameState>(),
+ ).execute(); // Add a curse first
+ expect(monsterDeck.drawPileContents.toList()[15].gfx, "curse");
+ expect(monsterDeck.badOmen, initialBadOmenValue + 3);
+
+ ChangeCurseCommand(
+ 1,
+ "Zealot",
+ "Zealot",
+ gameState: getIt<GameState>(),
+ ).execute(); // Add a curse first
+ expect(monsterDeck.drawPileContents.toList()[15].gfx, "curse");
+ expect(monsterDeck.badOmen, initialBadOmenValue + 2);
+
+ ChangeCurseCommand(
+ 1,
+ "Zealot",
+ "Zealot",
+ gameState: getIt<GameState>(),
+ ).execute(); // Add a curse first
+ expect(monsterDeck.drawPileContents.toList()[15].gfx, "curse");
+ expect(monsterDeck.badOmen, initialBadOmenValue + 1);
+
+ checkSaveState();
+ });
+
+ test('describe should return correct string', () {
+ // Arrange
+ final command = BadOmenCommand(false, gameState: getIt<GameState>());
+
+ // Act & Assert
+ expect(command.describe(), 'Bad Omen');
+ });
+ });
+}
diff --git a/server/test/command/change_name_command_test.dart b/server/test/command/change_name_command_test.dart
new file mode 100644
index 0000000..cb5dce4
--- /dev/null
+++ b/server/test/command/change_name_command_test.dart
@@ -0,0 +1,58 @@
+// ignore_for_file: avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/change_name_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+
+ setUp(() {
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "Blinky", 1).execute();
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ });
+
+ group('ChangeNameCommand', () {
+ test('should change a character\'s name', () {
+ // Arrange
+ final newName = 'BlinkyTheBlade';
+ final command = ChangeNameCommand(
+ newName,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+ final initialName = character.characterState.display;
+ expect(initialName, 'Blinky');
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalName = character.characterState.display;
+ expect(finalName, newName);
+ checkSaveState();
+ });
+
+ test('describe should return correct string', () {
+ // Arrange
+ final command = ChangeNameCommand(
+ 'NewName',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Change character name');
+ });
+ });
+}
diff --git a/server/test/command/change_stat_commands/change_bless_command_test.dart b/server/test/command/change_stat_commands/change_bless_command_test.dart
new file mode 100644
index 0000000..9a9059e
--- /dev/null
+++ b/server/test/command/change_stat_commands/change_bless_command_test.dart
@@ -0,0 +1,175 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_bless_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import '../test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ AddMonsterCommand(
+ "Zealot",
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ "Zealot",
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ );
+ });
+
+ group('ChangeBlessCommand', () {
+ test('should add a bless card to a character deck', () {
+ // Arrange
+ final character = getIt<GameState>().currentList.first as Character;
+ final command = ChangeBlessCommand(
+ 1,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+ final initialBlessCount = character.characterState.modifierDeck
+ .getRemovable("bless");
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalBlessCount = character.characterState.modifierDeck
+ .getRemovable("bless");
+ expect(finalBlessCount, initialBlessCount + 1);
+ checkSaveState();
+ });
+
+ test('should remove a bless card from a character deck', () {
+ // Arrange
+ final character = getIt<GameState>().currentList.first as Character;
+ ChangeBlessCommand(
+ 1,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute(); // Add a bless first
+ final initialBlessCount = character.characterState.modifierDeck
+ .getRemovable("bless");
+ final command = ChangeBlessCommand(
+ -1,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalBlessCount = character.characterState.modifierDeck
+ .getRemovable("bless");
+ expect(finalBlessCount, initialBlessCount - 1);
+ checkSaveState();
+ });
+
+ test('should add a bless card to the monster deck', () {
+ // Arrange
+ final gameState = getIt<GameState>();
+ final command = ChangeBlessCommand(
+ 1,
+ "Zealot",
+ "Zealot",
+ gameState: getIt<GameState>(),
+ ); // Empty string for monster deck
+ final initialBlessCount = gameState.modifierDeck.getRemovable("bless");
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalBlessCount = gameState.modifierDeck.getRemovable("bless");
+ expect(finalBlessCount, initialBlessCount + 1);
+ checkSaveState();
+ });
+
+ test('should remove a bless card from the monster deck', () {
+ // Arrange
+ final gameState = getIt<GameState>();
+ ChangeBlessCommand(
+ 1,
+ "Zealot",
+ "Zealot",
+ gameState: getIt<GameState>(),
+ ).execute(); // Add a bless first
+ final initialBlessCount = gameState.modifierDeck.getRemovable("bless");
+ final command = ChangeBlessCommand(
+ -1,
+ "Zealot",
+ "Zealot",
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalBlessCount = gameState.modifierDeck.getRemovable("bless");
+ expect(finalBlessCount, initialBlessCount - 1);
+ checkSaveState();
+ });
+
+ test('describe should return correct string for adding bless', () {
+ // Arrange
+ final command = ChangeBlessCommand(
+ 1,
+ 'Blinkblade',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Add a Bless');
+ checkSaveState();
+ });
+
+ test('describe should return correct string for removing bless', () {
+ // Arrange
+ final command = ChangeBlessCommand(
+ -1,
+ 'Blinkblade',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Remove a Bless');
+ checkSaveState();
+ });
+
+ test('describe should return correct string for monster deck', () {
+ // Arrange
+ final command = ChangeBlessCommand(
+ 1,
+ "Zealot",
+ "Zealot",
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Add a Bless');
+ checkSaveState();
+ });
+ });
+}
diff --git a/server/test/command/change_stat_commands/change_curse_command_test.dart b/server/test/command/change_stat_commands/change_curse_command_test.dart
new file mode 100644
index 0000000..677181a
--- /dev/null
+++ b/server/test/command/change_stat_commands/change_curse_command_test.dart
@@ -0,0 +1,175 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_curse_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import '../test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ AddMonsterCommand(
+ "Zealot",
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ "Zealot",
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ );
+ });
+
+ group('ChangeCurseCommand', () {
+ test('should add a curse card to a character deck', () {
+ // Arrange
+ final character = getIt<GameState>().currentList.first as Character;
+ final command = ChangeCurseCommand(
+ 1,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+ final initialCurseCount = character.characterState.modifierDeck
+ .getRemovable("curse");
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalCurseCount = character.characterState.modifierDeck
+ .getRemovable("curse");
+ expect(finalCurseCount, initialCurseCount + 1);
+ checkSaveState();
+ });
+
+ test('should remove a curse card from a character deck', () {
+ // Arrange
+ final character = getIt<GameState>().currentList.first as Character;
+ ChangeCurseCommand(
+ 1,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute(); // Add a curse first
+ final initialCurseCount = character.characterState.modifierDeck
+ .getRemovable("curse");
+ final command = ChangeCurseCommand(
+ -1,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalCurseCount = character.characterState.modifierDeck
+ .getRemovable("curse");
+ expect(finalCurseCount, initialCurseCount - 1);
+ checkSaveState();
+ });
+
+ test('should add a curse card to the monster deck', () {
+ // Arrange
+ final gameState = getIt<GameState>();
+ final command = ChangeCurseCommand(
+ 1,
+ "Zealot",
+ "Zealot",
+ gameState: getIt<GameState>(),
+ ); // Empty string for monster deck
+ final initialCurseCount = gameState.modifierDeck.getRemovable("curse");
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalCurseCount = gameState.modifierDeck.getRemovable("curse");
+ expect(finalCurseCount, initialCurseCount + 1);
+ checkSaveState();
+ });
+
+ test('should remove a curse card from the monster deck', () {
+ // Arrange
+ final gameState = getIt<GameState>();
+ ChangeCurseCommand(
+ 1,
+ "Zealot",
+ "Zealot",
+ gameState: getIt<GameState>(),
+ ).execute(); // Add a curse first
+ final initialCurseCount = gameState.modifierDeck.getRemovable("curse");
+ final command = ChangeCurseCommand(
+ -1,
+ "Zealot",
+ "Zealot",
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalCurseCount = gameState.modifierDeck.getRemovable("curse");
+ expect(finalCurseCount, initialCurseCount - 1);
+ checkSaveState();
+ });
+
+ test('describe should return correct string for adding curse', () {
+ // Arrange
+ final command = ChangeCurseCommand(
+ 1,
+ 'Blinkblade',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Add a Curse');
+ checkSaveState();
+ });
+
+ test('describe should return correct string for removing curse', () {
+ // Arrange
+ final command = ChangeCurseCommand(
+ -1,
+ 'Blinkblade',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Remove a Curse');
+ checkSaveState();
+ });
+
+ test('describe should return correct string for monster deck', () {
+ // Arrange
+ final command = ChangeCurseCommand(
+ 1,
+ "Zealot",
+ "Zealot",
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Add a Curse');
+ checkSaveState();
+ });
+ });
+}
diff --git a/server/test/command/change_stat_commands/change_empower_command_test.dart b/server/test/command/change_stat_commands/change_empower_command_test.dart
new file mode 100644
index 0000000..53151e3
--- /dev/null
+++ b/server/test/command/change_stat_commands/change_empower_command_test.dart
@@ -0,0 +1,240 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_empower_command.dart';
+import 'package:x_haven_server/core/commands/set_campaign_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import '../test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ AddMonsterCommand(
+ "Zealot",
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ "Zealot",
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ });
+
+ group('ChangeEmpowerCommand', () {
+ test('should add an empowerment to a character', () {
+ // Arrange
+ final character = getIt<GameState>().currentList.first as Character;
+ final command = ChangeEmpowerCommand(
+ 1,
+ "in-empower",
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+ final initialEmpowerCount = character.characterState.modifierDeck
+ .getRemovable("in-empower");
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalEmpowerCount = character.characterState.modifierDeck
+ .getRemovable("in-empower");
+ expect(finalEmpowerCount, initialEmpowerCount + 1);
+ checkSaveState();
+ });
+
+ test('should remove an empowerment from a character', () {
+ // Arrange
+ final character = getIt<GameState>().currentList.first as Character;
+ ChangeEmpowerCommand(
+ 1,
+ "in-empower",
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute(); // Add an empowerment first
+ final initialEmpowerCount = character.characterState.modifierDeck
+ .getRemovable("in-empower");
+ final command = ChangeEmpowerCommand(
+ -1,
+ "in-empower",
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalEmpowerCount = character.characterState.modifierDeck
+ .getRemovable("in-empower");
+ expect(finalEmpowerCount, initialEmpowerCount - 1);
+ checkSaveState();
+ });
+
+ test('should add an empowerment to a monster instance', () {
+ // Arrange
+ final monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ final monsterInstance = monster.monsterInstances.first;
+ final command = ChangeEmpowerCommand(
+ 1,
+ "in-empower",
+ monster.id,
+ monsterInstance.getId(),
+ gameState: getIt<GameState>(),
+ );
+ final initialEmpowerCount = getIt<GameState>().modifierDeck.getRemovable(
+ "in-empower",
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalEmpowerCount = getIt<GameState>().modifierDeck.getRemovable(
+ "in-empower",
+ );
+ expect(finalEmpowerCount, initialEmpowerCount + 1);
+ checkSaveState();
+ });
+
+ test('should remove an empowerment from a monster instance', () {
+ // Arrange
+ final monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ final monsterInstance = monster.monsterInstances.first;
+ ChangeEmpowerCommand(
+ 1,
+ "in-empower",
+ monster.id,
+ monsterInstance.getId(),
+ gameState: getIt<GameState>(),
+ ).execute(); // Add an empowerment first
+ final initialEmpowerCount = getIt<GameState>().modifierDeck.getRemovable(
+ "in-empower",
+ );
+ final command = ChangeEmpowerCommand(
+ -1,
+ "in-empower",
+ monster.id,
+ monsterInstance.getId(),
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ final finalEmpowerCount = getIt<GameState>().modifierDeck.getRemovable(
+ "in-empower",
+ );
+ expect(finalEmpowerCount, initialEmpowerCount - 1);
+ checkSaveState();
+ });
+
+ test('describe should return correct string for adding empowerment', () {
+ // Arrange
+ final command = ChangeEmpowerCommand(
+ 1,
+ "in-empower",
+ 'Blinkblade',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Add Empower');
+ });
+
+ test('describe should return correct string for removing empowerment', () {
+ // Arrange
+ final command = ChangeEmpowerCommand(
+ -1,
+ "in-empower",
+ 'Blinkblade',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Remove Empower');
+ });
+
+ test('undo does not throw', () {
+ final gs = getIt<GameState>();
+ final character = gs.currentList.first as Character;
+ gs.action(
+ ChangeEmpowerCommand(
+ 1,
+ "in-empower",
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ),
+ );
+ expect(() => gs.undo(), returnsNormally);
+ });
+
+ test('.deck() named constructor targets the given deck directly', () {
+ final deck = getIt<GameState>().modifierDeck;
+ final before = deck.getRemovable("in-empower");
+ ChangeEmpowerCommand.deck(
+ deck,
+ "in-empower",
+ gameState: getIt<GameState>(),
+ ).execute();
+ // change defaults to 0 for .deck() constructor, so value unchanged
+ expect(deck.getRemovable("in-empower"), before);
+ });
+
+ test('ally monster owner uses modifierDeckAllies', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ // Rat Monstrosity is marked isAlly in #6
+ final gs = getIt<GameState>();
+ final ratMonstrosity = gs.currentList.whereType<Monster>().firstWhere(
+ (m) => m.id == 'Rat Monstrosity',
+ );
+ expect(ratMonstrosity.isAlly, isTrue);
+
+ final alliesDeckBefore = gs.modifierDeckAllies.getRemovable("in-empower");
+ ChangeEmpowerCommand(
+ 1,
+ "in-empower",
+ ratMonstrosity.id,
+ ratMonstrosity.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(
+ gs.modifierDeckAllies.getRemovable("in-empower"),
+ alliesDeckBefore + 1,
+ );
+ });
+ });
+}
diff --git a/server/test/command/change_stat_commands/change_enfeeble_command_test.dart b/server/test/command/change_stat_commands/change_enfeeble_command_test.dart
new file mode 100644
index 0000000..9b10bed
--- /dev/null
+++ b/server/test/command/change_stat_commands/change_enfeeble_command_test.dart
@@ -0,0 +1,145 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_enfeeble_command.dart';
+import 'package:x_haven_server/core/commands/set_campaign_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import '../test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ });
+
+ group('ChangeEnfeebleCommand', () {
+ test('should add enfeeble to character modifier deck', () {
+ final character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ final initial = character.characterState.modifierDeck.getRemovable(
+ 'enfeeble',
+ );
+
+ ChangeEnfeebleCommand(
+ 1,
+ 'enfeeble',
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(
+ character.characterState.modifierDeck.getRemovable('enfeeble'),
+ initial + 1,
+ );
+ checkSaveState();
+ });
+
+ test('should add enfeeble to monster modifier deck', () {
+ final gameState = getIt<GameState>();
+ final initial = gameState.modifierDeck.getRemovable('enfeeble');
+
+ ChangeEnfeebleCommand(
+ 1,
+ 'enfeeble',
+ 'Ancient Artillery (FH)',
+ 'Ancient Artillery (FH)',
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(gameState.modifierDeck.getRemovable('enfeeble'), initial + 1);
+ });
+
+ test('describe should return "Add Enfeeble" when change is positive', () {
+ final command = ChangeEnfeebleCommand(
+ 1,
+ 'enfeeble',
+ 'Blinkblade',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Add Enfeeble');
+ });
+
+ test(
+ 'describe should return "Remove Enfeeble" when change is negative',
+ () {
+ final command = ChangeEnfeebleCommand(
+ -1,
+ 'enfeeble',
+ 'Blinkblade',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Remove Enfeeble');
+ },
+ );
+
+ test('undo does not throw', () {
+ final gs = getIt<GameState>();
+ final character = gs.currentList.first as Character;
+ gs.action(
+ ChangeEnfeebleCommand(
+ 1,
+ 'enfeeble',
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ),
+ );
+ expect(() => gs.undo(), returnsNormally);
+ });
+
+ test('.deck() named constructor targets the given deck directly', () {
+ final deck = getIt<GameState>().modifierDeck;
+ final before = deck.getRemovable('enfeeble');
+ ChangeEnfeebleCommand.deck(
+ deck,
+ 'enfeeble',
+ gameState: getIt<GameState>(),
+ ).execute();
+ // change defaults to 0 for .deck() constructor, so value unchanged
+ expect(deck.getRemovable('enfeeble'), before);
+ });
+
+ test('ally monster owner uses modifierDeckAllies', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final gs = getIt<GameState>();
+ final ratMonstrosity = gs.currentList.whereType<Monster>().firstWhere(
+ (m) => m.id == 'Rat Monstrosity',
+ );
+ expect(ratMonstrosity.isAlly, isTrue);
+
+ final before = gs.modifierDeckAllies.getRemovable('enfeeble');
+ ChangeEnfeebleCommand(
+ 1,
+ 'enfeeble',
+ ratMonstrosity.id,
+ ratMonstrosity.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(gs.modifierDeckAllies.getRemovable('enfeeble'), before + 1);
+ });
+ });
+}
diff --git a/server/test/command/change_stat_commands/change_health_command_test.dart b/server/test/command/change_stat_commands/change_health_command_test.dart
new file mode 100644
index 0000000..159ad74
--- /dev/null
+++ b/server/test/command/change_stat_commands/change_health_command_test.dart
@@ -0,0 +1,193 @@
+// ignore_for_file: no-magic-number, avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_health_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import '../test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+ late Monster monster;
+ late MonsterInstance monsterInstance;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ AddMonsterCommand(
+ "Zealot",
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ "Zealot",
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ monsterInstance = monster.monsterInstances.first;
+ });
+
+ group('ChangeHealthCommand', () {
+ test('should increase a character\'s health', () {
+ // Arrange
+ final initialHealth = character.characterState.health;
+ final command = ChangeHealthCommand(
+ 5,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(character.characterState.health, initialHealth + 5);
+ });
+
+ test('should decrease a character\'s health', () {
+ // Arrange
+ final initialHealth = character.characterState.health;
+ final command = ChangeHealthCommand(
+ -5,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(character.characterState.health, initialHealth - 5);
+ });
+
+ test('should kill a character when health reaches 0', () {
+ // Arrange
+ final command = ChangeHealthCommand(
+ -100,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(character.characterState.health, 0);
+ // A killed character's turn should be marked as done. this is not true
+ //expect(character.turnState, TurnsState.done);
+ });
+
+ test('should increase a monster instance\'s health', () {
+ // Arrange
+ final initialHealth = monsterInstance.health;
+ final command = ChangeHealthCommand(
+ 3,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(monsterInstance.health, initialHealth + 3);
+ });
+
+ test('should kill a monster instance when health reaches 0', () {
+ // Arrange
+ final command = ChangeHealthCommand(
+ -100,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ );
+ final initialInstanceCount = monster.monsterInstances.length;
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(monster.monsterInstances.length, initialInstanceCount - 1);
+ });
+
+ test('should not decrease health below 0', () {
+ // Arrange
+ final command = ChangeHealthCommand(
+ -100,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(character.characterState.health, 0);
+ });
+
+ test('describe should return correct string for increasing health', () {
+ final command = ChangeHealthCommand(
+ 5,
+ 'Blinkblade',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), "Increase Blinkblade's health by 5");
+ });
+
+ test('describe should return correct string for decreasing health', () {
+ final command = ChangeHealthCommand(
+ -5,
+ 'Blinkblade',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), "Decrease Blinkblade's health by 5");
+ });
+
+ test('describe should return kill string if health is already 0', () {
+ // Arrange
+ //character.characterState.setHealth(StateModifier(), 0);
+ ChangeHealthCommand(
+ -100,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final command = ChangeHealthCommand(
+ -1,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act & Assert
+ expect(command.describe(), 'Kill Blinkblade');
+ });
+ });
+}
diff --git a/server/test/command/change_stat_commands/change_max_health_command_test.dart b/server/test/command/change_stat_commands/change_max_health_command_test.dart
new file mode 100644
index 0000000..a07006d
--- /dev/null
+++ b/server/test/command/change_stat_commands/change_max_health_command_test.dart
@@ -0,0 +1,183 @@
+// ignore_for_file: no-magic-number, avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_max_health_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import '../test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+ late Monster monster;
+ late MonsterInstance monsterInstance;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ AddMonsterCommand(
+ "Zealot",
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ "Zealot",
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ monsterInstance = monster.monsterInstances.first;
+ });
+
+ group('ChangeMaxHealthCommand', () {
+ test('should increase a character\'s max health', () {
+ // Arrange
+ final initialMaxHealth = character.characterState.maxHealth;
+ final command = ChangeMaxHealthCommand(
+ 5,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(character.characterState.maxHealth, initialMaxHealth + 5);
+ });
+
+ test('should decrease a character\'s max health', () {
+ // Arrange
+ final initialMaxHealth = character.characterState.maxHealth;
+ final command = ChangeMaxHealthCommand(
+ -2,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(character.characterState.maxHealth, initialMaxHealth - 2);
+ });
+
+ test('should lower current health if it exceeds new max health', () {
+ // Arrange
+ final initialHealth = character.characterState.health;
+ expect(initialHealth, equals(character.characterState.maxHealth));
+ final command = ChangeMaxHealthCommand(
+ -3,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(
+ character.characterState.health,
+ character.characterState.maxHealth,
+ );
+ });
+
+ test(
+ 'should update current health when max health changes if they were equal',
+ () {
+ // Arrange
+ final command = ChangeMaxHealthCommand(
+ 5,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+ final initialHealth = character.characterState.health;
+ final initialMaxHealth = character.characterState.maxHealth;
+ expect(initialHealth, initialMaxHealth);
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(character.characterState.health, initialHealth + 5);
+ expect(character.characterState.maxHealth, initialMaxHealth + 5);
+ },
+ );
+
+ test('should not set max health to 0 or below', () {
+ // Arrange
+ final initialMaxHealth = character.characterState.maxHealth;
+ final command = ChangeMaxHealthCommand(
+ -100,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(character.characterState.maxHealth, initialMaxHealth);
+ });
+
+ test('should increase a monster instance\'s max health', () {
+ // Arrange
+ final initialMaxHealth = monsterInstance.maxHealth;
+ final command = ChangeMaxHealthCommand(
+ 3,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(monsterInstance.maxHealth, initialMaxHealth + 3);
+ });
+
+ test('describe should return correct string for increasing max health', () {
+ final command = ChangeMaxHealthCommand(
+ 5,
+ 'Blinkblade',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), "Increase Blinkblade's max health");
+ });
+
+ test('describe should return correct string for decreasing max health', () {
+ final command = ChangeMaxHealthCommand(
+ -5,
+ 'Blinkblade',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), "Decrease Blinkblade's max health");
+ });
+ });
+}
diff --git a/server/test/command/change_stat_commands/change_stat_command_test.dart b/server/test/command/change_stat_commands/change_stat_command_test.dart
new file mode 100644
index 0000000..5efba06
--- /dev/null
+++ b/server/test/command/change_stat_commands/change_stat_command_test.dart
@@ -0,0 +1,294 @@
+// ignore_for_file: no-magic-number, avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_health_command.dart';
+import 'package:x_haven_server/core/commands/draw_command.dart';
+import 'package:x_haven_server/core/commands/next_round_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/game_data.dart';
+import 'package:x_haven_server/core/settings.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import '../test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+ late Monster monster;
+ late MonsterInstance monsterInstance;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ 'Ancient Artillery (FH)',
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ monsterInstance = monster.monsterInstances.first;
+ });
+
+ // ChangeStatCommand is abstract; tested through ChangeHealthCommand as a concrete example
+ group('ChangeStatCommand (via ChangeHealthCommand)', () {
+ test('handleDeath removes monster instance when health reaches 0', () {
+ final currentHp = monsterInstance.health;
+ // Deal lethal damage
+ ChangeHealthCommand(
+ -currentHp,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(monster.monsterInstances, isEmpty);
+ });
+
+ test('handleDeath keeps character in list when health reaches 0', () {
+ final currentHp = character.characterState.health;
+ ChangeHealthCommand(
+ -currentHp,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(getIt<GameState>().currentList.contains(character), isTrue);
+ });
+
+ test('describe returns "change stat"', () {
+ // ChangeStatCommand.describe() returns "change stat"
+ final command = ChangeHealthCommand(
+ 1,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ );
+ // ChangeHealthCommand overrides describe, so check base via setChange
+ command.setChange(0);
+ expect(command.describe(), isNotEmpty);
+ });
+
+ test('handleDeath: monster death in playTurns state does not throw', () {
+ // Enter playTurns state
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ expect(getIt<GameState>().roundState, RoundState.playTurns);
+ final currentHp = monsterInstance.health;
+ // Kill the monster standee while in playTurns
+ expect(
+ () => ChangeHealthCommand(
+ -currentHp,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ ).execute(),
+ returnsNormally,
+ );
+ expect(monster.monsterInstances, isEmpty);
+ });
+
+ test(
+ 'handleDeath: character un-death triggers update (health 0 → positive)',
+ () {
+ // Kill the character
+ final maxHp = character.characterState.health;
+ ChangeHealthCommand(
+ -maxHp,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(character.characterState.health, 0);
+ // Revive: going from 0 to positive triggers the un-death path (line 23)
+ expect(
+ () => ChangeHealthCommand(
+ 1,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute(),
+ returnsNormally,
+ );
+ expect(character.characterState.health, 1);
+ },
+ );
+
+ test(
+ 'handleDeath: summon death removes summon from character summonList',
+ () {
+ // Add Banner Spear (has summons in test data)
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Banner Spear', 'Frosthaven', null, 1).execute();
+ final gs = getIt<GameState>();
+ final bannerSpear =
+ gs.currentList.firstWhere((e) => e is Character) as Character;
+
+ // Add a summon with health=1 so it dies on 1 damage
+ final summonData = SummonData(
+ 1,
+ 'BAN reinforcements',
+ 1,
+ 2,
+ 0,
+ 0,
+ 'BAN reinforcements',
+ );
+ AddStandeeCommand(
+ 1,
+ summonData,
+ bannerSpear.id,
+ MonsterType.summon,
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(bannerSpear.characterState.summonList, isNotEmpty);
+ final summonId = bannerSpear.characterState.summonList.first.getId();
+
+ // Kill the summon using its full ID (name+gfx+standeeNr)
+ ChangeHealthCommand(
+ -1,
+ summonId,
+ bannerSpear.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ // Summon should be removed
+ expect(bannerSpear.characterState.summonList, isEmpty);
+ },
+ );
+
+ test('handleDeath: summon death in playTurns state does not throw', () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Banner Spear', 'Frosthaven', null, 1).execute();
+ final gs = getIt<GameState>();
+ final bannerSpear =
+ gs.currentList.firstWhere((e) => e is Character) as Character;
+
+ final summonData = SummonData(
+ 1,
+ 'BAN reinforcements',
+ 1,
+ 2,
+ 0,
+ 0,
+ 'BAN reinforcements',
+ );
+ AddStandeeCommand(
+ 1,
+ summonData,
+ bannerSpear.id,
+ MonsterType.summon,
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final summonId = bannerSpear.characterState.summonList.first.getId();
+
+ // Enter playTurns state
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ expect(gs.roundState, RoundState.playTurns);
+
+ // Kill summon in playTurns
+ expect(
+ () => ChangeHealthCommand(
+ -1,
+ summonId,
+ bannerSpear.id,
+ gameState: getIt<GameState>(),
+ ).execute(),
+ returnsNormally,
+ );
+ expect(bannerSpear.characterState.summonList, isEmpty);
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+ });
+
+ test(
+ 'handleDeath: summon death when more summons remain still updates',
+ () {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Banner Spear', 'Frosthaven', null, 1).execute();
+ final gs = getIt<GameState>();
+ final bannerSpear =
+ gs.currentList.firstWhere((e) => e is Character) as Character;
+
+ // Add two summons with health 1 and 2
+ final summonData1 = SummonData(
+ 1,
+ 'BAN reinforcements',
+ 1,
+ 2,
+ 0,
+ 0,
+ 'BAN reinforcements',
+ );
+ final summonData2 = SummonData(
+ 2,
+ 'BAN banner of strength',
+ 2,
+ 2,
+ 0,
+ 0,
+ 'BAN banner of strength',
+ );
+ AddStandeeCommand(
+ 1,
+ summonData1,
+ bannerSpear.id,
+ MonsterType.summon,
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 2,
+ summonData2,
+ bannerSpear.id,
+ MonsterType.summon,
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(bannerSpear.characterState.summonList.length, 2);
+ // Get the ID of the first summon (health=1) before it's removed
+ final firstSummonId = bannerSpear.characterState.summonList
+ .firstWhere((s) => s.standeeNr == 1)
+ .getId();
+
+ // Kill only the first summon (health 1 → 0)
+ ChangeHealthCommand(
+ -1,
+ firstSummonId,
+ bannerSpear.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ // One summon remains
+ expect(bannerSpear.characterState.summonList.length, 1);
+ },
+ );
+ });
+}
diff --git a/server/test/command/change_stat_commands/change_xp_command_test.dart b/server/test/command/change_stat_commands/change_xp_command_test.dart
new file mode 100644
index 0000000..a782abc
--- /dev/null
+++ b/server/test/command/change_stat_commands/change_xp_command_test.dart
@@ -0,0 +1,103 @@
+// ignore_for_file: no-magic-number, avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_xp_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import '../test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ });
+
+ group('ChangeXPCommand', () {
+ test('should increase a character\'s XP', () {
+ // Arrange
+ final initialXp = character.characterState.xp;
+ final command = ChangeXPCommand(
+ 10,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(character.characterState.xp, initialXp + 10);
+ });
+
+ test('should decrease a character\'s XP', () {
+ // Arrange
+ ChangeXPCommand(
+ 20,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final initialXp = character.characterState.xp;
+ final command = ChangeXPCommand(
+ -5,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(character.characterState.xp, initialXp - 5);
+ });
+
+ test('should not decrease XP below 0', () {
+ // Arrange
+ final command = ChangeXPCommand(
+ -100,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(character.characterState.xp, 0);
+ });
+
+ test('describe should return correct string for increasing XP', () {
+ final command = ChangeXPCommand(
+ 10,
+ 'Blinkblade',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), "Increase Blinkblade's xp by 10");
+ });
+
+ test('describe should return correct string for decreasing XP', () {
+ final command = ChangeXPCommand(
+ -5,
+ 'Blinkblade',
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), "Decrease Blinkblade's xp by 5");
+ });
+ });
+}
diff --git a/server/test/command/clear_unlocked_classes_command_test.dart b/server/test/command/clear_unlocked_classes_command_test.dart
new file mode 100644
index 0000000..fcb47a5
--- /dev/null
+++ b/server/test/command/clear_unlocked_classes_command_test.dart
@@ -0,0 +1,52 @@
+// ignore_for_file: no-empty-block
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/clear_unlocked_classes_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {});
+
+ group('ClearUnlockedClassesCommand', () {
+ test('should clear unlocked classes', () {
+ // Arrange
+ AddCharacterCommand(
+ "Banner Spear",
+ "Frosthaven",
+ "Banny",
+ 1,
+ ).execute(); //test data BS is hidden class
+
+ final gameState = getIt<GameState>();
+ expect(
+ gameState.unlockedClasses,
+ isNotEmpty,
+ reason: "Prerequisite: A class should be unlocked.",
+ );
+
+ final command = ClearUnlockedClassesCommand();
+
+ // Act
+ command.execute();
+
+ // Assert
+ expect(gameState.unlockedClasses, isEmpty);
+ });
+
+ test('describe should return correct string', () {
+ // Arrange
+ final command = ClearUnlockedClassesCommand();
+
+ // Act & Assert
+ expect(command.describe(), 'Clear unlocked classes');
+ });
+ });
+}
diff --git a/server/test/command/command_registry_test.dart b/server/test/command/command_registry_test.dart
new file mode 100644
index 0000000..25f4d10
--- /dev/null
+++ b/server/test/command/command_registry_test.dart
@@ -0,0 +1,144 @@
+// ignore_for_file: avoid-top-level-members-in-tests
+
+import 'package:test/test.dart';
+
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_condition_command.dart';
+import 'package:x_haven_server/core/commands/command_registry.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+
+import 'test_helpers.dart';
+
+void _tests() {
+ group('command registry', () {
+ test('unknown name throws CommandRegistryError', () {
+ expect(
+ () => buildCommand('noSuchCommand', const {}, gameState),
+ throwsA(
+ isA<CommandRegistryError>().having(
+ (e) => e.message,
+ 'message',
+ contains('noSuchCommand'),
+ ),
+ ),
+ );
+ });
+
+ test('addCharacter builds and executes', () {
+ final command = buildCommand('addCharacter', {
+ 'id': 'Blinkblade',
+ 'edition': 'Frosthaven',
+ 'display': '',
+ 'level': 1,
+ }, gameState);
+ expect(command, isA<AddCharacterCommand>());
+ expect(commandName(command), 'addCharacter');
+ command.execute();
+ expect(gameState.currentList.length, 1);
+ expect(gameState.currentList.single, isA<Character>());
+ });
+
+ test('command constructor failure is wrapped as CommandRegistryError', () {
+ expect(
+ () => buildCommand('addCharacter', {
+ 'id': 'NotACharacter',
+ 'edition': 'Frosthaven',
+ 'display': '',
+ 'level': 1,
+ }, gameState),
+ throwsA(
+ isA<CommandRegistryError>().having(
+ (e) => e.message,
+ 'message',
+ contains('NotACharacter'),
+ ),
+ ),
+ );
+ });
+
+ test('missing required arg throws with the arg name in the message', () {
+ expect(
+ () => buildCommand('addCondition', {'condition': 'chill'}, gameState),
+ throwsA(
+ isA<CommandRegistryError>().having(
+ (e) => e.message,
+ 'message',
+ contains('figureId'),
+ ),
+ ),
+ );
+ });
+
+ test('wrong arg type throws', () {
+ expect(
+ () => buildCommand('setInit', {
+ 'characterId': 'Blinkblade',
+ 'init': '3',
+ }, gameState),
+ throwsA(
+ isA<CommandRegistryError>().having(
+ (e) => e.message,
+ 'message',
+ contains('init'),
+ ),
+ ),
+ );
+ });
+
+ test('enum args are resolved by name', () {
+ final command = buildCommand('addCondition', {
+ 'condition': 'chill',
+ 'figureId': 'Blinkblade',
+ }, gameState);
+ expect(command, isA<AddConditionCommand>());
+ expect((command as AddConditionCommand).condition, Condition.chill);
+ expect(commandName(command), 'addCondition');
+ });
+
+ test('bogus enum value throws', () {
+ expect(
+ () => buildCommand('addCondition', {
+ 'condition': 'notACondition',
+ 'figureId': 'Blinkblade',
+ }, gameState),
+ throwsA(
+ isA<CommandRegistryError>().having(
+ (e) => e.message,
+ 'message',
+ contains('notACondition'),
+ ),
+ ),
+ );
+ });
+
+ test('commandName round-trips for other commands', () {
+ final built = <MapEntry<String, Command>>[
+ MapEntry('draw', buildCommand('draw', const {}, gameState)),
+ MapEntry(
+ 'drawLootCard',
+ buildCommand('drawLootCard', const {}, gameState),
+ ),
+ MapEntry(
+ 'changeHealth',
+ buildCommand('changeHealth', {
+ 'change': -1,
+ 'figureId': 'Blinkblade',
+ }, gameState),
+ ),
+ MapEntry(
+ 'useElement',
+ buildCommand('useElement', {'element': 'fire'}, gameState),
+ ),
+ ];
+ for (final entry in built) {
+ expect(commandName(entry.value), entry.key);
+ }
+ });
+ });
+}
+
+Future<void> main() async {
+ await setUpGame();
+ _tests();
+}
diff --git a/server/test/command/corrosive_spew_command_test.dart b/server/test/command/corrosive_spew_command_test.dart
new file mode 100644
index 0000000..d47acf8
--- /dev/null
+++ b/server/test/command/corrosive_spew_command_test.dart
@@ -0,0 +1,31 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/corrosive_spew_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ group('CorrosiveSpewCommand', () {
+ test('should set corrosiveSpew to true on main modifier deck', () {
+ // CorrosiveSpew targets "Ruinmaw" which falls through to the main deck
+ expect(getIt<GameState>().modifierDeck.corrosiveSpew, isFalse);
+
+ CorrosiveSpewCommand(gameState: getIt<GameState>()).execute();
+
+ expect(getIt<GameState>().modifierDeck.corrosiveSpew, isTrue);
+ checkSaveState();
+ });
+
+ test('describe returns correct string', () {
+ expect(
+ CorrosiveSpewCommand(gameState: getIt<GameState>()).describe(),
+ 'Corrosive Spew',
+ );
+ });
+ });
+}
diff --git a/server/test/command/donate_cs_sanctuary_command_test.dart b/server/test/command/donate_cs_sanctuary_command_test.dart
new file mode 100644
index 0000000..c23357e
--- /dev/null
+++ b/server/test/command/donate_cs_sanctuary_command_test.dart
@@ -0,0 +1,77 @@
+// ignore_for_file: avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/donate_cs_sanctuary_command.dart';
+import 'package:x_haven_server/core/commands/remove_cs_sanctuary_donation_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ });
+
+ group('DonateCSSanctuaryCommand', () {
+ test('should add sanctuary cards to character modifier deck', () {
+ final deck = character.characterState.modifierDeck;
+ final countBefore = deck.drawPileSize;
+
+ DonateCSSanctuaryCommand(
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(deck.hasCSSanctuary(), isTrue);
+ expect(deck.drawPileSize, greaterThan(countBefore));
+ checkSaveState();
+ });
+
+ test('describe includes character id', () {
+ final command = DonateCSSanctuaryCommand(
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), '${character.id} donate to sanctuary');
+ });
+ });
+
+ group('RemoveCSSanctuaryDonationCommand', () {
+ test('should remove sanctuary cards from character modifier deck', () {
+ DonateCSSanctuaryCommand(
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final deck = character.characterState.modifierDeck;
+ expect(deck.hasCSSanctuary(), isTrue);
+
+ RemoveCSSanctuaryDonationCommand(
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(deck.hasCSSanctuary(), isFalse);
+ checkSaveState();
+ });
+
+ test('describe includes character id', () {
+ final command = RemoveCSSanctuaryDonationCommand(
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), "Remove ${character.id}'s donation");
+ });
+ });
+}
diff --git a/server/test/command/draw_ability_card_command_test.dart b/server/test/command/draw_ability_card_command_test.dart
new file mode 100644
index 0000000..4c73d08
--- /dev/null
+++ b/server/test/command/draw_ability_card_command_test.dart
@@ -0,0 +1,51 @@
+// ignore_for_file: avoid-non-null-assertion
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/draw_ability_card_command.dart';
+import 'package:x_haven_server/core/game_methods.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ });
+
+ group('DrawAbilityCardCommand', () {
+ test('should move a card from draw pile to discard pile', () {
+ final monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ final deck = GameMethods.getDeck(monster.type.deck)!;
+ final drawBefore = deck.drawPileSize;
+ final discardBefore = deck.discardPileSize;
+
+ DrawAbilityCardCommand(monster.id).execute();
+
+ expect(deck.drawPileSize, drawBefore - 1);
+ expect(deck.discardPileSize, discardBefore + 1);
+ checkSaveState();
+ });
+
+ test('describe returns correct string', () {
+ final monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ final command = DrawAbilityCardCommand(monster.id);
+ expect(command.describe(), 'Draw extra ability card');
+ });
+ });
+}
diff --git a/server/test/command/draw_command_test.dart b/server/test/command/draw_command_test.dart
new file mode 100644
index 0000000..2e14e71
--- /dev/null
+++ b/server/test/command/draw_command_test.dart
@@ -0,0 +1,46 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/draw_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'Blinky', 1).execute();
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ });
+
+ group('DrawCommand', () {
+ test('should set round state to playTurns', () {
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ expect(getIt<GameState>().roundState, RoundState.playTurns);
+ checkSaveState();
+ });
+
+ test('should set first list item turn state to current', () {
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ expect(
+ getIt<GameState>().currentList.first.turnState,
+ TurnsState.current,
+ );
+ });
+
+ test('describe returns "Draw"', () {
+ expect(DrawCommand(gameState: getIt<GameState>()).describe(), 'Draw');
+ });
+ });
+}
diff --git a/server/test/command/draw_loot_card_command_test.dart b/server/test/command/draw_loot_card_command_test.dart
new file mode 100644
index 0000000..80abe4c
--- /dev/null
+++ b/server/test/command/draw_loot_card_command_test.dart
@@ -0,0 +1,87 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/draw_loot_card_command.dart';
+import 'package:x_haven_server/core/commands/return_loot_card_command.dart';
+import 'package:x_haven_server/core/commands/set_campaign_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ // Frosthaven custom scenario creates a loot deck
+ SetCampaignCommand('Frosthaven').execute();
+ SetScenarioCommand(
+ 'custom',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ });
+
+ group('DrawLootCardCommand', () {
+ test('should move a card from draw pile to discard pile', () {
+ final lootDeck = getIt<GameState>().lootDeck;
+ expect(
+ lootDeck.drawPileIsNotEmpty,
+ isTrue,
+ reason: 'Frosthaven custom scenario should have a loot deck',
+ );
+ final drawBefore = lootDeck.drawPileSize;
+ final discardBefore = lootDeck.discardPileSize;
+
+ DrawLootCardCommand(gameState: getIt<GameState>()).execute();
+
+ expect(lootDeck.drawPileSize, drawBefore - 1);
+ expect(lootDeck.discardPileSize, discardBefore + 1);
+ checkSaveState();
+ });
+
+ test('should do nothing when draw pile is empty', () {
+ final lootDeck = getIt<GameState>().lootDeck;
+ final totalCards = lootDeck.drawPileSize + lootDeck.discardPileSize;
+ // Drain draw pile
+ while (lootDeck.drawPileIsNotEmpty) {
+ DrawLootCardCommand(gameState: getIt<GameState>()).execute();
+ }
+ DrawLootCardCommand(
+ gameState: getIt<GameState>(),
+ ).execute(); // should not throw
+ expect(lootDeck.drawPileSize + lootDeck.discardPileSize, totalCards);
+ });
+
+ test('describe returns correct string', () {
+ expect(
+ DrawLootCardCommand(gameState: getIt<GameState>()).describe(),
+ 'Draw loot card',
+ );
+ });
+ });
+
+ group('ReturnLootCardCommand', () {
+ test('should return discard card to top of draw pile', () {
+ DrawLootCardCommand(gameState: getIt<GameState>()).execute();
+ final lootDeck = getIt<GameState>().lootDeck;
+ final drawBefore = lootDeck.drawPileSize;
+ final discardBefore = lootDeck.discardPileSize;
+
+ ReturnLootCardCommand(true, gameState: getIt<GameState>()).execute();
+
+ expect(lootDeck.drawPileSize, drawBefore + 1);
+ expect(lootDeck.discardPileSize, discardBefore - 1);
+ checkSaveState();
+ });
+
+ test('describe returns correct string', () {
+ expect(
+ ReturnLootCardCommand(true, gameState: getIt<GameState>()).describe(),
+ 'Return loot card',
+ );
+ });
+ });
+}
diff --git a/server/test/command/draw_modifier_card_command_test.dart b/server/test/command/draw_modifier_card_command_test.dart
new file mode 100644
index 0000000..ebb4bd7
--- /dev/null
+++ b/server/test/command/draw_modifier_card_command_test.dart
@@ -0,0 +1,42 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/draw_modifier_card_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ group('DrawModifierCardCommand', () {
+ test('should move a card from draw pile to discard pile', () {
+ final deck = getIt<GameState>().modifierDeck;
+ final drawBefore = deck.drawPileSize;
+ final discardBefore = deck.discardPileSize;
+
+ DrawModifierCardCommand('', gameState: getIt<GameState>()).execute();
+
+ expect(deck.drawPileSize, drawBefore - 1);
+ expect(deck.discardPileSize, discardBefore + 1);
+ checkSaveState();
+ });
+
+ test('describe with empty name returns monster string', () {
+ final command = DrawModifierCardCommand(
+ '',
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Draw monster modifier card');
+ });
+
+ test('describe with non-empty name includes name', () {
+ final command = DrawModifierCardCommand(
+ 'Blinkblade',
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Draw Blinkblade modifier card');
+ });
+ });
+}
diff --git a/server/test/command/enhance_loot_card_command_test.dart b/server/test/command/enhance_loot_card_command_test.dart
new file mode 100644
index 0000000..73ebc3b
--- /dev/null
+++ b/server/test/command/enhance_loot_card_command_test.dart
@@ -0,0 +1,82 @@
+// ignore_for_file: no-magic-number
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/enhance_loot_card_command.dart';
+import 'package:x_haven_server/core/commands/set_campaign_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ SetCampaignCommand('Frosthaven').execute();
+ SetScenarioCommand(
+ '#0 Howling in the Snow',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ });
+
+ group('EnhanceLootCardCommand', () {
+ test('should add an enhancement to a loot card', () {
+ final lootDeck = getIt<GameState>().lootDeck;
+ // Get any existing card id from the draw pile
+ if (lootDeck.drawPileIsNotEmpty) {
+ final cardId = lootDeck.drawPileContents.toList().first.id;
+
+ EnhanceLootCardCommand(
+ cardId,
+ 2,
+ 'coin',
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ // After enhancement the deck is rebuilt; verify it doesn't crash
+ expect(lootDeck.drawPileIsNotEmpty, isTrue);
+ checkSaveState();
+ }
+ });
+
+ test('describe returns "Add Loot Enhancement" when value is positive', () {
+ expect(
+ EnhanceLootCardCommand(
+ 1,
+ 1,
+ 'coin',
+ gameState: getIt<GameState>(),
+ ).describe(),
+ 'Add Loot Enhancement',
+ );
+ });
+
+ test(
+ 'describe returns "Remove Loot Enhancement" when value is zero or negative',
+ () {
+ expect(
+ EnhanceLootCardCommand(
+ 1,
+ 0,
+ 'coin',
+ gameState: getIt<GameState>(),
+ ).describe(),
+ 'Remove Loot Enhancement',
+ );
+ expect(
+ EnhanceLootCardCommand(
+ 1,
+ -1,
+ 'coin',
+ gameState: getIt<GameState>(),
+ ).describe(),
+ 'Remove Loot Enhancement',
+ );
+ },
+ );
+ });
+}
diff --git a/server/test/command/ice_wraith_change_form_command_test.dart b/server/test/command/ice_wraith_change_form_command_test.dart
new file mode 100644
index 0000000..bbdc31f
--- /dev/null
+++ b/server/test/command/ice_wraith_change_form_command_test.dart
@@ -0,0 +1,97 @@
+// ignore_for_file: avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/commands/ice_wraith_change_form_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Monster monster;
+ late MonsterInstance monsterInstance;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ 'Ancient Artillery (FH)',
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ monsterInstance = monster.monsterInstances.first;
+ });
+
+ group('IceWraithChangeFormCommand', () {
+ test('should change type to elite when isElite is false', () {
+ expect(monsterInstance.type, MonsterType.normal);
+
+ IceWraithChangeFormCommand(
+ false,
+ monster.id,
+ monsterInstance.getId(),
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(monsterInstance.type, MonsterType.elite);
+ });
+
+ test('should change type to normal when isElite is true', () {
+ // First set to elite
+ IceWraithChangeFormCommand(
+ false,
+ monster.id,
+ monsterInstance.getId(),
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(monsterInstance.type, MonsterType.elite);
+
+ IceWraithChangeFormCommand(
+ true,
+ monster.id,
+ monsterInstance.getId(),
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(monsterInstance.type, MonsterType.normal);
+ });
+
+ test('describe when isElite is false returns turn-normal string', () {
+ final command = IceWraithChangeFormCommand(
+ false,
+ monster.id,
+ monsterInstance.getId(),
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Ice Wraith turn normal');
+ });
+
+ test('describe when isElite is true returns turn-elite string', () {
+ final command = IceWraithChangeFormCommand(
+ true,
+ monster.id,
+ monsterInstance.getId(),
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Ice Wraith turn elite');
+ });
+ });
+}
diff --git a/server/test/command/imbue_element_command_test.dart b/server/test/command/imbue_element_command_test.dart
new file mode 100644
index 0000000..564e0c6
--- /dev/null
+++ b/server/test/command/imbue_element_command_test.dart
@@ -0,0 +1,44 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/imbue_element_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ group('ImbueElementCommand', () {
+ test('should set element to full when half is false', () {
+ final command = ImbueElementCommand(Elements.fire, false);
+ command.execute();
+ expect(getIt<GameState>().elementState[Elements.fire], ElementState.full);
+ checkSaveState();
+ });
+
+ test('should set element to half when half is true', () {
+ final command = ImbueElementCommand(Elements.light, true);
+ command.execute();
+ expect(
+ getIt<GameState>().elementState[Elements.light],
+ ElementState.half,
+ );
+ checkSaveState();
+ });
+
+ test('should work on all element types', () {
+ for (final element in Elements.values) {
+ ImbueElementCommand(element, false).execute();
+ expect(getIt<GameState>().elementState[element], ElementState.full);
+ }
+ });
+
+ test('describe should include element name', () {
+ final command = ImbueElementCommand(Elements.dark, false);
+ expect(command.describe(), 'Imbue element dark');
+ });
+ });
+}
diff --git a/server/test/command/load_save_command_test.dart b/server/test/command/load_save_command_test.dart
new file mode 100644
index 0000000..2715913
--- /dev/null
+++ b/server/test/command/load_save_command_test.dart
@@ -0,0 +1,96 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/load_character_save_command.dart';
+import 'package:x_haven_server/core/commands/load_save_command.dart';
+import 'package:x_haven_server/core/commands/set_campaign_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ group('LoadSaveCommand', () {
+ test('should restore game state from serialized data', () {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'SaveTest', 1).execute();
+ final savedData = getIt<GameState>().toString();
+
+ // Change state
+ getIt<GameState>().clearList();
+
+ // Restore
+ LoadSaveCommand(
+ 'test save',
+ savedData,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(getIt<GameState>().currentList.whereType<Character>().length, 1);
+ expect(
+ getIt<GameState>().currentList
+ .whereType<Character>()
+ .first
+ .characterState
+ .display,
+ 'SaveTest',
+ );
+ });
+
+ test('describe includes save name', () {
+ final command = LoadSaveCommand(
+ 'my save',
+ '{}',
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Load saved game: my save');
+ });
+ });
+
+ group('LoadCharacterSaveCommand', () {
+ test('should load a character from serialized character data', () {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Frosthaven').execute();
+ SetScenarioCommand(
+ 'custom',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'OrigName', 1).execute();
+ final character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ final charData = character.toSave();
+
+ // Remove the character
+ getIt<GameState>().clearList();
+
+ // Reload from save data
+ LoadCharacterSaveCommand(
+ 'Blinkblade',
+ charData,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ final loaded =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ expect(loaded.id, 'Blinkblade');
+ expect(loaded.characterState.display, 'OrigName');
+ });
+
+ test('describe includes save name', () {
+ final command = LoadCharacterSaveCommand(
+ 'Blinkblade',
+ '{}',
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Load saved character: Blinkblade');
+ });
+ });
+}
diff --git a/server/test/command/mutable_game_methods_test.dart b/server/test/command/mutable_game_methods_test.dart
new file mode 100644
index 0000000..cf678c2
--- /dev/null
+++ b/server/test/command/mutable_game_methods_test.dart
@@ -0,0 +1,1488 @@
+// ignore_for_file: avoid-late-keyword, no-magic-number
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_condition_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_perk_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_health_command.dart';
+import 'package:x_haven_server/core/commands/draw_ability_card_command.dart';
+import 'package:x_haven_server/core/commands/draw_command.dart';
+import 'package:x_haven_server/core/commands/imbue_element_command.dart';
+import 'package:x_haven_server/core/commands/next_round_command.dart';
+import 'package:x_haven_server/core/commands/set_campaign_command.dart';
+import 'package:x_haven_server/core/commands/set_character_level_command.dart';
+import 'package:x_haven_server/core/commands/set_init_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/commands/turn_done_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/game_data.dart';
+import 'package:x_haven_server/core/settings.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ // ---------------------------------------------------------------------------
+ // sortByInitiative (called by DrawCommand)
+ // ---------------------------------------------------------------------------
+ group('sortByInitiative via DrawCommand', () {
+ setUp(() {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Frosthaven').execute();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'BB', 1).execute();
+ AddCharacterCommand('Banner Spear', 'Frosthaven', 'BS', 1).execute();
+ });
+
+ test(
+ 'character with lower initiative is placed before character with higher initiative',
+ () {
+ SetInitCommand(
+ 'Blinkblade',
+ 10,
+ gameState: getIt<GameState>(),
+ ).execute();
+ SetInitCommand(
+ 'Banner Spear',
+ 30,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ DrawCommand(gameState: getIt<GameState>()).execute();
+
+ final list = getIt<GameState>().currentList;
+ final bbIdx = list.indexWhere((e) => e.id == 'Blinkblade');
+ final bsIdx = list.indexWhere((e) => e.id == 'Banner Spear');
+ expect(
+ bbIdx,
+ lessThan(bsIdx),
+ reason:
+ 'Blinkblade (init 10) should come before Banner Spear (init 30)',
+ );
+ },
+ );
+
+ test(
+ 'character with higher initiative is placed after character with lower initiative',
+ () {
+ SetInitCommand(
+ 'Blinkblade',
+ 40,
+ gameState: getIt<GameState>(),
+ ).execute();
+ SetInitCommand(
+ 'Banner Spear',
+ 15,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ DrawCommand(gameState: getIt<GameState>()).execute();
+
+ final list = getIt<GameState>().currentList;
+ final bbIdx = list.indexWhere((e) => e.id == 'Blinkblade');
+ final bsIdx = list.indexWhere((e) => e.id == 'Banner Spear');
+ expect(
+ bsIdx,
+ lessThan(bbIdx),
+ reason:
+ 'Banner Spear (init 15) should come before Blinkblade (init 40)',
+ );
+ },
+ );
+
+ test(
+ 'dead character (health=0) is sorted after alive character even with lower initiative',
+ () {
+ final gs = getIt<GameState>();
+ final bs =
+ gs.currentList.firstWhere(
+ (e) => e is Character && e.id == 'Banner Spear',
+ )
+ as Character;
+ ChangeHealthCommand(
+ -bs.characterState.health,
+ bs.id,
+ bs.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(bs.characterState.health, 0);
+
+ // Banner Spear has lower initiative but is dead
+ SetInitCommand(
+ 'Blinkblade',
+ 30,
+ gameState: getIt<GameState>(),
+ ).execute();
+ SetInitCommand(
+ 'Banner Spear',
+ 5,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ DrawCommand(gameState: getIt<GameState>()).execute();
+
+ final list = gs.currentList;
+ final bbIdx = list.indexWhere((e) => e.id == 'Blinkblade');
+ final bsIdx = list.indexWhere((e) => e.id == 'Banner Spear');
+ expect(
+ bbIdx,
+ lessThan(bsIdx),
+ reason:
+ 'Dead Banner Spear should be last even with initiative 5 vs 30',
+ );
+ },
+ );
+
+ test('inactive monster sorted after active character', () {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Frosthaven').execute();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'BB', 1).execute();
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ SetInitCommand('Blinkblade', 50, gameState: getIt<GameState>()).execute();
+
+ DrawCommand(gameState: getIt<GameState>()).execute();
+
+ final list = getIt<GameState>().currentList;
+ final charIdx = list.indexWhere((e) => e is Character);
+ final monsterIdx = list.indexWhere((e) => e is Monster);
+ expect(
+ charIdx,
+ lessThan(monsterIdx),
+ reason: 'Character should come before inactive monster',
+ );
+ });
+
+ test(
+ 'active monster sorted by drawn ability card initiative relative to character',
+ () {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'BB', 1).execute();
+
+ final zealot =
+ getIt<GameState>().currentList.firstWhere(
+ (e) => e is Monster && e.id == 'Zealot',
+ )
+ as Monster;
+ AddStandeeCommand(
+ 1,
+ null,
+ zealot.id,
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ // Character initiative very high so Zealot should normally come first
+ SetInitCommand(
+ 'Blinkblade',
+ 99,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ DrawCommand(gameState: getIt<GameState>()).execute();
+
+ final zealotDeck = getIt<GameState>().currentAbilityDecks.firstWhere(
+ (d) => d.name == zealot.type.deck,
+ );
+ final zealotInit = zealotDeck.discardPileTop.initiative;
+
+ final list = getIt<GameState>().currentList;
+ final zealotIdx = list.indexWhere((e) => e.id == 'Zealot');
+ final charIdx = list.indexWhere(
+ (e) => e is Character && e.id == 'Blinkblade',
+ );
+
+ if (zealotInit < 99) {
+ expect(
+ zealotIdx,
+ lessThan(charIdx),
+ reason:
+ 'Zealot (init $zealotInit) should precede Blinkblade (init 99)',
+ );
+ } else {
+ expect(
+ charIdx,
+ lessThan(zealotIdx),
+ reason:
+ 'Blinkblade (init 99) should precede Zealot (init $zealotInit)',
+ );
+ }
+ },
+ );
+ });
+
+ // ---------------------------------------------------------------------------
+ // sortMonsterInstances (called during AddStandeeCommand)
+ // ---------------------------------------------------------------------------
+ group('sortMonsterInstances', () {
+ late Monster monster;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Frosthaven').execute();
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ });
+
+ test('elite standee is sorted before normal standee', () {
+ AddStandeeCommand(
+ 2,
+ null,
+ monster.id,
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ monster.id,
+ MonsterType.elite,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ final instances = monster.monsterInstances;
+ expect(
+ instances[0].type,
+ MonsterType.elite,
+ reason: 'Elite should be first in the instance list',
+ );
+ expect(
+ instances[1].type,
+ MonsterType.normal,
+ reason: 'Normal should be second',
+ );
+ });
+
+ test('normal standees are sorted by standee number ascending', () {
+ AddStandeeCommand(
+ 3,
+ null,
+ monster.id,
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ monster.id,
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ final instances = monster.monsterInstances;
+ expect(
+ instances[0].standeeNr,
+ 1,
+ reason: 'Lower standee number should come first',
+ );
+ expect(instances[1].standeeNr, 3);
+ });
+
+ test('elite standees are sorted by standee number ascending', () {
+ AddStandeeCommand(
+ 3,
+ null,
+ monster.id,
+ MonsterType.elite,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ monster.id,
+ MonsterType.elite,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ final instances = monster.monsterInstances;
+ expect(instances[0].standeeNr, 1);
+ expect(instances[1].standeeNr, 3);
+ });
+
+ test('mixed: elites by nr come before normals by nr', () {
+ AddStandeeCommand(
+ 2,
+ null,
+ monster.id,
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 3,
+ null,
+ monster.id,
+ MonsterType.elite,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ monster.id,
+ MonsterType.elite,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 4,
+ null,
+ monster.id,
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ final instances = monster.monsterInstances;
+ expect(instances[0].type, MonsterType.elite);
+ expect(instances[0].standeeNr, 1);
+ expect(instances[1].type, MonsterType.elite);
+ expect(instances[1].standeeNr, 3);
+ expect(instances[2].type, MonsterType.normal);
+ expect(instances[2].standeeNr, 2);
+ expect(instances[3].type, MonsterType.normal);
+ expect(instances[3].standeeNr, 4);
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // sortCharactersFirst (called by NextRoundCommand and SetScenarioCommand)
+ // ---------------------------------------------------------------------------
+ group('sortCharactersFirst via NextRoundCommand', () {
+ setUp(() {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Frosthaven').execute();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'BB', 1).execute();
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ 'Ancient Artillery (FH)',
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ });
+
+ test('all alive characters appear before active monsters', () {
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+
+ final list = getIt<GameState>().currentList;
+ bool seenActiveMonster = false;
+ for (final item in list) {
+ if (item is Monster && item.isActive) seenActiveMonster = true;
+ if (item is Character &&
+ item.characterState.health > 0 &&
+ seenActiveMonster) {
+ fail('Alive character "${item.id}" appeared after an active monster');
+ }
+ }
+ expect(list, isNotEmpty);
+ });
+
+ test('dead character is sorted after alive characters', () {
+ AddCharacterCommand('Banner Spear', 'Frosthaven', 'BS', 1).execute();
+ final bs =
+ getIt<GameState>().currentList.firstWhere(
+ (e) => e is Character && e.id == 'Banner Spear',
+ )
+ as Character;
+ ChangeHealthCommand(
+ -bs.characterState.health,
+ bs.id,
+ bs.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+
+ final list = getIt<GameState>().currentList;
+ final bbIdx = list.indexWhere(
+ (e) => e is Character && e.id == 'Blinkblade',
+ );
+ final bsIdx = list.indexWhere(
+ (e) => e is Character && e.id == 'Banner Spear',
+ );
+ expect(
+ bbIdx,
+ lessThan(bsIdx),
+ reason: 'Dead Banner Spear should appear after alive Blinkblade',
+ );
+ });
+
+ test('inactive monster sorted after active monsters', () {
+ AddMonsterCommand(
+ 'Test Boss (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ // Test Boss has no standees → inactive
+
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+
+ final list = getIt<GameState>().currentList;
+ final activeMonsterIdx = list.indexWhere(
+ (e) => e is Monster && e.isActive,
+ );
+ final inactiveMonsterIdx = list.indexWhere(
+ (e) => e is Monster && !e.isActive,
+ );
+
+ if (activeMonsterIdx != -1 && inactiveMonsterIdx != -1) {
+ expect(
+ activeMonsterIdx,
+ lessThan(inactiveMonsterIdx),
+ reason: 'Active monster should come before inactive monster',
+ );
+ }
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // drawAbilityCardFromInactiveDeck (called by AddStandeeCommand during playTurns)
+ // ---------------------------------------------------------------------------
+ group('drawAbilityCardFromInactiveDeck', () {
+ setUp(() {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'BB', 1).execute();
+ });
+
+ test(
+ 'adding first standee during playTurns draws an ability card for the inactive deck',
+ () {
+ final zealot =
+ getIt<GameState>().currentList.firstWhere(
+ (e) => e is Monster && e.id == 'Zealot',
+ )
+ as Monster;
+ final deck = getIt<GameState>().currentAbilityDecks.firstWhere(
+ (d) => d.name == zealot.type.deck,
+ );
+
+ // Zealot has no standees so not drawn during DrawCommand
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ expect(
+ deck.discardPileIsEmpty,
+ isTrue,
+ reason:
+ 'Inactive Zealot should not have drawn a card during DrawCommand',
+ );
+
+ // Add first standee during playTurns → triggers drawAbilityCardFromInactiveDeck
+ AddStandeeCommand(
+ 1,
+ null,
+ zealot.id,
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(
+ deck.discardPileIsNotEmpty,
+ isTrue,
+ reason:
+ 'First standee during playTurns should trigger an ability card draw',
+ );
+ },
+ );
+
+ test(
+ 'adding additional standees to already-active monster does not draw extra cards',
+ () {
+ final zealot =
+ getIt<GameState>().currentList.firstWhere(
+ (e) => e is Monster && e.id == 'Zealot',
+ )
+ as Monster;
+ final deck = getIt<GameState>().currentAbilityDecks.firstWhere(
+ (d) => d.name == zealot.type.deck,
+ );
+
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ zealot.id,
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final sizeAfterFirst = deck.discardPileSize;
+
+ // Second standee should NOT draw another card
+ AddStandeeCommand(
+ 2,
+ null,
+ zealot.id,
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(
+ deck.discardPileSize,
+ sizeAfterFirst,
+ reason:
+ 'Adding a second standee should not draw another ability card',
+ );
+ },
+ );
+ });
+
+ // ---------------------------------------------------------------------------
+ // sortItemToPlace (called by AddStandeeCommand during playTurns)
+ // ---------------------------------------------------------------------------
+ group('sortItemToPlace via AddStandeeCommand during playTurns', () {
+ setUp(() {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'BB', 1).execute();
+ });
+
+ test('monster placed before character when its drawn initiative is lower', () {
+ // Zealot's lowest card initiative is 27 — set character to 99
+ SetInitCommand('Blinkblade', 99, gameState: getIt<GameState>()).execute();
+ DrawCommand(gameState: getIt<GameState>()).execute();
+
+ final zealot =
+ getIt<GameState>().currentList.firstWhere(
+ (e) => e is Monster && e.id == 'Zealot',
+ )
+ as Monster;
+ AddStandeeCommand(
+ 1,
+ null,
+ zealot.id,
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ final deck = getIt<GameState>().currentAbilityDecks.firstWhere(
+ (d) => d.name == zealot.type.deck,
+ );
+ final drawnInit = deck.discardPileTop.initiative;
+
+ final list = getIt<GameState>().currentList;
+ final zealotIdx = list.indexWhere((e) => e.id == 'Zealot');
+ final charIdx = list.indexWhere((e) => e is Character);
+
+ // When monster's initiative < current item's initiative, sortItemToPlace
+ // places it AFTER the current item (not in strict initiative order).
+ if (drawnInit < 99) {
+ expect(
+ zealotIdx,
+ greaterThan(charIdx),
+ reason:
+ 'Zealot (init $drawnInit < 99) should be placed after current Blinkblade',
+ );
+ }
+ });
+
+ test(
+ 'monster placed after character when its drawn initiative is higher',
+ () {
+ // Set character initiative very low so Chaos Demon comes after
+ SetInitCommand(
+ 'Blinkblade',
+ 1,
+ gameState: getIt<GameState>(),
+ ).execute();
+ DrawCommand(gameState: getIt<GameState>()).execute();
+
+ final chaosDemon =
+ getIt<GameState>().currentList.firstWhere(
+ (e) => e is Monster && e.id == 'Chaos Demon',
+ )
+ as Monster;
+ AddStandeeCommand(
+ 1,
+ null,
+ chaosDemon.id,
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ final deck = getIt<GameState>().currentAbilityDecks.firstWhere(
+ (d) => d.name == chaosDemon.type.deck,
+ );
+ final drawnInit = deck.discardPileTop.initiative;
+
+ final list = getIt<GameState>().currentList;
+ final cdIdx = list.indexWhere((e) => e.id == 'Chaos Demon');
+ final charIdx = list.indexWhere((e) => e is Character);
+
+ if (drawnInit > 1) {
+ expect(
+ charIdx,
+ lessThan(cdIdx),
+ reason:
+ 'Blinkblade (init 1) should come before Chaos Demon (init $drawnInit)',
+ );
+ }
+ },
+ );
+ });
+
+ // ---------------------------------------------------------------------------
+ // removeExpiringConditions (via TurnDoneCommand)
+ // ---------------------------------------------------------------------------
+ group('removeExpiringConditions via TurnDoneCommand', () {
+ late Character character;
+ late Monster monster;
+ late MonsterInstance monsterInstance;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Frosthaven').execute();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'BB', 1).execute();
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ 'Ancient Artillery (FH)',
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ monsterInstance = monster.monsterInstances.first;
+ });
+
+ test(
+ 'stun expires on character when turn advances (condition added before draw)',
+ () {
+ // Condition added in chooseInitiative → NOT tracked as "added this turn"
+ AddConditionCommand(
+ Condition.stun,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(character.characterState.conditions, contains(Condition.stun));
+
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ TurnDoneCommand(character.id, gameState: getIt<GameState>()).execute();
+
+ expect(
+ character.characterState.conditions,
+ isNot(contains(Condition.stun)),
+ reason:
+ 'Stun added before round should expire when character turn advances',
+ );
+ },
+ );
+
+ test('poison does NOT expire when character turn advances', () {
+ AddConditionCommand(
+ Condition.poison,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ TurnDoneCommand(character.id, gameState: getIt<GameState>()).execute();
+
+ expect(
+ character.characterState.conditions,
+ contains(Condition.poison),
+ reason: 'Poison is not in the expiring list and should remain',
+ );
+ });
+
+ test('muddle expires on character when turn advances', () {
+ AddConditionCommand(
+ Condition.muddle,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ TurnDoneCommand(character.id, gameState: getIt<GameState>()).execute();
+
+ expect(
+ character.characterState.conditions,
+ isNot(contains(Condition.muddle)),
+ reason: 'Muddle is expirable and should be removed on turn advance',
+ );
+ });
+
+ test('immobilize expires on character when turn advances', () {
+ AddConditionCommand(
+ Condition.immobilize,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ TurnDoneCommand(character.id, gameState: getIt<GameState>()).execute();
+
+ expect(
+ character.characterState.conditions,
+ isNot(contains(Condition.immobilize)),
+ reason: 'Immobilize is expirable and should be removed on turn advance',
+ );
+ });
+
+ test('stun on monster instance expires when monster turn advances', () {
+ AddConditionCommand(
+ Condition.stun,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(monsterInstance.conditions, contains(Condition.stun));
+
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ // First call: notDone → current (no expiry yet)
+ TurnDoneCommand(monster.id, gameState: getIt<GameState>()).execute();
+ // Second call: current → done (triggers removeExpiringConditions)
+ TurnDoneCommand(monster.id, gameState: getIt<GameState>()).execute();
+
+ expect(
+ monsterInstance.conditions,
+ isNot(contains(Condition.stun)),
+ reason:
+ 'Stun on monster instance should expire when monster turn advances',
+ );
+ });
+
+ test(
+ 'wound on monster instance does NOT expire when monster turn advances',
+ () {
+ AddConditionCommand(
+ Condition.wound,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ TurnDoneCommand(monster.id, gameState: getIt<GameState>()).execute();
+
+ expect(
+ monsterInstance.conditions,
+ contains(Condition.wound),
+ reason: 'Wound is not expirable and should remain',
+ );
+ },
+ );
+
+ test('stun added during active turn is NOT expired immediately', () {
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ // Character is current → condition is tracked as "added this turn"
+ AddConditionCommand(
+ Condition.stun,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ TurnDoneCommand(character.id, gameState: getIt<GameState>()).execute();
+
+ expect(
+ character.characterState.conditions,
+ contains(Condition.stun),
+ reason:
+ 'Stun added during own turn should NOT expire at end of that turn',
+ );
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // setTurnDone edge cases
+ // ---------------------------------------------------------------------------
+ group('setTurnDone edge cases', () {
+ setUp(() {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Frosthaven').execute();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'BB', 1).execute();
+ AddCharacterCommand('Banner Spear', 'Frosthaven', 'BS', 1).execute();
+ });
+
+ test('dead character is skipped as next current figure', () {
+ final gs = getIt<GameState>();
+ final bs =
+ gs.currentList.firstWhere(
+ (e) => e is Character && e.id == 'Banner Spear',
+ )
+ as Character;
+ ChangeHealthCommand(
+ -bs.characterState.health,
+ bs.id,
+ bs.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ SetInitCommand('Blinkblade', 10, gameState: getIt<GameState>()).execute();
+ SetInitCommand(
+ 'Banner Spear',
+ 20,
+ gameState: getIt<GameState>(),
+ ).execute();
+ DrawCommand(gameState: getIt<GameState>()).execute();
+
+ final bb =
+ gs.currentList.firstWhere(
+ (e) => e is Character && e.id == 'Blinkblade',
+ )
+ as Character;
+ expect(bb.turnState, TurnsState.current);
+
+ TurnDoneCommand(bb.id, gameState: getIt<GameState>()).execute();
+
+ expect(
+ bs.turnState,
+ isNot(TurnsState.current),
+ reason: 'Dead Banner Spear should never become current',
+ );
+ });
+
+ test('inactive monster is skipped as next current figure', () {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Frosthaven').execute();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'BB', 1).execute();
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ SetInitCommand('Blinkblade', 50, gameState: getIt<GameState>()).execute();
+ DrawCommand(gameState: getIt<GameState>()).execute();
+
+ final bb =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ TurnDoneCommand(bb.id, gameState: getIt<GameState>()).execute();
+
+ final artillery =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ expect(
+ artillery.turnState,
+ isNot(TurnsState.current),
+ reason: 'Inactive monster should never become current',
+ );
+ });
+
+ test('items before the clicked index are set to done', () {
+ SetInitCommand('Blinkblade', 10, gameState: getIt<GameState>()).execute();
+ SetInitCommand(
+ 'Banner Spear',
+ 20,
+ gameState: getIt<GameState>(),
+ ).execute();
+ DrawCommand(gameState: getIt<GameState>()).execute();
+
+ final list = getIt<GameState>().currentList;
+ final bs =
+ list.firstWhere((e) => e is Character && e.id == 'Banner Spear')
+ as Character;
+
+ // Click on Banner Spear (index 1) skips Blinkblade to done
+ TurnDoneCommand(bs.id, gameState: getIt<GameState>()).execute();
+
+ final bb =
+ list.firstWhere((e) => e is Character && e.id == 'Blinkblade')
+ as Character;
+ expect(
+ bb.turnState,
+ TurnsState.done,
+ reason:
+ 'Blinkblade at index 0 should be set to done when Banner Spear at index 1 is clicked',
+ );
+ });
+
+ test('clicking a done item reverts it to current', () {
+ SetInitCommand('Blinkblade', 10, gameState: getIt<GameState>()).execute();
+ SetInitCommand(
+ 'Banner Spear',
+ 20,
+ gameState: getIt<GameState>(),
+ ).execute();
+ DrawCommand(gameState: getIt<GameState>()).execute();
+
+ final list = getIt<GameState>().currentList;
+ final bb =
+ list.firstWhere((e) => e is Character && e.id == 'Blinkblade')
+ as Character;
+
+ TurnDoneCommand(
+ bb.id,
+ gameState: getIt<GameState>(),
+ ).execute(); // current → done, next becomes current
+ expect(bb.turnState, TurnsState.done);
+
+ TurnDoneCommand(
+ bb.id,
+ gameState: getIt<GameState>(),
+ ).execute(); // done → current (revert)
+ expect(
+ bb.turnState,
+ TurnsState.current,
+ reason: 'Clicking a done item should make it current again',
+ );
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // shuffleDecksIfNeeded (called by NextRoundCommand)
+ // ---------------------------------------------------------------------------
+ group('shuffleDecksIfNeeded via NextRoundCommand', () {
+ setUp(() {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'BB', 1).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ 'Zealot',
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ });
+
+ test(
+ 'ability deck with empty draw pile is reshuffled on NextRoundCommand',
+ () {
+ final zealot =
+ getIt<GameState>().currentList.firstWhere(
+ (e) => e is Monster && e.id == 'Zealot',
+ )
+ as Monster;
+ final deck = getIt<GameState>().currentAbilityDecks.firstWhere(
+ (d) => d.name == zealot.type.deck,
+ );
+
+ // Drain all cards from the draw pile
+ while (deck.drawPileIsNotEmpty) {
+ DrawAbilityCardCommand(zealot.id).execute();
+ }
+ expect(
+ deck.drawPileIsEmpty,
+ isTrue,
+ reason: 'Precondition: draw pile should be empty',
+ );
+
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+
+ expect(
+ deck.drawPileIsNotEmpty,
+ isTrue,
+ reason: 'Ability deck should be reshuffled when draw pile was empty',
+ );
+ expect(
+ deck.discardPileIsEmpty,
+ isTrue,
+ reason: 'Discard pile should be empty after reshuffle',
+ );
+ },
+ );
+
+ test('ability deck with shuffle-card on top of discard is reshuffled', () {
+ final zealot =
+ getIt<GameState>().currentList.firstWhere(
+ (e) => e is Monster && e.id == 'Zealot',
+ )
+ as Monster;
+ final deck = getIt<GameState>().currentAbilityDecks.firstWhere(
+ (d) => d.name == zealot.type.deck,
+ );
+
+ // Draw until a shuffle-flagged card lands on top of the discard pile.
+ // We drain the deck once; if no shuffle card appears, skip the assertion.
+ int attempts = 0;
+ while (deck.drawPileIsNotEmpty && attempts < 50) {
+ DrawAbilityCardCommand(zealot.id).execute();
+ attempts++;
+ if (deck.discardPileIsNotEmpty && deck.discardPileTop.shuffle) break;
+ }
+
+ if (deck.discardPileIsNotEmpty && deck.discardPileTop.shuffle) {
+ final discardSizeBefore = deck.discardPileSize;
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+ expect(
+ deck.discardPileIsEmpty,
+ isTrue,
+ reason:
+ 'Discard pile should be empty after shuffle-triggered reshuffle',
+ );
+ expect(
+ deck.drawPileSize,
+ greaterThanOrEqualTo(discardSizeBefore),
+ reason: 'Draw pile should contain all formerly discarded cards',
+ );
+ }
+ // If we never got a shuffle card on top, the test is a no-op (inconclusive but not failing)
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // addPerk / removePerk – Hail perk 17 (adds special card to main modifier deck)
+ // ---------------------------------------------------------------------------
+ group('addPerk/removePerk – Hail perk 17 (Hail special card)', () {
+ late Character hail;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Frosthaven').execute();
+ // Reset the modifier deck between tests via SetScenarioCommand (section=false
+ // calls modifierDeck._initDeck() before we add our character)
+ SetScenarioCommand(
+ '#0 Howling in the Snow',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ // Hail's edition is "Mercenary Packs" (cross-edition character)
+ AddCharacterCommand('Hail', 'Mercenary Packs', 'H', 1).execute();
+ hail =
+ getIt<GameState>().currentList.firstWhere(
+ (e) => e is Character && e.id == 'Hail',
+ )
+ as Character;
+ });
+
+ test('adding Hail perk 17 adds special card to the main modifier deck', () {
+ final deckBefore = getIt<GameState>().modifierDeck.drawPileSize;
+
+ AddPerkCommand(hail.id, 17).execute();
+
+ expect(
+ getIt<GameState>().modifierDeck.hasHail(),
+ isTrue,
+ reason:
+ 'Main modifier deck should contain the Hail special card after perk 17',
+ );
+ expect(
+ getIt<GameState>().modifierDeck.drawPileSize,
+ greaterThan(deckBefore),
+ reason:
+ 'Main modifier deck size should increase after adding Hail perk 17',
+ );
+ });
+
+ test(
+ 'removing Hail perk 17 removes special card from the main modifier deck',
+ () {
+ AddPerkCommand(hail.id, 17).execute();
+ expect(getIt<GameState>().modifierDeck.hasHail(), isTrue);
+
+ AddPerkCommand(hail.id, 17).execute(); // toggle off
+
+ expect(
+ getIt<GameState>().modifierDeck.hasHail(),
+ isFalse,
+ reason:
+ 'Hail special card should be removed when perk 17 is toggled off',
+ );
+ },
+ );
+
+ test('main modifier deck card count is restored after add then remove', () {
+ final deckBefore = getIt<GameState>().modifierDeck.drawPileSize;
+
+ AddPerkCommand(hail.id, 17).execute();
+ AddPerkCommand(hail.id, 17).execute();
+
+ expect(
+ getIt<GameState>().modifierDeck.drawPileSize,
+ deckBefore,
+ reason: 'Deck count should be unchanged after toggling perk on and off',
+ );
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // addPerk / removePerk – Pain Conduit perk 16 (max health +5)
+ // ---------------------------------------------------------------------------
+ group('addPerk/removePerk – Pain Conduit perk 16 (max health +5)', () {
+ late Character painConduit;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Frosthaven').execute();
+ AddCharacterCommand('Pain Conduit', 'Frosthaven', 'PC', 1).execute();
+ painConduit =
+ getIt<GameState>().currentList.firstWhere(
+ (e) => e is Character && e.id == 'Pain Conduit',
+ )
+ as Character;
+ });
+
+ test('adding Pain Conduit perk 16 increases max health by 5', () {
+ final maxHealthBefore = painConduit.characterState.maxHealth;
+
+ AddPerkCommand(painConduit.id, 16).execute();
+
+ expect(
+ painConduit.characterState.maxHealth,
+ maxHealthBefore + 5,
+ reason: 'Max health should increase by 5 for Pain Conduit perk 16',
+ );
+ });
+
+ test('adding Pain Conduit perk 16 increases current health by 5', () {
+ final healthBefore = painConduit.characterState.health;
+
+ AddPerkCommand(painConduit.id, 16).execute();
+
+ expect(
+ painConduit.characterState.health,
+ healthBefore + 5,
+ reason: 'Current health should also increase by 5',
+ );
+ });
+
+ test('removing Pain Conduit perk 16 restores original max health', () {
+ final maxHealthBefore = painConduit.characterState.maxHealth;
+
+ AddPerkCommand(painConduit.id, 16).execute();
+ AddPerkCommand(painConduit.id, 16).execute(); // toggle off
+
+ expect(
+ painConduit.characterState.maxHealth,
+ maxHealthBefore,
+ reason:
+ 'Max health should be restored to original after toggling perk off',
+ );
+ });
+
+ test('Pain Conduit perk 16 bonus applies at a higher level', () {
+ SetCharacterLevelCommand(5, painConduit.id).execute();
+ final maxHealthAtLevel5 = painConduit.characterState.maxHealth;
+
+ AddPerkCommand(painConduit.id, 16).execute();
+
+ expect(
+ painConduit.characterState.maxHealth,
+ maxHealthAtLevel5 + 5,
+ reason: 'Perk 16 always adds exactly +5 regardless of level',
+ );
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // setCharacterLevel – level capping and special character handling
+ // ---------------------------------------------------------------------------
+ group('setCharacterLevel special cases', () {
+ setUp(() {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Frosthaven').execute();
+ });
+
+ test(
+ 'Pain Conduit with perk 16 active has correct health after level change',
+ () {
+ AddCharacterCommand('Pain Conduit', 'Frosthaven', 'PC', 1).execute();
+ final pc =
+ getIt<GameState>().currentList.firstWhere(
+ (e) => e is Character && e.id == 'Pain Conduit',
+ )
+ as Character;
+
+ AddPerkCommand(pc.id, 16).execute();
+ SetCharacterLevelCommand(3, pc.id).execute();
+
+ final baseHealth =
+ pc.characterClass.healthByLevel[2]; // level 3 = index 2
+ expect(
+ pc.characterState.health,
+ baseHealth + 5,
+ reason: 'Pain Conduit with perk 16 should have base level health + 5',
+ );
+ expect(pc.characterState.maxHealth, baseHealth + 5);
+ },
+ );
+
+ test('character level is capped at max health table length', () {
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'BB', 1).execute();
+ final bb =
+ getIt<GameState>().currentList.firstWhere(
+ (e) => e is Character && e.id == 'Blinkblade',
+ )
+ as Character;
+
+ final maxLevel = bb.characterClass.healthByLevel.length;
+ SetCharacterLevelCommand(maxLevel + 5, bb.id).execute();
+
+ expect(
+ bb.characterState.level,
+ maxLevel,
+ reason: 'Level should be capped at the number of health table entries',
+ );
+ });
+
+ test('character health and max health are updated on level change', () {
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'BB', 1).execute();
+ final bb =
+ getIt<GameState>().currentList.firstWhere(
+ (e) => e is Character && e.id == 'Blinkblade',
+ )
+ as Character;
+
+ SetCharacterLevelCommand(5, bb.id).execute();
+
+ final expectedHealth =
+ bb.characterClass.healthByLevel[4]; // level 5 = index 4
+ expect(bb.characterState.health, expectedHealth);
+ expect(bb.characterState.maxHealth, expectedHealth);
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // clearTurnState (called by NextRoundCommand)
+ // ---------------------------------------------------------------------------
+ group('clearTurnState via NextRoundCommand', () {
+ late Character character;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Frosthaven').execute();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'BB', 1).execute();
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ });
+
+ test('all turn states are reset to notDone after NextRoundCommand', () {
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ TurnDoneCommand(character.id, gameState: getIt<GameState>()).execute();
+
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+
+ for (final item in getIt<GameState>().currentList) {
+ expect(
+ item.turnState,
+ TurnsState.notDone,
+ reason: 'All items should be notDone after round end',
+ );
+ }
+ });
+
+ test('conditions tracking is cleared at round end', () {
+ // Add stun during active turn (tracked as this turn)
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ AddConditionCommand(
+ Condition.stun,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ TurnDoneCommand(character.id, gameState: getIt<GameState>()).execute();
+
+ // Stun is tracked in conditionsAddedThisTurn
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+ // conditionsAddedThisTurn → conditionsAddedPreviousTurn, and fresh turn starts
+
+ // Round state should be chooseInitiative now
+ expect(getIt<GameState>().roundState, RoundState.chooseInitiative);
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // updateElements (called by NextRoundCommand)
+ // ---------------------------------------------------------------------------
+ group('updateElements via NextRoundCommand', () {
+ setUp(() {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Frosthaven').execute();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'BB', 1).execute();
+ });
+
+ test('full element steps to half after NextRoundCommand', () {
+ ImbueElementCommand(Elements.fire, false).execute();
+ expect(getIt<GameState>().elementState[Elements.fire], ElementState.full);
+
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+
+ expect(getIt<GameState>().elementState[Elements.fire], ElementState.half);
+ });
+
+ test('half element steps to inert after NextRoundCommand', () {
+ ImbueElementCommand(Elements.ice, true).execute(); // half
+ expect(getIt<GameState>().elementState[Elements.ice], ElementState.half);
+
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+
+ expect(getIt<GameState>().elementState[Elements.ice], ElementState.inert);
+ });
+
+ test('inert element stays inert after NextRoundCommand', () {
+ // earth is inert by default
+ expect(
+ getIt<GameState>().elementState[Elements.earth],
+ ElementState.inert,
+ );
+
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+
+ expect(
+ getIt<GameState>().elementState[Elements.earth],
+ ElementState.inert,
+ );
+ });
+
+ test('all six elements decay by one step each round', () {
+ ImbueElementCommand(Elements.fire, false).execute();
+ ImbueElementCommand(Elements.ice, false).execute();
+ ImbueElementCommand(Elements.air, false).execute();
+ ImbueElementCommand(Elements.earth, false).execute();
+ ImbueElementCommand(Elements.light, false).execute();
+ ImbueElementCommand(Elements.dark, false).execute();
+
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+
+ for (final element in Elements.values) {
+ expect(
+ getIt<GameState>().elementState[element],
+ ElementState.half,
+ reason: '${element.name} should step from full to half',
+ );
+ }
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // resetElements (called by SetScenarioCommand)
+ // ---------------------------------------------------------------------------
+ group('resetElements via SetScenarioCommand', () {
+ test('all elements are reset to inert when loading a new scenario', () {
+ getIt<GameState>().clearList();
+ SetCampaignCommand('Frosthaven').execute();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'BB', 1).execute();
+
+ ImbueElementCommand(Elements.fire, false).execute();
+ ImbueElementCommand(Elements.light, true).execute();
+
+ SetScenarioCommand(
+ '#0 Howling in the Snow',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ for (final element in Elements.values) {
+ expect(
+ getIt<GameState>().elementState[element],
+ ElementState.inert,
+ reason: '${element.name} should be inert after scenario reset',
+ );
+ }
+ });
+ });
+}
diff --git a/server/test/command/next_round_command_test.dart b/server/test/command/next_round_command_test.dart
new file mode 100644
index 0000000..dd7cc5a
--- /dev/null
+++ b/server/test/command/next_round_command_test.dart
@@ -0,0 +1,174 @@
+// ignore_for_file: no-magic-number
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/draw_command.dart';
+import 'package:x_haven_server/core/commands/draw_modifier_card_command.dart';
+import 'package:x_haven_server/core/commands/imbue_element_command.dart';
+import 'package:x_haven_server/core/commands/next_round_command.dart';
+import 'package:x_haven_server/core/commands/set_campaign_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/game_data.dart';
+import 'package:x_haven_server/core/settings.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'Blinky', 1).execute();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ });
+
+ group('NextRoundCommand', () {
+ test('should increment the round counter', () {
+ final roundBefore = getIt<GameState>().round;
+
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+
+ expect(getIt<GameState>().round, roundBefore + 1);
+ checkSaveState();
+ });
+
+ test('should step down full elements to half after next round', () {
+ ImbueElementCommand(Elements.fire, false).execute();
+ expect(getIt<GameState>().elementState[Elements.fire], ElementState.full);
+
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+
+ expect(getIt<GameState>().elementState[Elements.fire], ElementState.half);
+ });
+
+ test('should step down half elements to inert after next round', () {
+ ImbueElementCommand(Elements.ice, true).execute();
+ expect(getIt<GameState>().elementState[Elements.ice], ElementState.half);
+
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+
+ expect(getIt<GameState>().elementState[Elements.ice], ElementState.inert);
+ });
+
+ test('describe returns "Next Round"', () {
+ expect(
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).describe(),
+ 'Next Round',
+ );
+ });
+
+ test('undo does not throw', () {
+ final gs = getIt<GameState>();
+ gs.action(
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ),
+ );
+ expect(() => gs.undo(), returnsNormally);
+ });
+
+ test('shuffles monster modifier deck when needsShuffle is true', () {
+ // Draw all cards to force needsShuffle
+ final gs = getIt<GameState>();
+ final deck = gs.modifierDeck;
+ // Draw until needsShuffle is set (drawing a multiply/2x or curse usually does it)
+ int attempts = 0;
+ while (!deck.needsShuffle && attempts < 30) {
+ DrawModifierCardCommand('', gameState: getIt<GameState>()).execute();
+ attempts++;
+ }
+ if (deck.needsShuffle) {
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+ // After next round with needsShuffle, deck should be reshuffled
+ expect(deck.drawPileIsNotEmpty, isTrue);
+ }
+ });
+
+ test('character modifier deck needsShuffle is shuffled on next round', () {
+ final gs = getIt<GameState>();
+ final character =
+ gs.currentList.firstWhere((e) => e is Character) as Character;
+ final deck = character.characterState.modifierDeck;
+ int attempts = 0;
+ while (!deck.needsShuffle && attempts < 30) {
+ DrawModifierCardCommand(
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ attempts++;
+ }
+ if (deck.needsShuffle) {
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+ expect(deck.drawPileIsNotEmpty, isTrue);
+ }
+ });
+
+ test('modifier deck ally needsShuffle is shuffled on next round', () {
+ final gs = getIt<GameState>();
+ final deck = gs.modifierDeckAllies;
+ int attempts = 0;
+ while (!deck.needsShuffle && attempts < 30) {
+ DrawModifierCardCommand(
+ 'allies',
+ gameState: getIt<GameState>(),
+ ).execute();
+ attempts++;
+ }
+ if (deck.needsShuffle) {
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+ expect(deck.drawPileIsNotEmpty, isTrue);
+ }
+ });
+
+ test('roundState is reset to chooseInitiative after DrawCommand', () {
+ DrawCommand(gameState: getIt<GameState>()).execute();
+ expect(getIt<GameState>().roundState, RoundState.playTurns);
+ NextRoundCommand(
+ gameState: getIt<GameState>(),
+ gameData: getIt<GameData>(),
+ settings: getIt<Settings>(),
+ ).execute();
+ expect(getIt<GameState>().roundState, RoundState.chooseInitiative);
+ });
+ });
+}
diff --git a/server/test/command/next_turn_command_test.dart b/server/test/command/next_turn_command_test.dart
new file mode 100644
index 0000000..89c0981
--- /dev/null
+++ b/server/test/command/next_turn_command_test.dart
@@ -0,0 +1,56 @@
+// ignore_for_file: avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/turn_done_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Banner Spear', 'Frosthaven', 'BS', 1).execute();
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ });
+
+ group('TurnDoneCommand', () {
+ test('should set character turn to current when not current', () {
+ expect(character.turnState, isNot(TurnsState.current));
+
+ TurnDoneCommand(character.id, gameState: getIt<GameState>()).execute();
+
+ expect(character.turnState, TurnsState.current);
+ });
+
+ test('should mark character turn as done when current', () {
+ // First call sets to current
+ TurnDoneCommand(character.id, gameState: getIt<GameState>()).execute();
+ expect(character.turnState, TurnsState.current);
+
+ // Second call sets to done
+ TurnDoneCommand(character.id, gameState: getIt<GameState>()).execute();
+
+ expect(character.turnState, TurnsState.done);
+ checkSaveState();
+ });
+
+ test('describe includes character id', () {
+ final command = TurnDoneCommand(
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), "${character.id}'s turn done");
+ });
+ });
+}
diff --git a/server/test/command/note_row_command_test.dart b/server/test/command/note_row_command_test.dart
new file mode 100644
index 0000000..da14bc2
--- /dev/null
+++ b/server/test/command/note_row_command_test.dart
@@ -0,0 +1,142 @@
+// ignore_for_file: avoid-late-keyword, no-magic-number
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_note_row_command.dart';
+import 'package:x_haven_server/core/commands/draw_command.dart';
+import 'package:x_haven_server/core/commands/remove_note_row_command.dart';
+import 'package:x_haven_server/core/commands/reorder_list_command.dart';
+import 'package:x_haven_server/core/commands/set_init_command.dart';
+import 'package:x_haven_server/core/commands/set_note_row_color_command.dart';
+import 'package:x_haven_server/core/commands/set_note_row_link_command.dart';
+import 'package:x_haven_server/core/commands/set_note_row_text_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ GameState gs() => getIt<GameState>();
+
+ setUp(() {
+ gs().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "Blinky", 1).execute();
+ AddMonsterCommand("Zealot", 1, false, gameState: gs()).execute();
+ });
+
+ int indexOfId(String id) =>
+ gs().currentList.toList().indexWhere((e) => e.id == id);
+
+ group('NoteRow commands', () {
+ test('unlinked note is added as its own row and survives save/load', () {
+ gs().action(
+ AddNoteRowCommand(
+ NoteRow.create('note1', text: 'remember'),
+ gameState: gs(),
+ ),
+ );
+
+ final match = gs().currentList.firstWhere((e) => e.id == 'note1');
+ expect(match, isA<NoteRow>());
+ expect((match as NoteRow).text, 'remember');
+ checkSaveState();
+ });
+
+ test('linked note is glued directly after its target', () {
+ // Link a note to the Zealot monster.
+ gs().action(
+ AddNoteRowCommand(
+ NoteRow.create('note1', text: 'focus first', linkedId: 'Zealot'),
+ gameState: gs(),
+ ),
+ );
+
+ final monsterIndex = indexOfId('Zealot');
+ final noteIndex = indexOfId('note1');
+ expect(
+ noteIndex,
+ monsterIndex + 1,
+ reason: 'linked note must sit immediately after its target',
+ );
+ checkSaveState();
+ });
+
+ test('note re-glues after the list is reordered', () {
+ gs().action(
+ AddNoteRowCommand(
+ NoteRow.create('note1', linkedId: 'Zealot'),
+ gameState: gs(),
+ ),
+ );
+
+ // Move the note to the very top; reflow should pull it back under Zealot.
+ final from = indexOfId('note1');
+ gs().action(ReorderListCommand(0, from, gameState: gs()));
+
+ final monsterIndex = indexOfId('Zealot');
+ expect(indexOfId('note1'), monsterIndex + 1);
+ });
+
+ test(
+ 'linked note stays glued under its target through the draw (round start)',
+ () {
+ // Give the character an initiative and link a note to it.
+ SetInitCommand('Blinkblade', 25, gameState: gs()).execute();
+ gs().action(
+ AddNoteRowCommand(
+ NoteRow.create('note1', linkedId: 'Blinkblade'),
+ gameState: gs(),
+ ),
+ );
+ expect(indexOfId('note1'), indexOfId('Blinkblade') + 1);
+
+ // Drawing for the round sorts the list by initiative (scattering notes,
+ // which have no initiative) and notifies via updateList.notify(). The
+ // reflow in the sort must still re-glue the note under its target.
+ gs().action(DrawCommand(gameState: gs()));
+
+ expect(
+ indexOfId('note1'),
+ indexOfId('Blinkblade') + 1,
+ reason: 'note must follow its target across the initiative sort',
+ );
+ },
+ );
+
+ test('setText / setColor / link / unlink mutate the note', () {
+ gs().action(AddNoteRowCommand(NoteRow.create('note1'), gameState: gs()));
+ final note =
+ gs().currentList.firstWhere((e) => e.id == 'note1') as NoteRow;
+
+ gs().action(SetNoteRowTextCommand('hello', 'note1', gameState: gs()));
+ expect(note.text, 'hello');
+
+ gs().action(SetNoteRowColorCommand(0xFFAA0000, 'note1', gameState: gs()));
+ expect(note.color, 0xFFAA0000);
+
+ gs().action(SetNoteRowLinkCommand('note1', 'Zealot', 3, gameState: gs()));
+ expect(note.linkedId, 'Zealot');
+ expect(note.standeeNr, 3);
+
+ // Unlink clears the standee too.
+ gs().action(SetNoteRowLinkCommand('note1', '', 0, gameState: gs()));
+ expect(note.linkedId, '');
+ expect(note.standeeNr, 0);
+ checkSaveState();
+ });
+
+ test('remove deletes the note row', () {
+ gs().action(AddNoteRowCommand(NoteRow.create('note1'), gameState: gs()));
+ expect(indexOfId('note1') >= 0, true);
+
+ gs().action(RemoveNoteRowCommand('note1', gameState: gs()));
+ expect(indexOfId('note1'), -1);
+ checkSaveState();
+ });
+ });
+}
diff --git a/server/test/command/note_row_standee_death_test.dart b/server/test/command/note_row_standee_death_test.dart
new file mode 100644
index 0000000..5586700
--- /dev/null
+++ b/server/test/command/note_row_standee_death_test.dart
@@ -0,0 +1,81 @@
+// ignore_for_file: no-magic-number, avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_note_row_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_health_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ GameState gs() => getIt<GameState>();
+
+ test(
+ 'a note tied to a specific standee is deleted when that standee dies',
+ () {
+ gs().clearList();
+ AddMonsterCommand("Zealot", 1, false, gameState: gs()).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ "Zealot",
+ MonsterType.normal,
+ false,
+ gameState: gs(),
+ ).execute();
+ final monster =
+ gs().currentList.firstWhere((e) => e is Monster) as Monster;
+ final instance = monster.monsterInstances.first;
+ final standeeNr = instance.standeeNr;
+
+ // A note pinned to this standee, plus a whole-group note (standeeNr 0).
+ gs().action(
+ AddNoteRowCommand(
+ NoteRow.create(
+ 'standeeNote',
+ linkedId: monster.id,
+ standeeNr: standeeNr,
+ ),
+ gameState: gs(),
+ ),
+ );
+ gs().action(
+ AddNoteRowCommand(
+ NoteRow.create('groupNote', linkedId: monster.id),
+ gameState: gs(),
+ ),
+ );
+ expect(gs().currentList.any((e) => e.id == 'standeeNote'), true);
+
+ // Defeat the standee (drop its health to 0).
+ gs().action(
+ ChangeHealthCommand(
+ -instance.health,
+ instance.getId(),
+ monster.id,
+ gameState: gs(),
+ ),
+ );
+
+ // The standee's note is gone; the whole-group note remains.
+ expect(
+ gs().currentList.any((e) => e.id == 'standeeNote'),
+ false,
+ reason: 'note tied to the defeated standee should be deleted',
+ );
+ expect(
+ gs().currentList.any((e) => e.id == 'groupNote'),
+ true,
+ reason: 'whole-group note is not standee-specific and should remain',
+ );
+ },
+ );
+}
diff --git a/server/test/command/remove_amd_card_command_test.dart b/server/test/command/remove_amd_card_command_test.dart
new file mode 100644
index 0000000..a444cc0
--- /dev/null
+++ b/server/test/command/remove_amd_card_command_test.dart
@@ -0,0 +1,75 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/draw_modifier_card_command.dart';
+import 'package:x_haven_server/core/commands/remove_amd_card_command.dart';
+import 'package:x_haven_server/core/commands/return_removed_amd_card_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ group('RemoveAMDCardCommand', () {
+ test('should move card from discard to removed pile', () {
+ DrawModifierCardCommand('', gameState: getIt<GameState>()).execute();
+ final deck = getIt<GameState>().modifierDeck;
+ final discardBefore = deck.discardPileSize;
+ final removedBefore = deck.removedPileSize;
+
+ RemoveAMDCardCommand(
+ index: 0,
+ name: '',
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(deck.discardPileSize, discardBefore - 1);
+ expect(deck.removedPileSize, removedBefore + 1);
+ checkSaveState();
+ });
+
+ test('describe returns correct string', () {
+ final command = RemoveAMDCardCommand(
+ index: 0,
+ name: '',
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Remove AMD card');
+ });
+ });
+
+ group('ReturnRemovedAMDCardCommand', () {
+ test('should move card from removed pile back to discard', () {
+ DrawModifierCardCommand('', gameState: getIt<GameState>()).execute();
+ RemoveAMDCardCommand(
+ index: 0,
+ name: '',
+ gameState: getIt<GameState>(),
+ ).execute();
+ final deck = getIt<GameState>().modifierDeck;
+ final discardBefore = deck.discardPileSize;
+ final removedBefore = deck.removedPileSize;
+
+ ReturnRemovedAMDCardCommand(
+ index: 0,
+ name: '',
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(deck.removedPileSize, removedBefore - 1);
+ expect(deck.discardPileSize, discardBefore + 1);
+ checkSaveState();
+ });
+
+ test('describe returns correct string', () {
+ final command = ReturnRemovedAMDCardCommand(
+ index: 0,
+ name: '',
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Return removed AMD card');
+ });
+ });
+}
diff --git a/server/test/command/remove_character_command_test.dart b/server/test/command/remove_character_command_test.dart
new file mode 100644
index 0000000..f4793a4
--- /dev/null
+++ b/server/test/command/remove_character_command_test.dart
@@ -0,0 +1,30 @@
+// ignore_for_file: no-magic-number
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/remove_character_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void _tests() {
+ final oldState = gameState.toString();
+ AddCharacterCommand("Hatchet", "Jaws of the Lion", "Arnold", 9).execute();
+ RemoveCharacterCommand(
+ List.of([gameState.currentList.last as Character]),
+ gameState: getIt<GameState>(),
+ ).execute();
+ test("removed ok", () {
+ expect(gameState.currentList.isEmpty, true);
+ expect(gameState.unlockedClasses.first, "Hatchet");
+
+ checkNoSideEffects(["unlockedClasses"], oldState);
+ checkSaveState();
+ });
+}
+
+Future<void> main() async {
+ await setUpGame();
+ _tests();
+}
diff --git a/server/test/command/remove_condition_command_test.dart b/server/test/command/remove_condition_command_test.dart
new file mode 100644
index 0000000..11bb79f
--- /dev/null
+++ b/server/test/command/remove_condition_command_test.dart
@@ -0,0 +1,129 @@
+// ignore_for_file: no-magic-number, avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_condition_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/commands/remove_condition_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+ late Monster monster;
+ late MonsterInstance monsterInstance;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ 'Ancient Artillery (FH)',
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ monsterInstance = monster.monsterInstances.first;
+ });
+
+ group('RemoveConditionCommand', () {
+ test('should remove a condition from a character', () {
+ AddConditionCommand(
+ Condition.poison,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(character.characterState.conditions, contains(Condition.poison));
+
+ RemoveConditionCommand(
+ Condition.poison,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(
+ character.characterState.conditions,
+ isNot(contains(Condition.poison)),
+ );
+ checkSaveState();
+ });
+
+ test('should remove a condition from a monster instance', () {
+ AddConditionCommand(
+ Condition.wound,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(monsterInstance.conditions, contains(Condition.wound));
+
+ RemoveConditionCommand(
+ Condition.wound,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(monsterInstance.conditions, isNot(contains(Condition.wound)));
+ });
+
+ test('should decrement chill counter when removing chill', () {
+ AddConditionCommand(
+ Condition.chill,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddConditionCommand(
+ Condition.chill,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(character.characterState.chill, 2);
+
+ RemoveConditionCommand(
+ Condition.chill,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(character.characterState.chill, 1);
+ });
+
+ test('describe should return correct string', () {
+ final command = RemoveConditionCommand(
+ Condition.stun,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Remove condition: stun');
+ });
+ });
+}
diff --git a/server/test/command/remove_cs_party_card_command_test.dart b/server/test/command/remove_cs_party_card_command_test.dart
new file mode 100644
index 0000000..3d8324f
--- /dev/null
+++ b/server/test/command/remove_cs_party_card_command_test.dart
@@ -0,0 +1,54 @@
+// ignore_for_file: avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_cs_party_card_command.dart';
+import 'package:x_haven_server/core/commands/remove_cs_party_card_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "", 1).execute();
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ });
+
+ group('RemoveCSPartyCardCommand', () {
+ test('should remove party card from character modifier deck', () {
+ AddCSPartyCardCommand(
+ character.id,
+ 1,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final deck = character.characterState.modifierDeck;
+ expect(deck.hasCard('party/1'), isTrue);
+
+ RemoveCSPartyCardCommand(
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(deck.hasCard('party/1'), isFalse);
+ checkSaveState();
+ });
+
+ test('describe includes character id', () {
+ final command = RemoveCSPartyCardCommand(
+ character.id,
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), '${character.id} remove party card');
+ });
+ });
+}
diff --git a/server/test/command/remove_monster_command_test.dart b/server/test/command/remove_monster_command_test.dart
new file mode 100644
index 0000000..1bcd3da
--- /dev/null
+++ b/server/test/command/remove_monster_command_test.dart
@@ -0,0 +1,74 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/remove_monster_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ });
+
+ group('RemoveMonsterCommand', () {
+ test('should remove a single monster from the list', () {
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ expect(getIt<GameState>().currentList.whereType<Monster>().length, 1);
+
+ RemoveMonsterCommand([monster], gameState: getIt<GameState>()).execute();
+
+ expect(getIt<GameState>().currentList.whereType<Monster>(), isEmpty);
+ checkSaveState();
+ });
+
+ test(
+ 'describe returns "Remove all monsters" for multiple items in list',
+ () {
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ // Passing the same monster twice simulates a multi-monster list
+ final command = RemoveMonsterCommand([
+ monster,
+ monster,
+ ], gameState: getIt<GameState>());
+ expect(command.describe(), 'Remove all monsters');
+ },
+ );
+
+ test('describe includes monster type name for single monster', () {
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ final command = RemoveMonsterCommand([
+ monster,
+ ], gameState: getIt<GameState>());
+ expect(command.describe(), contains('Remove'));
+ });
+ });
+}
diff --git a/server/test/command/remove_special_loot_card_command_test.dart b/server/test/command/remove_special_loot_card_command_test.dart
new file mode 100644
index 0000000..4c1ba1a
--- /dev/null
+++ b/server/test/command/remove_special_loot_card_command_test.dart
@@ -0,0 +1,76 @@
+// ignore_for_file: no-magic-number
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_special_loot_card_command.dart';
+import 'package:x_haven_server/core/commands/remove__special_loot_card_command.dart';
+import 'package:x_haven_server/core/commands/set_campaign_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ SetCampaignCommand('Frosthaven').execute();
+ SetScenarioCommand(
+ '#0 Howling in the Snow',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ });
+
+ group('RemoveSpecialLootCardCommand', () {
+ test('should remove special card 1418 from draw pile', () {
+ AddSpecialLootCardCommand(1418, gameState: getIt<GameState>()).execute();
+ final lootDeck = getIt<GameState>().lootDeck;
+ expect(lootDeck.hasCard1418, isTrue);
+
+ RemoveSpecialLootCardCommand(
+ 1418,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(lootDeck.hasCard1418, isFalse);
+ checkSaveState();
+ });
+
+ test('should remove special card 1419 from draw pile', () {
+ AddSpecialLootCardCommand(1419, gameState: getIt<GameState>()).execute();
+ final lootDeck = getIt<GameState>().lootDeck;
+ expect(lootDeck.hasCard1419, isTrue);
+
+ RemoveSpecialLootCardCommand(
+ 1419,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(lootDeck.hasCard1419, isFalse);
+ checkSaveState();
+ });
+
+ test('should do nothing for unknown card nr', () {
+ final lootDeck = getIt<GameState>().lootDeck;
+ final countBefore = lootDeck.drawPileSize;
+
+ RemoveSpecialLootCardCommand(
+ 9999,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(lootDeck.drawPileSize, countBefore);
+ });
+
+ test('describe includes the card number', () {
+ final command = RemoveSpecialLootCardCommand(
+ 1418,
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Remove Special loot card 1418');
+ });
+ });
+}
diff --git a/server/test/command/reorder_list_command_test.dart b/server/test/command/reorder_list_command_test.dart
new file mode 100644
index 0000000..f7b065f
--- /dev/null
+++ b/server/test/command/reorder_list_command_test.dart
@@ -0,0 +1,124 @@
+// ignore_for_file: prefer-first, no-magic-number, avoid-non-null-assertion
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/reorder_ability_list_command.dart';
+import 'package:x_haven_server/core/commands/reorder_list_command.dart';
+import 'package:x_haven_server/core/commands/reorder_modifier_list_command.dart';
+import 'package:x_haven_server/core/game_methods.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Banner Spear', 'Frosthaven', 'BS', 1).execute();
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ });
+
+ group('ReorderListCommand', () {
+ test('should swap two items in the main list', () {
+ final list = getIt<GameState>().currentList;
+ final firstId = list[0].id;
+ final secondId = list[1].id;
+
+ ReorderListCommand(0, 1, gameState: getIt<GameState>()).execute();
+
+ expect(getIt<GameState>().currentList[0].id, secondId);
+ expect(getIt<GameState>().currentList[1].id, firstId);
+ });
+
+ test('describe returns correct string', () {
+ expect(
+ ReorderListCommand(0, 1, gameState: getIt<GameState>()).describe(),
+ 'Reorder List',
+ );
+ });
+
+ test('undo does not throw', () {
+ final gs = getIt<GameState>();
+ gs.action(ReorderListCommand(0, 1, gameState: getIt<GameState>()));
+ expect(() => gs.undo(), returnsNormally);
+ });
+ });
+
+ group('ReorderAbilityListCommand', () {
+ test('should reorder cards in a monster ability deck', () {
+ final monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ final deck = GameMethods.getDeck(monster.type.deck)!;
+ // Need at least 2 cards
+ if (deck.drawPileSize >= 2) {
+ final firstCardNr = deck.drawPileContents.toList()[0].nr;
+ final secondCardNr = deck.drawPileContents.toList()[1].nr;
+
+ ReorderAbilityListCommand(
+ monster.type.deck,
+ 0,
+ 1,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(deck.drawPileContents.toList()[0].nr, secondCardNr);
+ expect(deck.drawPileContents.toList()[1].nr, firstCardNr);
+ }
+ });
+
+ test('describe returns correct string', () {
+ expect(
+ ReorderAbilityListCommand(
+ 'deck',
+ 0,
+ 1,
+ gameState: getIt<GameState>(),
+ ).describe(),
+ 'Reorder Ability Cards',
+ );
+ });
+ });
+
+ group('ReorderModifierListCommand', () {
+ test('should reorder cards in a modifier deck draw pile', () {
+ final deck = getIt<GameState>().modifierDeck;
+ if (deck.drawPileSize >= 2) {
+ final firstGfx = deck.drawPileContents.toList()[0].gfx;
+ final secondGfx = deck.drawPileContents.toList()[1].gfx;
+
+ ReorderModifierListCommand(
+ 0,
+ 1,
+ '',
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(deck.drawPileContents.toList()[0].gfx, secondGfx);
+ expect(deck.drawPileContents.toList()[1].gfx, firstGfx);
+ }
+ });
+
+ test('describe returns correct string', () {
+ expect(
+ ReorderModifierListCommand(
+ 0,
+ 1,
+ '',
+ gameState: getIt<GameState>(),
+ ).describe(),
+ 'Reorder Modifier Cards',
+ );
+ });
+ });
+}
diff --git a/server/test/command/return_modifier_card_command_test.dart b/server/test/command/return_modifier_card_command_test.dart
new file mode 100644
index 0000000..cac044c
--- /dev/null
+++ b/server/test/command/return_modifier_card_command_test.dart
@@ -0,0 +1,33 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/draw_modifier_card_command.dart';
+import 'package:x_haven_server/core/commands/return_modifier_card_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ group('ReturnModifierCardCommand', () {
+ test('should move top discard card back to draw pile', () {
+ DrawModifierCardCommand('', gameState: getIt<GameState>()).execute();
+ final deck = getIt<GameState>().modifierDeck;
+ final drawBefore = deck.drawPileSize;
+ final discardBefore = deck.discardPileSize;
+
+ ReturnModifierCardCommand('').execute();
+
+ expect(deck.drawPileSize, drawBefore + 1);
+ expect(deck.discardPileSize, discardBefore - 1);
+ checkSaveState();
+ });
+
+ test('describe returns correct string', () {
+ final command = ReturnModifierCardCommand('');
+ expect(command.describe(), 'Return modifier card to top');
+ });
+ });
+}
diff --git a/server/test/command/set_ally_deck_in_og_gloom_command_test.dart b/server/test/command/set_ally_deck_in_og_gloom_command_test.dart
new file mode 100644
index 0000000..8e1659d
--- /dev/null
+++ b/server/test/command/set_ally_deck_in_og_gloom_command_test.dart
@@ -0,0 +1,66 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/set_ally_deck_in_og_gloom_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ group('SetAllyDeckInOgGloomCommand', () {
+ test('should set allyDeckInOGGloom to false', () {
+ SetAllyDeckInOgGloomCommand(
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().allyDeckInOGGloom, isFalse);
+ checkSaveState();
+ });
+
+ test('should set allyDeckInOGGloom to true', () {
+ SetAllyDeckInOgGloomCommand(
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ SetAllyDeckInOgGloomCommand(
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().allyDeckInOGGloom, isTrue);
+ checkSaveState();
+ });
+
+ test('describe when false returns no-ally string', () {
+ final command = SetAllyDeckInOgGloomCommand(
+ false,
+ gameState: getIt<GameState>(),
+ );
+ expect(
+ command.describe(),
+ 'No ally deck in 1st edition Gloomhaven campaigns',
+ );
+ });
+
+ test('describe when true returns use-ally string', () {
+ final command = SetAllyDeckInOgGloomCommand(
+ true,
+ gameState: getIt<GameState>(),
+ );
+ expect(
+ command.describe(),
+ 'Use Ally Deck in 1st edition Gloomhaven Campaigns',
+ );
+ });
+
+ test('undo does not throw', () {
+ final gs = getIt<GameState>();
+ gs.action(
+ SetAllyDeckInOgGloomCommand(true, gameState: getIt<GameState>()),
+ );
+ expect(() => gs.undo(), returnsNormally);
+ });
+ });
+}
diff --git a/server/test/command/set_as_summon_command_test.dart b/server/test/command/set_as_summon_command_test.dart
new file mode 100644
index 0000000..9bc4e64
--- /dev/null
+++ b/server/test/command/set_as_summon_command_test.dart
@@ -0,0 +1,90 @@
+// ignore_for_file: avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/commands/set_as_summon_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Monster monster;
+ late MonsterInstance monsterInstance;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ 'Ancient Artillery (FH)',
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ monsterInstance = monster.monsterInstances.first;
+ });
+
+ group('SetAsSummonCommand', () {
+ test('should mark a monster instance as summoned', () {
+ SetAsSummonCommand(
+ true,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(monsterInstance.roundSummoned, greaterThanOrEqualTo(1));
+ });
+
+ test('should clear summon mark when summoned is false', () {
+ SetAsSummonCommand(
+ true,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ SetAsSummonCommand(
+ false,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(monsterInstance.roundSummoned, -1);
+ });
+
+ test('describe when summoned is true mentions mark', () {
+ final command = SetAsSummonCommand(
+ true,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), contains('summon'));
+ });
+
+ test('describe when summoned is false mentions remove', () {
+ final command = SetAsSummonCommand(
+ false,
+ monsterInstance.getId(),
+ monster.id,
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), contains('Remove'));
+ });
+ });
+}
diff --git a/server/test/command/set_auto_level_adjust_command_test.dart b/server/test/command/set_auto_level_adjust_command_test.dart
new file mode 100644
index 0000000..d9cd253
--- /dev/null
+++ b/server/test/command/set_auto_level_adjust_command_test.dart
@@ -0,0 +1,51 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/set_auto_level_adjust_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ group('SetAutoLevelAdjustCommand', () {
+ test('should turn auto level adjust on', () {
+ final command = SetAutoLevelAdjustCommand(
+ true,
+ gameState: getIt<GameState>(),
+ );
+ command.execute();
+ expect(getIt<GameState>().autoScenarioLevel, isTrue);
+ checkSaveState();
+ });
+
+ test('should turn auto level adjust off', () {
+ SetAutoLevelAdjustCommand(true, gameState: getIt<GameState>()).execute();
+ final command = SetAutoLevelAdjustCommand(
+ false,
+ gameState: getIt<GameState>(),
+ );
+ command.execute();
+ expect(getIt<GameState>().autoScenarioLevel, isFalse);
+ checkSaveState();
+ });
+
+ test('describe should say "on" when enabled', () {
+ final command = SetAutoLevelAdjustCommand(
+ true,
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Turn automatic level update on');
+ });
+
+ test('describe should say "off" when disabled', () {
+ final command = SetAutoLevelAdjustCommand(
+ false,
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Turn automatic level update off');
+ });
+ });
+}
diff --git a/server/test/command/set_campaign_command_test.dart b/server/test/command/set_campaign_command_test.dart
new file mode 100644
index 0000000..1f214ed
--- /dev/null
+++ b/server/test/command/set_campaign_command_test.dart
@@ -0,0 +1,33 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/set_campaign_command.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ group('SetCampaignCommand', () {
+ test('should set campaign to Frosthaven', () {
+ final command = SetCampaignCommand('Frosthaven');
+ command.execute();
+ expect(getIt<GameState>().currentCampaign, 'Frosthaven');
+ checkSaveState();
+ });
+
+ test('should set campaign to Jaws of the Lion', () {
+ final command = SetCampaignCommand('Jaws of the Lion');
+ command.execute();
+ expect(getIt<GameState>().currentCampaign, 'Jaws of the Lion');
+ checkSaveState();
+ });
+
+ test('describe should return correct string', () {
+ final command = SetCampaignCommand('Frosthaven');
+ expect(command.describe(), 'Set Frosthaven campaign');
+ });
+ });
+}
diff --git a/server/test/command/set_character_level_command_test.dart b/server/test/command/set_character_level_command_test.dart
new file mode 100644
index 0000000..6faa86e
--- /dev/null
+++ b/server/test/command/set_character_level_command_test.dart
@@ -0,0 +1,48 @@
+// ignore_for_file: no-magic-number, avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/set_character_level_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Banner Spear', 'Frosthaven', 'BS', 1).execute();
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ });
+
+ group('SetCharacterLevelCommand', () {
+ test('should set character level', () {
+ final command = SetCharacterLevelCommand(3, character.id);
+ command.execute();
+ expect(character.characterState.level, 3);
+ checkSaveState();
+ });
+
+ test('should update max health when level changes', () {
+ final healthAtLevel1 = character.characterState.maxHealth;
+ SetCharacterLevelCommand(5, character.id).execute();
+ expect(
+ character.characterState.maxHealth,
+ greaterThanOrEqualTo(healthAtLevel1),
+ );
+ });
+
+ test('describe should include character id', () {
+ final command = SetCharacterLevelCommand(3, 'Blinkblade');
+ expect(command.describe(), "Set Blinkblade's Level");
+ });
+ });
+}
diff --git a/server/test/command/set_difficulty_command_test.dart b/server/test/command/set_difficulty_command_test.dart
new file mode 100644
index 0000000..d63571b
--- /dev/null
+++ b/server/test/command/set_difficulty_command_test.dart
@@ -0,0 +1,35 @@
+// ignore_for_file: no-magic-number
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/set_difficulty_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ group('SetDifficultyCommand', () {
+ test('should set difficulty to given value', () {
+ final command = SetDifficultyCommand(2, gameState: getIt<GameState>());
+ command.execute();
+ expect(getIt<GameState>().difficulty, 2);
+ checkSaveState();
+ });
+
+ test('should set difficulty to negative value', () {
+ final command = SetDifficultyCommand(-1, gameState: getIt<GameState>());
+ command.execute();
+ expect(getIt<GameState>().difficulty, -1);
+ checkSaveState();
+ });
+
+ test('describe should include difficulty level', () {
+ final command = SetDifficultyCommand(3, gameState: getIt<GameState>());
+ expect(command.describe(), 'Set difficulty level to 3');
+ });
+ });
+}
diff --git a/server/test/command/set_figure_note_command_test.dart b/server/test/command/set_figure_note_command_test.dart
new file mode 100644
index 0000000..835c8df
--- /dev/null
+++ b/server/test/command/set_figure_note_command_test.dart
@@ -0,0 +1,78 @@
+// ignore_for_file: avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/set_figure_note_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ GameState gs() => getIt<GameState>();
+ late Character character;
+
+ setUp(() {
+ gs().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', "Blinky", 1).execute();
+ character = gs().currentList.firstWhere((e) => e is Character) as Character;
+ });
+
+ group('SetFigureNoteCommand', () {
+ test(
+ 'sets a character note (on the shared base) and survives save/load',
+ () {
+ expect(character.note, '');
+ SetFigureNoteCommand(
+ 'poison next turn',
+ character.id,
+ gameState: gs(),
+ ).execute();
+
+ expect(character.note, 'poison next turn');
+ // Round-trips the whole game through toJson/fromJson and asserts the
+ // serialized state is unchanged, proving the note persists.
+ checkSaveState();
+ },
+ );
+
+ test('sets a monster note and survives save/load', () {
+ AddMonsterCommand("Zealot", 1, false, gameState: gs()).execute();
+ final monster =
+ gs().currentList.firstWhere((e) => e is Monster) as Monster;
+ expect(monster.note, '');
+
+ SetFigureNoteCommand(
+ 'focus first',
+ monster.id,
+ gameState: gs(),
+ ).execute();
+
+ expect(monster.note, 'focus first');
+ checkSaveState();
+ });
+
+ test('clears the note when set to empty', () {
+ SetFigureNoteCommand('temp', character.id, gameState: gs()).execute();
+ expect(character.note, 'temp');
+
+ SetFigureNoteCommand('', character.id, gameState: gs()).execute();
+ expect(character.note, '');
+ checkSaveState();
+ });
+
+ test('describe should return correct string', () {
+ final command = SetFigureNoteCommand(
+ 'note',
+ 'Blinkblade',
+ gameState: gs(),
+ );
+ expect(command.describe(), 'Set note for Blinkblade');
+ });
+ });
+}
diff --git a/server/test/command/set_init_command_test.dart b/server/test/command/set_init_command_test.dart
new file mode 100644
index 0000000..1637566
--- /dev/null
+++ b/server/test/command/set_init_command_test.dart
@@ -0,0 +1,53 @@
+// ignore_for_file: no-magic-number, avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/set_init_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Banner Spear', 'Frosthaven', 'BS', 1).execute();
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ });
+
+ group('SetInitCommand', () {
+ test('should set initiative for a character', () {
+ final command = SetInitCommand(
+ character.id,
+ 15,
+ gameState: getIt<GameState>(),
+ );
+ command.execute();
+ expect(character.characterState.initiative, 15);
+ checkSaveState();
+ });
+
+ test('should update initiative to a new value', () {
+ SetInitCommand(character.id, 10, gameState: getIt<GameState>()).execute();
+ SetInitCommand(character.id, 25, gameState: getIt<GameState>()).execute();
+ expect(character.characterState.initiative, 25);
+ });
+
+ test('describe should include character id', () {
+ final command = SetInitCommand(
+ 'Blinkblade',
+ 15,
+ gameState: getIt<GameState>(),
+ );
+ expect(command.describe(), 'Set initiative of Blinkblade');
+ });
+ });
+}
diff --git a/server/test/command/set_level_command_test.dart b/server/test/command/set_level_command_test.dart
new file mode 100644
index 0000000..3a2c1a8
--- /dev/null
+++ b/server/test/command/set_level_command_test.dart
@@ -0,0 +1,55 @@
+// ignore_for_file: no-magic-number
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/set_level_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ });
+
+ group('SetLevelCommand', () {
+ test('should set global level when monsterId is null', () {
+ final command = SetLevelCommand(3, null);
+ command.execute();
+ expect(getIt<GameState>().level, 3);
+ checkSaveState();
+ });
+
+ test('should set a specific monster level when monsterId is provided', () {
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+
+ SetLevelCommand(4, monster.id).execute();
+
+ expect(monster.level, 4);
+ checkSaveState();
+ });
+
+ test('describe without monsterId returns "Set Level"', () {
+ final command = SetLevelCommand(2, null);
+ expect(command.describe(), 'Set Level');
+ });
+
+ test('describe with monsterId includes monster name', () {
+ final command = SetLevelCommand(2, 'Ancient Artillery (FH)');
+ expect(command.describe(), "Set Ancient Artillery (FH)'s level");
+ });
+ });
+}
diff --git a/server/test/command/set_loot_owner_command_test.dart b/server/test/command/set_loot_owner_command_test.dart
new file mode 100644
index 0000000..00d95a9
--- /dev/null
+++ b/server/test/command/set_loot_owner_command_test.dart
@@ -0,0 +1,48 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/draw_loot_card_command.dart';
+import 'package:x_haven_server/core/commands/set_campaign_command.dart';
+import 'package:x_haven_server/core/commands/set_loot_owner_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'blinky', 1).execute();
+ SetCampaignCommand('Frosthaven').execute();
+ SetScenarioCommand(
+ 'custom',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ DrawLootCardCommand(gameState: getIt<GameState>()).execute();
+ });
+
+ group('SetLootOwnerCommand', () {
+ test('should set owner on the loot card', () {
+ final lootDeck = getIt<GameState>().lootDeck;
+ final card = lootDeck.discardPileTop;
+ expect(card.owner, isEmpty);
+
+ SetLootOwnerCommand('Blinkblade', card).execute();
+
+ expect(card.owner, 'Blinkblade');
+ checkSaveState();
+ });
+
+ test('describe returns correct string', () {
+ final lootDeck = getIt<GameState>().lootDeck;
+ final card = lootDeck.discardPileTop;
+ final command = SetLootOwnerCommand('Blinkblade', card);
+ expect(command.describe(), 'Set loot card owner');
+ });
+ });
+}
diff --git a/server/test/command/set_scenario_command_test.dart b/server/test/command/set_scenario_command_test.dart
new file mode 100644
index 0000000..cf6ebe2
--- /dev/null
+++ b/server/test/command/set_scenario_command_test.dart
@@ -0,0 +1,714 @@
+// ignore_for_file: no-magic-number
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/add_condition_command.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/change_stat_commands/change_xp_command.dart';
+import 'package:x_haven_server/core/commands/imbue_element_command.dart';
+import 'package:x_haven_server/core/commands/set_campaign_command.dart';
+import 'package:x_haven_server/core/commands/set_init_command.dart';
+import 'package:x_haven_server/core/commands/set_scenario_command.dart';
+import 'package:x_haven_server/core/commands/show_ally_deck_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/game_methods.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+// Test data availability:
+// JotL monsters: Zealot, Chaos Demon, Blood Tumor, Rat Monstrosity, Black Sludge, Vermling Raider
+// FH monsters: Ancient Artillery (FH)
+// JotL scenarios usable: #5 (Zealot/Chaos Demon/Blood Tumor), #6 (Rat Monstrosity/Black Sludge)
+// FH scenarios usable: #0 Howling in the Snow (Ancient Artillery FH), custom
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'apan', 1).execute();
+ SetCampaignCommand('Jaws of the Lion').execute();
+ });
+
+ // ---------------------------------------------------------------------------
+ // describe()
+ // ---------------------------------------------------------------------------
+ group('SetScenarioCommand describe()', () {
+ test('returns "Set Scenario" when section is false', () {
+ expect(
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).describe(),
+ 'Set Scenario',
+ );
+ });
+
+ test('returns "Add Section" when section is true', () {
+ expect(
+ SetScenarioCommand(
+ '#door',
+ true,
+ gameState: getIt<GameState>(),
+ ).describe(),
+ 'Add Section',
+ );
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // Basic scenario setup
+ // ---------------------------------------------------------------------------
+ group('SetScenarioCommand basic scenario setup', () {
+ test('sets scenario name on game state', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().scenario, '#5 A Deeper Understanding');
+ });
+
+ test('loads correct number of monsters and ability decks', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final gs = getIt<GameState>();
+ // #5 has Zealot, Chaos Demon, Blood Tumor
+ expect(gs.currentList.whereType<Monster>().length, 3);
+ expect(gs.currentAbilityDecks.length, 3);
+ checkSaveState();
+ });
+
+ test('round is reset to 1', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().round, 1);
+ });
+
+ test('totalRounds is reset to 1', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().totalRounds, 1);
+ });
+
+ test('round state is set to chooseInitiative', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().roundState, RoundState.chooseInitiative);
+ });
+
+ test('showAllyDeck is false for scenario with no AllyDeck rule', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().showAllyDeck, isFalse);
+ });
+
+ test('no loot deck for JotL scenario', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().lootDeck.drawPileSize, 0);
+ });
+
+ test('loot deck populated for Frosthaven scenario with loot', () {
+ SetCampaignCommand('Frosthaven').execute();
+ SetScenarioCommand(
+ '#0 Howling in the Snow',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().lootDeck.drawPileSize, greaterThan(0));
+ checkSaveState();
+ });
+
+ test('scenarioSectionsAdded is empty on fresh scenario', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().scenarioSectionsAdded, isEmpty);
+ });
+
+ test('scenarioSpecialRules is populated for scenario with rules', () {
+ // #6 has Allies and Objective rules
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().scenarioSpecialRules, isNotEmpty);
+ });
+
+ test('ability decks have cards in draw pile after scenario load', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ for (final deck in getIt<GameState>().currentAbilityDecks) {
+ expect(deck.drawPileIsNotEmpty, isTrue);
+ }
+ });
+
+ test('modifier deck discard pile is empty after scenario load', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().modifierDeck.discardPileIsEmpty, isTrue);
+ });
+
+ test('modifier deck draw pile is not empty after scenario load', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().modifierDeck.drawPileIsNotEmpty, isTrue);
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // Character state reset
+ // ---------------------------------------------------------------------------
+ group('SetScenarioCommand character state reset', () {
+ test('character initiative is reset to 0', () {
+ final character = getIt<GameState>().currentList.first as Character;
+ SetInitCommand(character.id, 42, gameState: getIt<GameState>()).execute();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final after = getIt<GameState>().currentList.first as Character;
+ expect(after.characterState.initiative, 0);
+ });
+
+ test('character xp is reset to 0', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final character = getIt<GameState>().currentList.first as Character;
+ ChangeXPCommand(
+ 10,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ // Load a different scenario to trigger reset
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final after =
+ getIt<GameState>().currentList.firstWhere(
+ (e) =>
+ e is Character &&
+ !GameMethods.isObjectiveOrEscort(e.characterClass),
+ )
+ as Character;
+ expect(after.characterState.xp, 0);
+ });
+
+ test('character conditions are cleared', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final character = getIt<GameState>().currentList.first as Character;
+ AddConditionCommand(
+ Condition.poison,
+ character.id,
+ character.id,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(character.characterState.conditions, contains(Condition.poison));
+
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ final after =
+ getIt<GameState>().currentList.firstWhere(
+ (e) =>
+ e is Character &&
+ !GameMethods.isObjectiveOrEscort(e.characterClass),
+ )
+ as Character;
+ expect(after.characterState.conditions, isEmpty);
+ });
+
+ test('character health is restored to max on reset', () {
+ final character = getIt<GameState>().currentList.first as Character;
+ final maxHp = character.characterState.maxHealth;
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final after = getIt<GameState>().currentList.first as Character;
+ expect(after.characterState.health, maxHp);
+ });
+
+ test('normal characters are preserved across scenario changes', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final characters = getIt<GameState>().currentList.whereType<Character>();
+ expect(
+ characters.any(
+ (c) => !GameMethods.isObjectiveOrEscort(c.characterClass),
+ ),
+ isTrue,
+ );
+ });
+
+ test('objectives from previous scenario are removed on new scenario', () {
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(
+ getIt<GameState>().currentList.any(
+ (item) =>
+ item is Character &&
+ GameMethods.isObjectiveOrEscort(item.characterClass),
+ ),
+ isTrue,
+ );
+
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(
+ getIt<GameState>().currentList.any(
+ (item) =>
+ item is Character &&
+ GameMethods.isObjectiveOrEscort(item.characterClass),
+ ),
+ isFalse,
+ );
+ });
+
+ test('previous scenario monsters are replaced on new scenario', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ // #5 has Zealot
+ expect(
+ getIt<GameState>().currentList.whereType<Monster>().any(
+ (m) => m.id == 'Zealot',
+ ),
+ isTrue,
+ );
+
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ // #6 has Rat Monstrosity and Black Sludge, not Zealot
+ expect(
+ getIt<GameState>().currentList.whereType<Monster>().any(
+ (m) => m.id == 'Zealot',
+ ),
+ isFalse,
+ reason: 'Zealot from #5 should not be present in #6',
+ );
+ expect(
+ getIt<GameState>().currentList.whereType<Monster>().any(
+ (m) => m.id == 'Rat Monstrosity',
+ ),
+ isTrue,
+ );
+ });
+
+ test('previous ability decks are replaced on new scenario', () {
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final decksAfterFirst = getIt<GameState>().currentAbilityDecks
+ .map((d) => d.name)
+ .toSet();
+
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final decksAfterSecond = getIt<GameState>().currentAbilityDecks
+ .map((d) => d.name)
+ .toSet();
+
+ expect(decksAfterSecond, isNot(equals(decksAfterFirst)));
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // Element reset
+ // ---------------------------------------------------------------------------
+ group('SetScenarioCommand element reset', () {
+ test('all elements are reset to inert on new scenario', () {
+ ImbueElementCommand(Elements.fire, false).execute();
+ ImbueElementCommand(Elements.ice, false).execute();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final elementState = getIt<GameState>().elementState;
+ for (final element in Elements.values) {
+ expect(
+ elementState[element],
+ ElementState.inert,
+ reason: '${element.name} should be inert',
+ );
+ }
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // Ally / Ally deck rules
+ // ---------------------------------------------------------------------------
+ group('SetScenarioCommand ally rules', () {
+ // #6 Corrupted Research (JotL): "Allies": ["Rat Monstrosity"]
+ test('monsters listed in Allies rule are marked isAlly', () {
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final ratMonstrosity = getIt<GameState>().currentList
+ .whereType<Monster>()
+ .firstWhere((m) => m.id == 'Rat Monstrosity');
+ expect(ratMonstrosity.isAlly, isTrue);
+ });
+
+ test('monsters not in Allies rule are not marked isAlly', () {
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final blackSludge = getIt<GameState>().currentList
+ .whereType<Monster>()
+ .firstWhere((m) => m.id == 'Black Sludge');
+ expect(blackSludge.isAlly, isFalse);
+ });
+
+ test(
+ 'shouldShowAlliesDeck returns true when allied monsters are present',
+ () {
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(GameMethods.shouldShowAlliesDeck(), isTrue);
+ },
+ );
+
+ test('showAllyDeck flag stays false when allies come from "Allies" rule '
+ 'rather than "AllyDeck" rule', () {
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ // The Allies rule marks monsters as isAlly but does NOT set showAllyDeck
+ expect(getIt<GameState>().showAllyDeck, isFalse);
+ });
+
+ test(
+ 'showAllyDeck is reset to false when loading a scenario without AllyDeck rule',
+ () {
+ // Start from a state where showAllyDeck is true (set manually via ShowAllyDeckCommand)
+ ShowAllyDeckCommand().execute();
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().showAllyDeck, isFalse);
+ },
+ );
+ });
+
+ // ---------------------------------------------------------------------------
+ // Objective special rule
+ // ---------------------------------------------------------------------------
+ group('SetScenarioCommand Objective special rule', () {
+ test('all 7 objectives from #6 Corrupted Research are added to list', () {
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final objectives = getIt<GameState>().currentList.where(
+ (item) =>
+ item is Character &&
+ GameMethods.isObjectiveOrEscort(item.characterClass),
+ );
+ expect(objectives.length, 7);
+ checkSaveState();
+ });
+
+ test('objective display names match scenario data (Growth 1–7)', () {
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final names = getIt<GameState>().currentList
+ .whereType<Character>()
+ .where((c) => GameMethods.isObjectiveOrEscort(c.characterClass))
+ .map((c) => c.characterState.display)
+ .toSet();
+ for (int i = 1; i <= 7; i++) {
+ expect(names, contains('Growth $i'));
+ }
+ });
+
+ test('objectives have positive health', () {
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ for (final obj
+ in getIt<GameState>().currentList.whereType<Character>().where(
+ (c) => GameMethods.isObjectiveOrEscort(c.characterClass),
+ )) {
+ expect(obj.characterState.health, greaterThan(0));
+ }
+ });
+
+ test('objectives are IsObjectiveOrEscort characters', () {
+ SetScenarioCommand(
+ '#6 Corrupted Research',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ for (final obj
+ in getIt<GameState>().currentList.whereType<Character>().where(
+ (c) => GameMethods.isObjectiveOrEscort(c.characterClass),
+ )) {
+ expect(GameMethods.isObjectiveOrEscort(obj.characterClass), isTrue);
+ }
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // undo() coverage
+ // ---------------------------------------------------------------------------
+ group('SetScenarioCommand undo', () {
+ test('undo does not throw', () {
+ final gs = getIt<GameState>();
+ gs.action(
+ SetScenarioCommand(
+ '#5 A Deeper Understanding',
+ false,
+ gameState: getIt<GameState>(),
+ ),
+ );
+ expect(() => gs.undo(), returnsNormally);
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // Custom scenarios
+ // ---------------------------------------------------------------------------
+ group('SetScenarioCommand custom scenarios', () {
+ test('Frosthaven custom scenario creates a loot deck', () {
+ SetCampaignCommand('Frosthaven').execute();
+ SetScenarioCommand(
+ 'custom',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().lootDeck.drawPileSize, greaterThan(0));
+ checkSaveState();
+ });
+
+ test('non-Frosthaven custom scenario has no loot deck', () {
+ SetCampaignCommand('Jaws of the Lion').execute();
+ SetScenarioCommand(
+ 'custom',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().lootDeck.drawPileSize, 0);
+ });
+
+ test('custom scenario has no monsters', () {
+ SetCampaignCommand('Frosthaven').execute();
+ SetScenarioCommand(
+ 'custom',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().currentList.whereType<Monster>(), isEmpty);
+ });
+
+ test('custom scenario has no ability decks', () {
+ SetCampaignCommand('Frosthaven').execute();
+ SetScenarioCommand(
+ 'custom',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().currentAbilityDecks, isEmpty);
+ });
+ });
+
+ // ---------------------------------------------------------------------------
+ // Sections
+ // Test data: FH '#0 Howling in the Snow' has one test section: '#0.1 The Frozen Depths'
+ // ---------------------------------------------------------------------------
+ group('SetScenarioCommand sections', () {
+ const String baseScenario = '#0 Howling in the Snow';
+ const String sectionName = '#0.1 The Frozen Depths';
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Blinkblade', 'Frosthaven', 'apan', 1).execute();
+ SetCampaignCommand('Frosthaven').execute();
+ SetScenarioCommand(
+ baseScenario,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ });
+
+ test('section name is tracked in scenarioSectionsAdded', () {
+ SetScenarioCommand(
+ sectionName,
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().scenarioSectionsAdded, contains(sectionName));
+ checkSaveState();
+ });
+
+ test('adding the same section twice records it twice', () {
+ SetScenarioCommand(
+ sectionName,
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+ SetScenarioCommand(
+ sectionName,
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(
+ getIt<GameState>().scenarioSectionsAdded
+ .where((s) => s == sectionName)
+ .length,
+ 2,
+ );
+ });
+
+ test(
+ 'scenarioSectionsAdded is cleared when a new base scenario is loaded',
+ () {
+ SetScenarioCommand(
+ sectionName,
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().scenarioSectionsAdded, isNotEmpty);
+
+ SetScenarioCommand(
+ '#0 Howling in the Snow',
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(getIt<GameState>().scenarioSectionsAdded, isEmpty);
+ },
+ );
+
+ test('adding a section does not remove previously-added monsters', () {
+ // Manually add a known monster after loading the base scenario
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final monstersBefore = getIt<GameState>().currentList
+ .whereType<Monster>()
+ .length;
+
+ SetScenarioCommand(
+ sectionName,
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+
+ expect(
+ getIt<GameState>().currentList.whereType<Monster>().length,
+ greaterThanOrEqualTo(monstersBefore),
+ );
+ });
+
+ test('section does not reset round or scenario name', () {
+ final roundBefore = getIt<GameState>().round;
+ final scenarioBefore = getIt<GameState>().scenario;
+ SetScenarioCommand(
+ sectionName,
+ true,
+ gameState: getIt<GameState>(),
+ ).execute();
+ expect(getIt<GameState>().round, roundBefore);
+ expect(getIt<GameState>().scenario, scenarioBefore);
+ });
+ });
+}
diff --git a/server/test/command/set_solo_command_test.dart b/server/test/command/set_solo_command_test.dart
new file mode 100644
index 0000000..3ac9c21
--- /dev/null
+++ b/server/test/command/set_solo_command_test.dart
@@ -0,0 +1,39 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/set_solo_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ group('SetSoloCommand', () {
+ test('should set solo to true', () {
+ final command = SetSoloCommand(true);
+ command.execute();
+ expect(getIt<GameState>().solo, isTrue);
+ checkSaveState();
+ });
+
+ test('should set solo to false', () {
+ SetSoloCommand(true).execute();
+ final command = SetSoloCommand(false);
+ command.execute();
+ expect(getIt<GameState>().solo, isFalse);
+ checkSaveState();
+ });
+
+ test('describe should return solo recommendation string when true', () {
+ final command = SetSoloCommand(true);
+ expect(command.describe(), 'Set solo level recommendation on');
+ });
+
+ test('describe should return regular recommendation string when false', () {
+ final command = SetSoloCommand(false);
+ expect(command.describe(), 'Set solo level recommendation off');
+ });
+ });
+}
diff --git a/server/test/command/show_ally_deck_command_test.dart b/server/test/command/show_ally_deck_command_test.dart
new file mode 100644
index 0000000..d1652ea
--- /dev/null
+++ b/server/test/command/show_ally_deck_command_test.dart
@@ -0,0 +1,45 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/hide_ally_deck_command.dart';
+import 'package:x_haven_server/core/commands/show_ally_deck_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ group('ShowAllyDeckCommand', () {
+ test('should set showAllyDeck to true', () {
+ HideAllyDeckCommand().execute();
+ expect(getIt<GameState>().showAllyDeck, isFalse);
+
+ ShowAllyDeckCommand().execute();
+
+ expect(getIt<GameState>().showAllyDeck, isTrue);
+ checkSaveState();
+ });
+
+ test('describe should return correct string', () {
+ expect(ShowAllyDeckCommand().describe(), 'Show Ally Deck');
+ });
+ });
+
+ group('HideAllyDeckCommand', () {
+ test('should set showAllyDeck to false', () {
+ ShowAllyDeckCommand().execute();
+ expect(getIt<GameState>().showAllyDeck, isTrue);
+
+ HideAllyDeckCommand().execute();
+
+ expect(getIt<GameState>().showAllyDeck, isFalse);
+ checkSaveState();
+ });
+
+ test('describe should return correct string', () {
+ expect(HideAllyDeckCommand().describe(), 'Hide Ally Deck');
+ });
+ });
+}
diff --git a/server/test/command/shuffle_ability_card_command_test.dart b/server/test/command/shuffle_ability_card_command_test.dart
new file mode 100644
index 0000000..10eee0d
--- /dev/null
+++ b/server/test/command/shuffle_ability_card_command_test.dart
@@ -0,0 +1,93 @@
+// ignore_for_file: avoid-late-keyword, avoid-non-null-assertion
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/draw_ability_card_command.dart';
+import 'package:x_haven_server/core/commands/shuffle_ability_card_command.dart';
+import 'package:x_haven_server/core/commands/shuffle_amd_card_command.dart';
+import 'package:x_haven_server/core/commands/shuffle_drawn_ability_card_command.dart';
+import 'package:x_haven_server/core/game_methods.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Monster monster;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ });
+
+ group('ShuffleAbilityCardCommand', () {
+ test('should shuffle ability deck (discard into draw pile)', () {
+ // Draw some cards into discard
+ DrawAbilityCardCommand(monster.id).execute();
+ DrawAbilityCardCommand(monster.id).execute();
+ final deck = GameMethods.getDeck(monster.type.deck)!;
+ expect(deck.discardPileIsNotEmpty, isTrue);
+
+ ShuffleAbilityCardCommand(monster.id).execute();
+
+ expect(deck.discardPileContents, isEmpty);
+ checkSaveState();
+ });
+
+ test('describe returns correct string', () {
+ expect(
+ ShuffleAbilityCardCommand(monster.id).describe(),
+ 'Extra ability deck shuffle',
+ );
+ });
+ });
+
+ group('ShuffleDrawnAbilityCardCommand', () {
+ test('should shuffle only undrawn part of ability deck', () {
+ final deck = GameMethods.getDeck(monster.type.deck)!;
+ final totalBefore = deck.drawPileSize + deck.discardPileSize;
+
+ ShuffleDrawnAbilityCardCommand(monster.type.deck).execute();
+
+ final totalAfter = deck.drawPileSize + deck.discardPileSize;
+ expect(totalAfter, totalBefore);
+ });
+
+ test('describe returns correct string', () {
+ expect(
+ ShuffleDrawnAbilityCardCommand(monster.type.deck).describe(),
+ 'Drawn ability deck shuffle',
+ );
+ });
+ });
+
+ group('ShuffleAMDCardCommand', () {
+ test('describe returns correct string', () {
+ expect(
+ ShuffleAMDCardCommand('', gameState: getIt<GameState>()).describe(),
+ 'Extra AMD deck shuffle',
+ );
+ });
+
+ test('should shuffle modifier deck draw pile', () {
+ final deck = getIt<GameState>().modifierDeck;
+ final sizeBefore = deck.drawPileSize;
+
+ ShuffleAMDCardCommand('', gameState: getIt<GameState>()).execute();
+
+ expect(deck.drawPileSize, sizeBefore);
+ });
+ });
+}
diff --git a/server/test/command/test_helpers.dart b/server/test/command/test_helpers.dart
new file mode 100644
index 0000000..67e6f16
--- /dev/null
+++ b/server/test/command/test_helpers.dart
@@ -0,0 +1,56 @@
+// ignore_for_file: no-magic-number, avoid-late-keyword, avoid-top-level-members-in-tests
+
+import 'dart:convert';
+
+import 'package:x_haven_server/core/game_data.dart';
+import 'package:x_haven_server/core/save_store.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:json_diff/json_diff.dart';
+
+late final GameState gameState;
+
+/// Bootstraps the headless engine with the test data set.
+///
+/// Mirror of the reference app's `setUpGame()`: registers the core
+/// singletons with an in-memory save store, initializes the game state, loads
+/// the test data from `assets/testData/`, and restores the (empty) save.
+Future<void> setUpGame() async {
+ setupCore(saveStore: InMemorySaveStore());
+ gameState = getIt<GameState>();
+ //initialize game
+ gameState.init();
+ await getIt<GameData>().loadData('assets/testData/');
+ gameState.load();
+}
+
+void checkSaveState() {
+ String state = gameState.toString();
+ int nrStates = gameState.gameSaveStates.length;
+ gameState.save();
+ gameState.load();
+ String newState = gameState.toString();
+ assert(
+ gameState.gameSaveStates.length == nrStates + 2,
+ ); //for some reason a null state is added on load.
+ assert(newState == state);
+}
+
+void checkNoSideEffects(List<String> changedFields, String oldState) {
+ final differ = JsonDiffer.fromJson(
+ json.decode(oldState),
+ json.decode(gameState.toString()),
+ );
+ DiffNode diff = differ.diff();
+
+ diff.forEach((s, dn) {
+ print("for each");
+ print(s);
+ assert(changedFields.contains(s));
+ print(dn.added);
+ print(dn.moved);
+ print(dn.removed);
+ print(dn.changed);
+ print(dn.node);
+ });
+}
diff --git a/server/test/command/track_standees_command_test.dart b/server/test/command/track_standees_command_test.dart
new file mode 100644
index 0000000..cb4e0b4
--- /dev/null
+++ b/server/test/command/track_standees_command_test.dart
@@ -0,0 +1,97 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_monster_command.dart';
+import 'package:x_haven_server/core/commands/add_standee_command.dart';
+import 'package:x_haven_server/core/commands/track_standees_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/settings.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ getIt<Settings>().noStandees = false;
+ });
+
+ group('TrackStandeesCommand', () {
+ test('should set noStandees to true when track is false', () {
+ TrackStandeesCommand(
+ false,
+ gameState: getIt<GameState>(),
+ settings: getIt<Settings>(),
+ ).execute();
+ expect(getIt<Settings>().noStandees, isTrue);
+ });
+
+ test('should set noStandees to false when track is true', () {
+ TrackStandeesCommand(
+ false,
+ gameState: getIt<GameState>(),
+ settings: getIt<Settings>(),
+ ).execute();
+ TrackStandeesCommand(
+ true,
+ gameState: getIt<GameState>(),
+ settings: getIt<Settings>(),
+ ).execute();
+ expect(getIt<Settings>().noStandees, isFalse);
+ });
+
+ test('should clear monster instances when switching to no-track mode', () {
+ AddMonsterCommand(
+ 'Ancient Artillery (FH)',
+ 1,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ AddStandeeCommand(
+ 1,
+ null,
+ 'Ancient Artillery (FH)',
+ MonsterType.normal,
+ false,
+ gameState: getIt<GameState>(),
+ ).execute();
+ final monster =
+ getIt<GameState>().currentList.firstWhere((e) => e is Monster)
+ as Monster;
+ expect(monster.monsterInstances, isNotEmpty);
+
+ TrackStandeesCommand(
+ false,
+ gameState: getIt<GameState>(),
+ settings: getIt<Settings>(),
+ ).execute();
+
+ expect(monster.monsterInstances, isEmpty);
+ });
+
+ test('describe returns correct string when track is false', () {
+ expect(
+ TrackStandeesCommand(
+ false,
+ gameState: getIt<GameState>(),
+ settings: getIt<Settings>(),
+ ).describe(),
+ "Don't track standees",
+ );
+ });
+
+ test('describe returns correct string when track is true', () {
+ expect(
+ TrackStandeesCommand(
+ true,
+ gameState: getIt<GameState>(),
+ settings: getIt<Settings>(),
+ ).describe(),
+ 'Track standees',
+ );
+ });
+ });
+}
diff --git a/server/test/command/use_element_command_test.dart b/server/test/command/use_element_command_test.dart
new file mode 100644
index 0000000..f4434e9
--- /dev/null
+++ b/server/test/command/use_element_command_test.dart
@@ -0,0 +1,40 @@
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/imbue_element_command.dart';
+import 'package:x_haven_server/core/commands/use_element_command.dart';
+import 'package:x_haven_server/core/enums.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ group('UseElementCommand', () {
+ test('should set element state to inert', () {
+ ImbueElementCommand(Elements.fire, false).execute();
+ expect(getIt<GameState>().elementState[Elements.fire], ElementState.full);
+
+ UseElementCommand(Elements.fire).execute();
+
+ expect(
+ getIt<GameState>().elementState[Elements.fire],
+ ElementState.inert,
+ );
+ checkSaveState();
+ });
+
+ test('should work on any element', () {
+ ImbueElementCommand(Elements.ice, false).execute();
+ UseElementCommand(Elements.ice).execute();
+ expect(getIt<GameState>().elementState[Elements.ice], ElementState.inert);
+ });
+
+ test('describe should include element name', () {
+ final command = UseElementCommand(Elements.earth);
+ expect(command.describe(), 'Use Element earth');
+ });
+ });
+}
diff --git a/server/test/command/use_fh_perks_command_test.dart b/server/test/command/use_fh_perks_command_test.dart
new file mode 100644
index 0000000..3b19ce8
--- /dev/null
+++ b/server/test/command/use_fh_perks_command_test.dart
@@ -0,0 +1,50 @@
+// ignore_for_file: avoid-late-keyword
+
+import 'package:test/test.dart';
+import 'package:x_haven_server/core/commands/add_character_command.dart';
+import 'package:x_haven_server/core/commands/use_fh_perks_command.dart';
+import 'package:x_haven_server/core/state/game_state.dart';
+import 'package:x_haven_server/core/service_locator.dart';
+
+import 'test_helpers.dart';
+
+void main() {
+ setUpAll(() async {
+ await setUpGame();
+ });
+
+ late Character character;
+
+ setUp(() {
+ getIt<GameState>().clearList();
+ AddCharacterCommand('Banner Spear', 'Frosthaven', 'BS', 1).execute();
+ character =
+ getIt<GameState>().currentList.firstWhere((e) => e is Character)
+ as Character;
+ });
+
+ group('UseFHPerksCommand', () {
+ test('should toggle useFHPerks from false to true', () {
+ expect(character.characterState.useFHPerks, isFalse);
+
+ UseFHPerksCommand(character.id).execute();
+
+ expect(character.characterState.useFHPerks, isTrue);
+ checkSaveState();
+ });
+
+ test('should toggle useFHPerks from true to false', () {
+ UseFHPerksCommand(character.id).execute();
+ expect(character.characterState.useFHPerks, isTrue);
+
+ UseFHPerksCommand(character.id).execute();
+
+ expect(character.characterState.useFHPerks, isFalse);
+ });
+
+ test('describe should include character id', () {
+ final command = UseFHPerksCommand(character.id);
+ expect(command.describe(), contains(character.id));
+ });
+ });
+}