summaryrefslogtreecommitdiff
path: root/server/test/command/next_turn_command_test.dart
blob: 89c09814f20e665e77f69c3955cd8d98828bd7cd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
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");
    });
  });
}