summaryrefslogtreecommitdiff
path: root/server/test/command/unlock_special_command_test.dart
blob: 282f4f99b613a056e3d42e8bfbfc19042ad7413c (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
import 'package:test/test.dart';
import 'package:x_haven_server/core/commands/unlock_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();
  });

  // The command toggles, so normalize: start every test with "Demons"
  // locked.
  setUp(() {
    final gs = getIt<GameState>();
    if (gs.unlockedClasses.contains('Demons')) {
      UnlockSpecialCommand('Demons', gameState: gs).execute();
    }
  });

  group('UnlockSpecialCommand', () {
    test('should unlock a special that is not unlocked yet', () {
      final gs = getIt<GameState>();
      expect(gs.unlockedClasses.contains('Demons'), isFalse);

      UnlockSpecialCommand('Demons', gameState: gs).execute();

      expect(gs.unlockedClasses.contains('Demons'), isTrue);
      checkSaveState();
    });

    test('should re-lock a special that is already unlocked', () {
      final gs = getIt<GameState>();
      UnlockSpecialCommand('Demons', gameState: gs).execute();
      expect(gs.unlockedClasses.contains('Demons'), isTrue);

      UnlockSpecialCommand('Demons', gameState: gs).execute();

      expect(gs.unlockedClasses.contains('Demons'), isFalse);
      checkSaveState();
    });

    test('describe should return correct strings', () {
      final gs = getIt<GameState>();

      final unlock = UnlockSpecialCommand('Demons', gameState: gs);
      expect(unlock.describe(), 'Unlock Demons');
      unlock.execute();
      expect(unlock.describe(), 'Unlock Demons');

      final lock = UnlockSpecialCommand('Demons', gameState: gs);
      lock.execute();
      expect(lock.describe(), 'Lock Demons');
    });
  });
}