summaryrefslogtreecommitdiff
path: root/server/test/command/enhance_loot_card_command_test.dart
blob: 73ebc3b90f3d624fe15cc92c3a2a6270ffc94d3f (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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',
        );
      },
    );
  });
}