dyo-tools 0.1.0-rc2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/.c8rc.json +4 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.json +47 -0
  4. package/LICENSE +21 -0
  5. package/Makefile +34 -0
  6. package/README.md +0 -7
  7. package/babel.config.js +1 -0
  8. package/cucumber-report.html +48 -0
  9. package/cucumber.js +9 -0
  10. package/dist/constants.d.ts +6 -0
  11. package/dist/constants.js +63 -0
  12. package/dist/constants.js.map +1 -0
  13. package/dist/core/DTBunch.d.ts +11 -15
  14. package/dist/core/DTBunch.js +27 -106
  15. package/dist/core/DTBunch.js.map +1 -1
  16. package/dist/core/DTComponent.d.ts +13 -5
  17. package/dist/core/DTComponent.js +39 -1
  18. package/dist/core/DTComponent.js.map +1 -1
  19. package/dist/core/DTComponentPhysical.d.ts +10 -0
  20. package/dist/core/DTComponentPhysical.js +16 -0
  21. package/dist/core/DTComponentPhysical.js.map +1 -0
  22. package/dist/core/DTComponentWithMeta.d.ts +2 -2
  23. package/dist/core/DTComponentWithMeta.js.map +1 -1
  24. package/dist/core/DTElement.d.ts +2 -7
  25. package/dist/core/DTElement.js +3 -12
  26. package/dist/core/DTElement.js.map +1 -1
  27. package/dist/core/DTManager.d.ts +31 -0
  28. package/dist/core/DTManager.js +180 -0
  29. package/dist/core/DTManager.js.map +1 -0
  30. package/dist/core/DTPlayer.js +1 -1
  31. package/dist/core/DTPlayer.js.map +1 -1
  32. package/dist/index.d.ts +2 -0
  33. package/dist/index.js +5 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/libs/DYOFinder.d.ts +10 -0
  36. package/dist/libs/DYOFinder.js +96 -0
  37. package/dist/libs/DYOFinder.js.map +1 -0
  38. package/dist/tsconfig.tsbuildinfo +1 -1321
  39. package/dist/types/index.d.ts +64 -24
  40. package/dist/types/index.js.map +1 -1
  41. package/docs/.nojekyll +1 -0
  42. package/docs/assets/highlight.css +29 -0
  43. package/docs/assets/main.js +58 -0
  44. package/docs/assets/search.js +1 -0
  45. package/docs/assets/style.css +1367 -0
  46. package/docs/index.html +46 -0
  47. package/e2e/0.2.0/epic1.feature +29 -0
  48. package/e2e/0.2.0/epic2.feature +22 -0
  49. package/e2e/0.2.0/epic3.feature +25 -0
  50. package/e2e/0.2.0/resources/dominion.js +195 -0
  51. package/e2e/0.2.0/resources/utils.js +27 -0
  52. package/e2e/0.2.0/support/steps.js +108 -0
  53. package/e2e/future/epic4.feature +39 -0
  54. package/e2e/future/resources/dominion.js +238 -0
  55. package/e2e/future/resources/utils.js +27 -0
  56. package/jest.config.js +6 -0
  57. package/package.json +33 -23
  58. package/src/constants.ts +85 -0
  59. package/src/core/DTBunch.ts +461 -0
  60. package/src/core/DTComponent.ts +225 -0
  61. package/src/core/DTComponentPhysical.ts +39 -0
  62. package/src/core/DTComponentWithMeta.ts +65 -0
  63. package/src/core/DTElement.ts +69 -0
  64. package/src/core/DTError.ts +78 -0
  65. package/src/core/DTManager.ts +446 -0
  66. package/src/core/DTPlayer.ts +57 -0
  67. package/src/index.ts +9 -0
  68. package/src/libs/DYOFinder.ts +175 -0
  69. package/src/types/index.ts +162 -0
  70. package/test/core/DTBunch.double.ts +253 -0
  71. package/test/core/DTBunch.spec.ts +895 -0
  72. package/test/core/DTComponent.double.ts +164 -0
  73. package/test/core/DTComponent.spec.ts +295 -0
  74. package/test/core/DTComponentPhysical.double.ts +76 -0
  75. package/test/core/DTComponentPhysical.spec.ts +64 -0
  76. package/test/core/DTComponentWithMeta.double.ts +115 -0
  77. package/test/core/DTComponentWithMeta.spec.ts +124 -0
  78. package/test/core/DTElement.double.ts +147 -0
  79. package/test/core/DTElement.spec.ts +102 -0
  80. package/test/core/DTError.double.ts +92 -0
  81. package/test/core/DTError.spec.ts +89 -0
  82. package/test/core/DTManager.double.ts +192 -0
  83. package/test/core/DTManager.spec.ts +902 -0
  84. package/test/core/DTPlayer.double.ts +64 -0
  85. package/test/core/DTPlayer.spec.ts +80 -0
  86. package/test/core/copy.spec.ts +227 -0
  87. package/test/libs/DYOFinder.double.ts +152 -0
  88. package/test/libs/DYOFinder.spec.ts +194 -0
  89. package/tsconfig.dev.json +22 -0
  90. package/tsconfig.json +21 -0
  91. package/dist/utils/filters.d.ts +0 -6
  92. package/dist/utils/filters.js +0 -39
  93. package/dist/utils/filters.js.map +0 -1
@@ -0,0 +1,46 @@
1
+ <!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>dyo-tools</title><meta name="description" content="Documentation for dyo-tools"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/search.js" id="tsd-search-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os"</script><header class="tsd-page-toolbar">
2
+ <div class="tsd-toolbar-contents container">
3
+ <div class="table-cell" id="tsd-search" data-base=".">
4
+ <div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><path d="M15.7824 13.833L12.6666 10.7177C12.5259 10.5771 12.3353 10.499 12.1353 10.499H11.6259C12.4884 9.39596 13.001 8.00859 13.001 6.49937C13.001 2.90909 10.0914 0 6.50048 0C2.90959 0 0 2.90909 0 6.49937C0 10.0896 2.90959 12.9987 6.50048 12.9987C8.00996 12.9987 9.39756 12.4863 10.5008 11.6239V12.1332C10.5008 12.3332 10.5789 12.5238 10.7195 12.6644L13.8354 15.7797C14.1292 16.0734 14.6042 16.0734 14.8948 15.7797L15.7793 14.8954C16.0731 14.6017 16.0731 14.1267 15.7824 13.833ZM6.50048 10.499C4.29094 10.499 2.50018 8.71165 2.50018 6.49937C2.50018 4.29021 4.28781 2.49976 6.50048 2.49976C8.71001 2.49976 10.5008 4.28708 10.5008 6.49937C10.5008 8.70852 8.71314 10.499 6.50048 10.499Z" fill="var(--color-text)"></path></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div>
5
+ <div class="field">
6
+ <div id="tsd-toolbar-links"></div></div>
7
+ <ul class="results">
8
+ <li class="state loading">Preparing search index...</li>
9
+ <li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">dyo-tools</a></div>
10
+ <div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><rect x="1" y="3" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="7" width="14" height="2" fill="var(--color-text)"></rect><rect x="1" y="11" width="14" height="2" fill="var(--color-text)"></rect></svg></a></div></div></header>
11
+ <div class="container container-main">
12
+ <div class="col-content">
13
+ <div class="tsd-page-title">
14
+ <h2>dyo-tools</h2></div>
15
+ <div class="tsd-panel tsd-typography"></div></div>
16
+ <div class="col-sidebar">
17
+ <div class="page-menu">
18
+ <div class="tsd-navigation settings">
19
+ <details class="tsd-index-accordion"><summary class="tsd-accordion-summary">
20
+ <h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><path d="M4.93896 8.531L12 15.591L19.061 8.531L16.939 6.409L12 11.349L7.06098 6.409L4.93896 8.531Z" fill="var(--color-text)" id="icon-chevronDown"></path></svg>Settings</h3></summary>
21
+ <div class="tsd-accordion-details">
22
+ <div class="tsd-filter-visibility">
23
+ <h4 class="uppercase">Member Visibility</h4><form>
24
+ <ul id="tsd-filter-options">
25
+ <li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li>
26
+ <li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li>
27
+ <li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li>
28
+ <li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></form></div>
29
+ <div class="tsd-theme-toggle">
30
+ <h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div>
31
+ <div class="site-menu">
32
+ <nav class="tsd-navigation"><a href="index.html" class="current"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><g id="icon-4"><rect fill="var(--color-icon-background)" stroke="var(--color-ts-namespace)" stroke-width="1.5" x="1" y="1" width="22" height="22" rx="6"></rect><path d="M9.33 16V7.24H10.77L13.446 14.74C13.43 14.54 13.41 14.296 13.386 14.008C13.37 13.712 13.354 13.404 13.338 13.084C13.33 12.756 13.326 12.448 13.326 12.16V7.24H14.37V16H12.93L10.266 8.5C10.282 8.692 10.298 8.936 10.314 9.232C10.33 9.52 10.342 9.828 10.35 10.156C10.366 10.476 10.374 10.784 10.374 11.08V16H9.33Z" fill="var(--color-text)"></path></g></svg><span>dyo-<wbr/>tools</span></a>
33
+ <ul class="tsd-small-nested-navigation">
34
+ <li><a href="modules/core_DTBunch.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>core/DTBunch</span></a></li>
35
+ <li><a href="modules/core_DTComponent.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>core/DTComponent</span></a></li>
36
+ <li><a href="modules/core_DTComponentPhysical.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>core/DTComponent<wbr/>Physical</span></a></li>
37
+ <li><a href="modules/core_DTComponentWithMeta.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>core/DTComponent<wbr/>With<wbr/>Meta</span></a></li>
38
+ <li><a href="modules/core_DTElement.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>core/DTElement</span></a></li>
39
+ <li><a href="modules/core_DTError.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>core/DTError</span></a></li>
40
+ <li><a href="modules/core_DTManager.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>core/DTManager</span></a></li>
41
+ <li><a href="modules/core_DTPlayer.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>core/DTPlayer</span></a></li>
42
+ <li><a href="modules/libs_DYOFinder.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>libs/DYOFinder</span></a></li>
43
+ <li><a href="modules/types.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="#icon-4"></use></svg><span>types</span></a></li></ul></nav></div></div></div>
44
+ <div class="tsd-generator">
45
+ <p>Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></div>
46
+ <div class="overlay"></div></body></html>
@@ -0,0 +1,29 @@
1
+ Feature: Epic 1 - Manager and bunches
2
+
3
+ Scenario: Store of bunches
4
+ Given my empty manager
5
+ When I add 5 physical bunches and 2 virtual bunches
6
+ Then I should have 7 bunches in my manager
7
+
8
+ Scenario: No duplicated bunches
9
+ Given my dominion manager
10
+ When I add an already existing bunch
11
+ Then I should see an error "id_conflict"
12
+
13
+ Scenario: Easy finding of bunch
14
+ Given my dominion manager
15
+ Then I should find my current hand
16
+ And I should find 2 bunches with
17
+ | key | hand |
18
+ And I should find 5 bunches with
19
+ | owner | PRIAM |
20
+ And I should find 2 bunches with
21
+ | cost | 4 |
22
+
23
+ Scenario: Bunch removal
24
+ Given my dominion manager
25
+ When I remove my current hand
26
+ Then I shouldn't find my current hand
27
+ And I should find 1 bunches with
28
+ | key | hand |
29
+
@@ -0,0 +1,22 @@
1
+ Feature: Epic 2 - Manager and Library
2
+
3
+ Scenario: Store of all elements
4
+ Given my dominion manager
5
+ Then I should have 104 elements in my library
6
+
7
+ Scenario: Autodetect already existing element
8
+ Given my dominion manager
9
+ When I add a new trash pile with 2 already existing elements into the scope "default"
10
+ Then I should have 107 elements in my library
11
+
12
+ Scenario: Library isn't a manager bunch
13
+ Given my dominion manager
14
+ Then I shouldn't find my library id into bunches
15
+
16
+ Scenario: Auto adding new element in bunch
17
+ Given my dominion manager
18
+ When I add a new external card in my current hand
19
+ Then I should have 105 elements in my library
20
+
21
+
22
+
@@ -0,0 +1,25 @@
1
+ Feature: Epic 3 - Manager and Scopes
2
+
3
+ Scenario: Scope configuration
4
+ Given my dominion manager
5
+ Then I should have 7 scopes in my manager
6
+ And I should have 9 bunches in my scope "supply"
7
+
8
+ Scenario: Adding bunch into a scope
9
+ Given my dominion manager
10
+ When I add a new trash pile with 2 already existing elements into the scope "supply"
11
+ Then I should have 10 bunches in my scope "supply"
12
+
13
+ Scenario: No adding in non-declared scope
14
+ Given my dominion manager
15
+ When I add a new trash pile with 2 already existing elements into the scope "trash"
16
+ Then I should see an error "invalid_scope"
17
+
18
+ Scenario: Moving bunch through scopes
19
+ Given my dominion manager
20
+ When I move my current hand to the scope "supply"
21
+ Then I should have 10 bunches in my scope "supply"
22
+ And I should have 1 bunches in my scope "hand"
23
+
24
+
25
+
@@ -0,0 +1,195 @@
1
+ const {DTElement, DTManager, DTBunch, DTPlayer} = require("../../../dist/src");
2
+
3
+ /****************** CARDS REFERENCE ************************/
4
+ const cards = {
5
+ "COPPER": {
6
+ meta: {
7
+ type: 'treasure',
8
+ cost: 0,
9
+ treasurePoints: 1
10
+ },
11
+ events: {
12
+ play: (ctx) => {
13
+ ctx.getOwner.setMeta('coin', 1);
14
+ }
15
+ }
16
+ },
17
+ "SILVER": {
18
+ meta: {
19
+ type: 'treasure',
20
+ cost: 3,
21
+ treasurePoints: 2
22
+ },
23
+ events: {
24
+ play: (ctx) => {
25
+ ctx.getOwner.setMeta('coin', 2);
26
+ }
27
+ }
28
+ },
29
+ "GOLD": {
30
+ meta: {
31
+ type: 'treasure',
32
+ cost: 6,
33
+ treasurePoints: 3
34
+ },
35
+ events: {
36
+ play: (ctx) => {
37
+ ctx.getOwner.setMeta('coin', 3);
38
+ }
39
+ }
40
+ },
41
+ "ESTATE": {
42
+ meta: {
43
+ type: 'victory',
44
+ cost: 2,
45
+ victoryPoints: 1
46
+ }
47
+ },
48
+ "DUCHY": {
49
+ meta: {
50
+ type: 'victory',
51
+ cost: 5,
52
+ treasurePoints: 3
53
+ }
54
+ },
55
+ "PROVINCE": {
56
+ meta: {
57
+ type: 'victory',
58
+ cost: 8,
59
+ treasurePoints: 6
60
+ }
61
+ },
62
+ "SMITHY": {
63
+ meta: {
64
+ type: 'action',
65
+ cost: 4,
66
+ }
67
+ },
68
+ "WORKSHOP": {
69
+ meta: {
70
+ type: 'action',
71
+ cost: 3,
72
+ }
73
+ },
74
+ "MILITIA": {
75
+ meta: {
76
+ type: 'action',
77
+ cost: 4,
78
+ }
79
+ },
80
+ }
81
+
82
+ /****************** BUILDERS ************************/
83
+
84
+ const buildCard = (key) => {
85
+ const element = new DTElement(key);
86
+ element.setManyMeta(cards[key].meta);
87
+ return element;
88
+ }
89
+
90
+ const duplicateCard = (card, nb) => {
91
+ const items = [card];
92
+ let i = 1;
93
+ while (i <= nb) {
94
+ items.push(card.copy());
95
+ i++;
96
+ }
97
+ return items;
98
+ }
99
+
100
+ const initializeDominionManager = () => {
101
+ const scopes = [
102
+ 'supply',
103
+ 'hand',
104
+ 'playZone',
105
+ 'discard',
106
+ 'deck'
107
+ ];
108
+ const library = [
109
+ ...duplicateCard(buildCard('COPPER'), 13),
110
+ ...duplicateCard(buildCard('ESTATE'), 5)
111
+ ];
112
+ const manager = new DTManager('dominionCard', library, scopes, { errors: true });
113
+
114
+ // Initialize Supply zone
115
+ const copperPile = new DTBunch('copperPile', duplicateCard(buildCard('COPPER'), 11));
116
+ copperPile.setMeta('cost', cards["COPPER"].cost);
117
+ const silverPile = new DTBunch('silverPile', duplicateCard(buildCard('SILVER'), 11));
118
+ silverPile.setMeta('cost', cards["SILVER"].cost);
119
+ const goldPile = new DTBunch('goldPile', duplicateCard(buildCard('GOLD'), 11));
120
+ goldPile.setMeta('cost', cards["GOLD"].cost);
121
+
122
+ const estatePile = new DTBunch('estatePile', duplicateCard(buildCard('ESTATE'), 7));
123
+ estatePile.setMeta('cost', cards["ESTATE"].cost);
124
+ const duchyPile = new DTBunch('duchyPile', duplicateCard(buildCard('DUCHY'), 7));
125
+ duchyPile.setMeta('cost', cards["DUCHY"].cost);
126
+ const provincePile = new DTBunch('provincePile', duplicateCard(buildCard('PROVINCE'), 7));
127
+ provincePile.setMeta('cost', cards["PROVINCE"].cost);
128
+
129
+ const militiaPile = new DTBunch('militiaPile', duplicateCard(buildCard('MILITIA'), 7));
130
+ militiaPile.setMeta('cost', cards["MILITIA"].cost);
131
+ const smithyPile = new DTBunch('smithyPile', duplicateCard(buildCard('SMITHY'), 7));
132
+ smithyPile.setMeta('cost', cards["SMITHY"].cost);
133
+ const workshopPile = new DTBunch('workshopPile', duplicateCard(buildCard('WORKSHOP'), 7));
134
+ workshopPile.setMeta('cost', cards["WORKSHOP"].cost);
135
+
136
+ manager.addMany([
137
+ copperPile,
138
+ silverPile,
139
+ goldPile,
140
+ estatePile,
141
+ duchyPile,
142
+ provincePile,
143
+ militiaPile,
144
+ smithyPile,
145
+ workshopPile
146
+ ], 'supply');
147
+
148
+ // Initialize players
149
+ const players = [
150
+ new DTPlayer('PRIAM'),
151
+ new DTPlayer('ECTESIAM'),
152
+ ]
153
+
154
+ // Initialize players deck, discard and hand
155
+ let current = {};
156
+ for (let player of players) {
157
+ const deck = new DTBunch('deck');
158
+ deck.setOwner(player);
159
+ manager.add(deck, 'deck');
160
+
161
+ const discard = new DTBunch('discard');
162
+ discard.setOwner(player);
163
+ manager.add(discard, 'discard');
164
+
165
+ const hand = new DTBunch('hand');
166
+ hand.setOwner(player);
167
+ manager.add(hand, 'hand');
168
+
169
+ const playZone = new DTBunch('playZone');
170
+ playZone.setOwner(player);
171
+ manager.add(playZone, 'playZone');
172
+
173
+ const playerCards = new DTBunch('playerCards', [], { virtualContext: true });
174
+ playerCards.setOwner(player);
175
+ manager.add(playerCards);
176
+
177
+ if (player.getKey() === 'PRIAM') {
178
+ current = {
179
+ player,
180
+ deck,
181
+ hand,
182
+ playZone
183
+ }
184
+ }
185
+ }
186
+
187
+ // Return
188
+ return {
189
+ manager,
190
+ current,
191
+ players
192
+ }
193
+ }
194
+
195
+ module.exports = initializeDominionManager
@@ -0,0 +1,27 @@
1
+
2
+ const transformDataTableToBunchFinderArgs = (table) => {
3
+ const validArgs = ['key', 'id', 'owner', 'scope'];
4
+ const finalArgs = {};
5
+
6
+ for (let [arg, value] of Object.entries(table.rowsHash())) {
7
+ if (validArgs.includes(arg)) {
8
+ finalArgs[arg] = { $eq: value };
9
+ } else {
10
+ if (!finalArgs.meta) {
11
+ finalArgs.meta = {};
12
+ }
13
+ finalArgs.meta[arg] = { $eq: value };
14
+ }
15
+ }
16
+
17
+ return finalArgs;
18
+ }
19
+
20
+ const extractKeysElement = (elements) => {
21
+ return elements.map((element) => element.getKey());
22
+ }
23
+
24
+ module.exports = {
25
+ transformDataTableToBunchFinderArgs,
26
+ extractKeysElement
27
+ }
@@ -0,0 +1,108 @@
1
+ const expect = require('expect')
2
+ const { Given, When, Then } = require('@cucumber/cucumber')
3
+ const {DTManager, DTPlayer, DTBunch, DTElement} = require("../../../dist/src");
4
+ const initializeDominionManager = require("../resources/dominion");
5
+ const {transformDataTableToBunchFinderArgs, extractKeysElement } = require("../resources/utils");
6
+
7
+ /******************* INSTALLATION (GIVEN) STEPS *************************/
8
+
9
+ Given('my empty manager', function () {
10
+ this.manager = new DTManager('emptyManager', [], [], { errors: true });
11
+ })
12
+
13
+ Given('my dominion manager', function () {
14
+ const { manager, current, players } = initializeDominionManager();
15
+ this.manager = manager;
16
+ this.current = current;
17
+ this.players = players;
18
+ })
19
+
20
+
21
+ /**************************** ACT STEPS ********************************/
22
+
23
+ When('I add {int} physical bunches and {int} virtual bunches', function (nbBunches, nbVirtualBunches) {
24
+ let i = 1;
25
+ while (i <= nbBunches) {
26
+ this.manager.add(new DTBunch('hand'));
27
+ i++;
28
+ }
29
+ let j = 1;
30
+ while (i <= nbVirtualBunches) {
31
+ this.manager.add(new DTBunch('virtualHand', [], { virtualContext: true }));
32
+ j++;
33
+ }
34
+ });
35
+
36
+ Then('I should have {int} bunches in my manager', function (nbBunches) {
37
+ expect(this.manager.getAll().length).toBe(nbBunches);
38
+ });
39
+
40
+ When('I add an already existing bunch', function () {
41
+ this.manager.add(this.current.hand);
42
+ })
43
+
44
+ Then('I should see an error {string}', function (errorCode) {
45
+ expect(this.manager.getLastError().getCode()).toBe(errorCode);
46
+ });
47
+
48
+ Then('I should find my current hand', function (pred) {
49
+ expect(this.manager.get(this.current.hand.getId()).getId()).toBe(this.current.hand.getId());
50
+ })
51
+
52
+ Then('I shouldn\'t find my current hand', function (pred) {
53
+ expect(this.manager.get(this.current.hand.getId())).toBeUndefined();
54
+ })
55
+
56
+ Then('I should find {int} bunches with', function (nbBunches, table) {
57
+ const findArgs = transformDataTableToBunchFinderArgs(table);
58
+ expect(this.manager.find(findArgs).length).toBe(nbBunches);
59
+ })
60
+
61
+
62
+ When('I move my current hand to the scope {string}', function (scope) {
63
+ this.manager.moveToScope(scope, this.current.hand.getId());
64
+ })
65
+ When('I remove my current hand', function () {
66
+ this.manager.remove(this.current.hand.getId());
67
+ })
68
+
69
+ Then('I should have {int} elements in my library', function (nbElements) {
70
+ expect(this.manager.getLibrary().getAll().length).toBe(nbElements);
71
+ })
72
+
73
+ When('I add a new trash pile with 2 already existing elements into the scope {string}', function (scope) {
74
+ const coppers = this.manager.getLibrary().find({ key: { $eq: 'COPPER' }});
75
+ const trashPile = new DTBunch('trash', [
76
+ new DTElement('CURSE'),
77
+ new DTElement('CURSE'),
78
+ new DTElement('CURSE'),
79
+ coppers[0],
80
+ coppers[1]
81
+ ]);
82
+ this.manager.add(trashPile, scope);
83
+ })
84
+
85
+ Then('I shouldn\'t find my library id into bunches', function () {
86
+ const libraryId = this.manager.getLibrary().getId();
87
+ expect(this.manager.get(libraryId)).toBeUndefined();
88
+ })
89
+
90
+ When('I add a new external card in my current hand', function () {
91
+ const curseCard = new DTElement('CURSE');
92
+ this.current.hand.add(curseCard);
93
+ })
94
+
95
+ Then('I should have {int} scopes in my manager', function (nbScopes) {
96
+ expect(this.manager.getScopes().length).toBe(nbScopes);
97
+ })
98
+
99
+ Then('I should have {int} bunches in my scope {string}', function (nbBunches, scope) {
100
+ expect(this.manager.getAll(scope).length).toBe(nbBunches);
101
+ })
102
+
103
+
104
+
105
+
106
+
107
+
108
+
@@ -0,0 +1,39 @@
1
+ Feature: Epic 4 - Action and Events
2
+
3
+ Scenario: Configuring action into the manager
4
+ Given my dominion manager
5
+ When I add a new action "trash"
6
+ Then I should have 4 actions in my manager
7
+
8
+ Scenario: No duplicated action
9
+ Given my dominion manager
10
+ When I add a new action "shuffle"
11
+ Then I should see an error "action_key_conflict"
12
+
13
+ Scenario: Shuffle my current deck
14
+ Given my dominion manager
15
+ And deal is done
16
+ When I shuffle my current "deck"
17
+ Then I should have copper,estate,copper,estate,copper at the top of my current deck
18
+
19
+ Scenario: Drawing my first hand
20
+ Given my dominion manager
21
+ And deal is done
22
+ When I draw my 5 cards hand
23
+ Then I should have copper,estate,copper,estate,copper in my current hand
24
+
25
+ Scenario: Playing a copper
26
+ Given my dominion manager
27
+ And deal is done
28
+ When I draw my 5 cards hand
29
+ And I play my first card Copper
30
+ Then I should have 1 copper into my play zone
31
+ And my player should have 1 coin for the turn
32
+
33
+ Scenario: No triggering of action outside the restricted scope
34
+ Given my dominion manager
35
+ And deal is done
36
+ When I shuffle my current "hand"
37
+ Then I should see an error "invalid_action_scope"
38
+
39
+