diff options
Diffstat (limited to 'server/test/command/add_monster_command_test.dart')
| -rw-r--r-- | server/test/command/add_monster_command_test.dart | 95 |
1 files changed, 95 insertions, 0 deletions
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'); + }); + }); +} |
