dyo-tools 0.3.2 → 0.4.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 (209) hide show
  1. package/.c8rc.json +4 -4
  2. package/.eslintignore +1 -1
  3. package/.eslintrc.json +47 -47
  4. package/Makefile +34 -34
  5. package/dist/constants.d.ts +1 -0
  6. package/dist/constants.d.ts.map +1 -0
  7. package/dist/constants.js +24 -20
  8. package/dist/constants.js.map +1 -1
  9. package/dist/core/DTAction.d.ts +6 -4
  10. package/dist/core/DTAction.d.ts.map +1 -0
  11. package/dist/core/DTAction.js +3 -6
  12. package/dist/core/DTAction.js.map +1 -1
  13. package/dist/core/DTBunch.d.ts +8 -5
  14. package/dist/core/DTBunch.d.ts.map +1 -0
  15. package/dist/core/DTBunch.js +53 -19
  16. package/dist/core/DTBunch.js.map +1 -1
  17. package/dist/core/DTComponent.d.ts +13 -10
  18. package/dist/core/DTComponent.d.ts.map +1 -0
  19. package/dist/core/DTComponent.js +23 -10
  20. package/dist/core/DTComponent.js.map +1 -1
  21. package/dist/core/DTComponentPhysical.d.ts +11 -8
  22. package/dist/core/DTComponentPhysical.d.ts.map +1 -0
  23. package/dist/core/DTComponentPhysical.js +21 -6
  24. package/dist/core/DTComponentPhysical.js.map +1 -1
  25. package/dist/core/DTComponentWithMeta.d.ts +6 -3
  26. package/dist/core/DTComponentWithMeta.d.ts.map +1 -0
  27. package/dist/core/DTComponentWithMeta.js +21 -7
  28. package/dist/core/DTComponentWithMeta.js.map +1 -1
  29. package/dist/core/DTElement.d.ts +10 -8
  30. package/dist/core/DTElement.d.ts.map +1 -0
  31. package/dist/core/DTElement.js +8 -9
  32. package/dist/core/DTElement.js.map +1 -1
  33. package/dist/core/DTError.d.ts +8 -7
  34. package/dist/core/DTError.d.ts.map +1 -0
  35. package/dist/core/DTError.js +1 -5
  36. package/dist/core/DTError.js.map +1 -1
  37. package/dist/core/DTManager.d.ts +17 -14
  38. package/dist/core/DTManager.d.ts.map +1 -0
  39. package/dist/core/DTManager.js +84 -26
  40. package/dist/core/DTManager.js.map +1 -1
  41. package/dist/core/DTMaster.d.ts +19 -16
  42. package/dist/core/DTMaster.d.ts.map +1 -0
  43. package/dist/core/DTMaster.js +48 -31
  44. package/dist/core/DTMaster.js.map +1 -1
  45. package/dist/core/DTModule.d.ts +8 -5
  46. package/dist/core/DTModule.d.ts.map +1 -0
  47. package/dist/core/DTModule.js +6 -6
  48. package/dist/core/DTModule.js.map +1 -1
  49. package/dist/index.d.ts +1 -0
  50. package/dist/index.d.ts.map +1 -0
  51. package/dist/index.js +12 -28
  52. package/dist/index.js.map +1 -1
  53. package/dist/libs/DYOFinder.d.ts +1 -0
  54. package/dist/libs/DYOFinder.d.ts.map +1 -0
  55. package/dist/libs/DYOFinder.js +10 -14
  56. package/dist/libs/DYOFinder.js.map +1 -1
  57. package/dist/libs/dix/DIXModule.module.d.ts +8 -0
  58. package/dist/libs/dix/DIXModule.module.d.ts.map +1 -0
  59. package/dist/libs/dix/DIXModule.module.js +73 -0
  60. package/dist/libs/player/DTPlayer.element.d.ts +3 -2
  61. package/dist/libs/player/DTPlayer.element.d.ts.map +1 -0
  62. package/dist/libs/player/DTPlayer.element.js +2 -6
  63. package/dist/libs/player/DTPlayer.element.js.map +1 -1
  64. package/dist/libs/player/DTPlayer.manager.d.ts +8 -7
  65. package/dist/libs/player/DTPlayer.manager.d.ts.map +1 -0
  66. package/dist/libs/player/DTPlayer.manager.js +13 -20
  67. package/dist/libs/player/DTPlayer.manager.js.map +1 -1
  68. package/dist/tsconfig.dev.tsbuildinfo +1 -0
  69. package/dist/tsconfig.tsbuildinfo +1 -1
  70. package/dist/types/core.d.ts +40 -12
  71. package/dist/types/core.d.ts.map +1 -0
  72. package/dist/types/core.js +2 -6
  73. package/dist/types/core.js.map +1 -1
  74. package/dist/types/index.d.ts +1 -0
  75. package/dist/types/index.d.ts.map +1 -0
  76. package/dist/types/index.js +2 -19
  77. package/dist/types/index.js.map +1 -1
  78. package/dist/types/player.d.ts +1 -1
  79. package/dist/types/player.d.ts.map +1 -0
  80. package/dist/types/player.js +1 -3
  81. package/integration/data/components/DTHero.ts +42 -0
  82. package/integration/data/components/DTHeroManager.ts +11 -0
  83. package/integration/data/components/DTHeroPlayZone.ts +6 -0
  84. package/integration/data/components/DTHeroPlayerHand.ts +11 -0
  85. package/integration/data/components/index.ts +5 -0
  86. package/integration/data/in/heroIn.helper.ts +8 -0
  87. package/integration/data/in/playerIn.helper.ts +13 -0
  88. package/integration/data/out/heroOut.helper.ts +48 -0
  89. package/integration/endings/synchronisation.ending.ts +25 -0
  90. package/integration/scenes/drawCard.scene.ts +31 -0
  91. package/integration/scenes/empty.scene.ts +6 -0
  92. package/integration/scenes/playCard.scene.ts +23 -0
  93. package/integration/scenes/playerLeave.scene.ts +33 -0
  94. package/integration/stages/baseDix.stage.ts +137 -0
  95. package/integration/stages/syncDix.stage.ts +36 -0
  96. package/integration/tests/scenario1.spec.ts +55 -0
  97. package/integration/types/index.ts +24 -0
  98. package/jest-integration.config.ts +25 -0
  99. package/jest.config.ts +26 -0
  100. package/package.json +31 -19
  101. package/src/constants.ts +2 -0
  102. package/src/core/DTAction.ts +7 -5
  103. package/src/core/DTBunch.ts +78 -14
  104. package/src/core/DTComponent.ts +48 -15
  105. package/src/core/DTComponentPhysical.ts +45 -11
  106. package/src/core/DTComponentWithMeta.ts +37 -4
  107. package/src/core/DTElement.ts +19 -10
  108. package/src/core/DTError.ts +7 -7
  109. package/src/core/DTManager.ts +120 -30
  110. package/src/core/DTMaster.ts +76 -28
  111. package/src/core/DTModule.ts +12 -6
  112. package/src/index.ts +17 -17
  113. package/src/libs/DYOFinder.ts +175 -175
  114. package/src/libs/dix/DIXModule.module.ts +98 -0
  115. package/src/libs/player/DTPlayer.element.ts +2 -2
  116. package/src/libs/player/DTPlayer.manager.ts +20 -34
  117. package/src/types/core.ts +39 -4
  118. package/src/types/index.ts +2 -2
  119. package/src/types/player.ts +0 -1
  120. package/test/core/DTAction.double.ts +12 -28
  121. package/test/core/DTAction.spec.ts +8 -16
  122. package/test/core/DTBunch.double.ts +49 -135
  123. package/test/core/DTBunch.spec.ts +157 -245
  124. package/test/core/DTComponent.double.ts +17 -2
  125. package/test/core/DTComponent.spec.ts +6 -4
  126. package/test/core/DTComponentPhysical.double.ts +29 -43
  127. package/test/core/DTComponentPhysical.spec.ts +22 -19
  128. package/test/core/DTComponentWithMeta.double.ts +38 -31
  129. package/test/core/DTComponentWithMeta.spec.ts +23 -18
  130. package/test/core/DTElement.double.ts +32 -53
  131. package/test/core/DTElement.spec.ts +15 -38
  132. package/test/core/DTError.double.ts +18 -53
  133. package/test/core/DTError.spec.ts +21 -32
  134. package/test/core/DTManager.double.ts +74 -141
  135. package/test/core/DTManager.spec.ts +289 -380
  136. package/test/core/DTMaster.double.ts +56 -80
  137. package/test/core/DTMaster.spec.ts +185 -232
  138. package/test/core/DTModule.double.ts +12 -25
  139. package/test/core/DTModule.spec.ts +14 -28
  140. package/test/core/copy.spec.ts +9 -30
  141. package/tsconfig.dev.json +5 -8
  142. package/tsconfig.json +5 -8
  143. package/cucumber-report.html +0 -48
  144. package/docs/assets/navigation.js +0 -1
  145. package/docs/classes/core_DTAction.DYOToolsAction.html +0 -89
  146. package/docs/classes/core_DTBunch.DYOToolsBunch.html +0 -254
  147. package/docs/classes/core_DTComponent.DYOToolsComponent.html +0 -76
  148. package/docs/classes/core_DTComponentPhysical.DYOToolsComponentPhysical.html +0 -110
  149. package/docs/classes/core_DTComponentWithMeta.DYOToolsComponentWithMeta.html +0 -96
  150. package/docs/classes/core_DTElement.DYOToolsElement.html +0 -135
  151. package/docs/classes/core_DTError.DYOToolsError.html +0 -37
  152. package/docs/classes/core_DTManager.DYOToolsManager.html +0 -237
  153. package/docs/classes/core_DTMaster.DYOToolsMaster.html +0 -150
  154. package/docs/classes/core_DTModule.DYOToolsModule.html +0 -92
  155. package/docs/classes/libs_DYOFinder.DYOFinder.html +0 -34
  156. package/docs/classes/libs_player_DTPlayer_element.DYOToolsPlayer.html +0 -134
  157. package/docs/classes/libs_player_DTPlayer_manager.DYOToolsPlayerManager.html +0 -243
  158. package/docs/enums/types_core.FilterOperatorType.html +0 -10
  159. package/docs/hierarchy.html +0 -1
  160. package/docs/interfaces/types_core.DTBunchFilters.html +0 -6
  161. package/docs/interfaces/types_core.DTBunchOptions.html +0 -19
  162. package/docs/interfaces/types_core.DTBunchToObject.html +0 -7
  163. package/docs/interfaces/types_core.DTComponentOptions.html +0 -5
  164. package/docs/interfaces/types_core.DTComponentToObject.html +0 -4
  165. package/docs/interfaces/types_core.DTElementToObject.html +0 -7
  166. package/docs/interfaces/types_core.DTManagerFilters.html +0 -6
  167. package/docs/interfaces/types_core.DTManagerOptions.html +0 -8
  168. package/docs/interfaces/types_core.DTManagerToObject.html +0 -5
  169. package/docs/interfaces/types_core.DTMasterToObject.html +0 -8
  170. package/docs/interfaces/types_core.DTModuleToObject.html +0 -6
  171. package/docs/interfaces/types_core.DYOFinderConfigurationPropDefault.html +0 -4
  172. package/docs/interfaces/types_core.DYOFinderConfigurationPropObjectSearch.html +0 -4
  173. package/docs/interfaces/types_core.DYOFinderFilterOperatorAdvanced.html +0 -5
  174. package/docs/interfaces/types_core.DYOFinderFilterOperatorBase.html +0 -5
  175. package/docs/interfaces/types_player.DTPlayerManagerSimpleConfiguration.html +0 -3
  176. package/docs/modules/constants.html +0 -6
  177. package/docs/modules/core_DTAction.html +0 -2
  178. package/docs/modules/core_DTBunch.html +0 -2
  179. package/docs/modules/core_DTComponent.html +0 -2
  180. package/docs/modules/core_DTComponentPhysical.html +0 -2
  181. package/docs/modules/core_DTComponentWithMeta.html +0 -2
  182. package/docs/modules/core_DTElement.html +0 -2
  183. package/docs/modules/core_DTError.html +0 -2
  184. package/docs/modules/core_DTManager.html +0 -2
  185. package/docs/modules/core_DTMaster.html +0 -2
  186. package/docs/modules/core_DTModule.html +0 -2
  187. package/docs/modules/libs_DYOFinder.html +0 -2
  188. package/docs/modules/libs_player_DTPlayer_element.html +0 -2
  189. package/docs/modules/libs_player_DTPlayer_manager.html +0 -2
  190. package/docs/modules/types.html +0 -29
  191. package/docs/modules/types_core.html +0 -28
  192. package/docs/modules/types_player.html +0 -2
  193. package/docs/types/types_core.DTAcceptedMetaData.html +0 -2
  194. package/docs/types/types_core.DTManagerItemType.html +0 -1
  195. package/docs/types/types_core.DTManagerItemsType.html +0 -2
  196. package/docs/types/types_core.DYOFinderComponentType.html +0 -1
  197. package/docs/types/types_core.DYOFinderConfiguration.html +0 -2
  198. package/docs/types/types_core.DYOFinderConfigurationProp.html +0 -1
  199. package/docs/types/types_core.DYOFinderFilterOperator.html +0 -1
  200. package/docs/types/types_core.DYOFinderFilterOperatorArgument.html +0 -1
  201. package/docs/types/types_core.DYOFinderFilters.html +0 -1
  202. package/docs/types/types_core.StandardPrimitiveType.html +0 -2
  203. package/docs/types/types_core.StandardPrimitiveTypeWithArray.html +0 -1
  204. package/docs/variables/constants.bunchDefaultOptions.html +0 -2
  205. package/docs/variables/constants.componentBunchDefaultFinderConfiguration.html +0 -1
  206. package/docs/variables/constants.componentManagerDefaultFinderConfiguration.html +0 -1
  207. package/docs/variables/constants.componentPhysicalDefaultFinderConfiguration.html +0 -1
  208. package/docs/variables/constants.managerDefaultOptions.html +0 -2
  209. package/jest.config.js +0 -6
@@ -1,22 +1,13 @@
1
1
  import {beforeEach, describe, expect, jest, test} from '@jest/globals';
2
2
  import {DomainTest, DTElementTest, IDTest, KeyTest} from './DTElement.double';
3
3
  import {MeldrineMetaData} from './DTComponentWithMeta.double';
4
- import {DTComponentPhysical, DTElement} from "../../src";
5
- import {mockOverriddenMethods, OwnerTest} from "./DTComponentPhysical.double";
4
+ import {DTBunch, DTComponentPhysical, DTElement} from "../../src";
5
+ import {OwnerTest} from "./DTComponentPhysical.double";
6
6
  import {DTBunchStub, IDTest as bunchIdTest} from "./DTBunch.double";
7
7
 
8
- /******************** MOCK DEPENDENCIES
9
- * All Dependencies used by the component are mocked with Jest
10
- * *****/
11
- jest.mock('../../src/core/DTComponent');
12
- jest.mock('../../src/core/DTComponentWithMeta');
13
- jest.mock('../../src/core/DTComponentPhysical');
14
- jest.mock('../../src/core/DTBunch');
15
- // Add specific mock for inherited methods to have a basic implementation
16
- mockOverriddenMethods(DTComponentPhysical);
17
8
 
18
9
  /************************* TESTS SUITES *******************************/
19
- describe('class DYOToolsElement', () => {
10
+ describe('class DTElement', () => {
20
11
  let elementTest: DTElementTest;
21
12
 
22
13
  beforeEach(() => {
@@ -35,7 +26,7 @@ describe('class DYOToolsElement', () => {
35
26
 
36
27
  describe('_componentType', () => {
37
28
  test('componentType must be "element"', () => {
38
- expect(elementTest.th_get_componentType()).toBe('element');
29
+ expect(elementTest.getComponentType()).toBe('element');
39
30
  });
40
31
  });
41
32
 
@@ -46,7 +37,7 @@ describe('class DYOToolsElement', () => {
46
37
 
47
38
  test('return container', () => {
48
39
  const container = new DTBunchStub();
49
- elementTest.th_set_container(container);
40
+ elementTest = new DTElementTest(IDTest, KeyTest, container);
50
41
 
51
42
  expect(elementTest.getContainer()).toBeDefined();
52
43
  expect(elementTest.getContainer().getId()).toStrictEqual(bunchIdTest);
@@ -57,32 +48,24 @@ describe('class DYOToolsElement', () => {
57
48
  test('set a new container for element', () => {
58
49
  const container = new DTBunchStub();
59
50
 
60
- elementTest.setContainer(container);
51
+ elementTest.setContainer(container as DTBunch);
61
52
 
62
- expect(elementTest.th_get_container()).toBeDefined();
63
- expect(elementTest.th_get_container().getId()).toStrictEqual(bunchIdTest);
53
+ expect(elementTest.getContainer()).toBeDefined();
54
+ expect(elementTest.getContainer().getId()).toStrictEqual(bunchIdTest);
64
55
  });
65
56
  });
66
57
 
67
58
  describe('removeContainer()', () => {
68
59
  test('remove the current container', () => {
69
60
  const bunchContainer = new DTBunchStub();
70
- elementTest.th_set_container(bunchContainer);
61
+ elementTest = new DTElementTest(IDTest, KeyTest, bunchContainer);
71
62
 
72
63
  elementTest.removeContainer();
73
- expect(elementTest.th_get_container()).toBeUndefined();
64
+ expect(elementTest.getContainer()).toBeUndefined();
74
65
  });
75
66
  });
76
67
 
77
- describe('copy()', () => {
78
- // @see copy.spec.ts for unit tests about copy method
79
- })
80
-
81
68
  describe('toObject()', () => {
82
- beforeEach(() => {
83
- elementTest.th_set_id(IDTest);
84
- elementTest.th_set_key(KeyTest);
85
- })
86
69
 
87
70
  test('toObject output standard', () => {
88
71
  const toObjectElement = elementTest.toObject();
@@ -94,7 +77,7 @@ describe('class DYOToolsElement', () => {
94
77
  });
95
78
 
96
79
  test('toObject output standard with owner', () => {
97
- elementTest.th_set_owner(OwnerTest);
80
+ elementTest.setOwner(OwnerTest);
98
81
 
99
82
  const toObjectElement = elementTest.toObject();
100
83
 
@@ -103,11 +86,8 @@ describe('class DYOToolsElement', () => {
103
86
  });
104
87
 
105
88
  test('toObject output standard with owner and meta', () => {
106
- jest.spyOn(elementTest, 'getManyMeta').mockImplementation(function () {
107
- return this._meta;
108
- });
109
- elementTest.th_set_owner(OwnerTest);
110
- elementTest.th_set_meta(MeldrineMetaData);
89
+ elementTest.setOwner(OwnerTest);
90
+ elementTest.setManyMeta(MeldrineMetaData);
111
91
 
112
92
  const toObjectElement = elementTest.toObject();
113
93
 
@@ -117,9 +97,6 @@ describe('class DYOToolsElement', () => {
117
97
  });
118
98
 
119
99
  describe('toString()', () => {
120
- beforeEach(() => {
121
- elementTest.th_set_key(KeyTest);
122
- })
123
100
 
124
101
  test('string output standard', () => {
125
102
  const toStringElement = elementTest.toString();
@@ -128,7 +105,7 @@ describe('class DYOToolsElement', () => {
128
105
  });
129
106
 
130
107
  test('string output standard with domain', () => {
131
- elementTest.th_set_domain(DomainTest);
108
+ elementTest = new DTElementTest(IDTest, KeyTest, undefined, DomainTest);
132
109
 
133
110
  const toStringElement = elementTest.toString();
134
111
 
@@ -136,7 +113,7 @@ describe('class DYOToolsElement', () => {
136
113
  });
137
114
 
138
115
  test('string output standard with owner', () => {
139
- elementTest.th_set_owner(OwnerTest);
116
+ elementTest.setOwner(OwnerTest);
140
117
 
141
118
  const toStringElement = elementTest.toString();
142
119
 
@@ -1,7 +1,8 @@
1
1
  import {DTError} from '../../src';
2
2
  import {expect} from "@jest/globals";
3
- import DYOToolsComponent from "../../src/core/DTComponent";
3
+ import DTComponent from "../../src/core/DTComponent";
4
4
  import MockedFunction = jest.MockedFunction;
5
+ import {DTComponentStub} from "./DTComponent.double";
5
6
 
6
7
  /******************** STUB PROPERTIES CONSTANTS
7
8
  * Fixed properties to use with double classes, avoid auto generated and easy checking on test
@@ -15,36 +16,25 @@ export const TimestampTest = 1500000000000;
15
16
  * Providing methods to property access and other facilities, in order to avoid using class methods
16
17
  * *****/
17
18
  export class DTErrorTest extends DTError {
18
- th_get_code(): string {
19
- return this.code;
20
- }
21
-
22
- th_get_message(): string {
23
- return this.message;
24
- }
25
-
26
- th_get_timestamp(): Date {
27
- return this.timestamp;
28
- }
29
-
30
- th_set_timestamp(timestamp: Date): void {
31
- this.timestamp = timestamp;
32
- }
33
-
34
- th_get_initiator(): DYOToolsComponent {
35
- return this.initiator;
36
- }
37
-
38
- th_set_initiator(initiator: DYOToolsComponent): void {
39
- this.initiator = initiator;
19
+ constructor(
20
+ code: string,
21
+ message: string,
22
+ initiator?: DTComponentStub,
23
+ convicted?: DTComponentStub,
24
+ timestamp?: Date,
25
+ ) {
26
+ super(code, message, initiator, convicted);
27
+ if (timestamp) {
28
+ this.timestamp = timestamp;
29
+ }
40
30
  }
41
31
 
42
- th_get_convicted(): DYOToolsComponent {
43
- return this.convicted;
32
+ _getConvictedId(): string | undefined {
33
+ return (this.convicted as DTComponentStub)._getStubId();
44
34
  }
45
35
 
46
- th_set_convicted(convicted: DYOToolsComponent): void {
47
- this.convicted = convicted;
36
+ _getInitiatorId(): string | undefined {
37
+ return (this.initiator as DTComponentStub)._getStubId();
48
38
  }
49
39
  }
50
40
 
@@ -58,35 +48,10 @@ export class DTErrorStub extends DTError {
58
48
  this.message = MessageTest;
59
49
  this.timestamp = new Date(Math.random() * 100000000);
60
50
  }
61
-
62
- getCode(): string {
63
- return CodeTest;
64
- }
65
-
66
- getMessage(): string {
67
- return MessageTest;
68
- }
69
-
70
- getTimestamp(): Date {
71
- return this.timestamp;
72
- }
73
51
  }
74
52
 
75
53
  /******************** HELPER METHODS
76
54
  * Additional helper methods to use with testing
77
55
  * *****/
78
- export const checkCallForMockedDTError = (code, message, initiatorId, convictedId?) => {
79
- const mockedErrorConstructor = DTError.prototype.constructor as MockedFunction<(code: string, message: string, initiator?: DYOToolsComponent, convicted?: DYOToolsComponent) => DTError>;
80
- if (!mockedErrorConstructor.mock) {
81
- throw new Error('The DTError Constructor is not a mock');
82
- } else {
83
- expect(mockedErrorConstructor.mock.calls.length).toBe(1);
84
- expect(mockedErrorConstructor.mock.calls[0][0]).toBe(code);
85
- expect(mockedErrorConstructor.mock.calls[0][1]).toBe(message);
86
- expect(mockedErrorConstructor.mock.calls[0][2].getId()).toBe(initiatorId);
87
- if (convictedId) {
88
- expect(mockedErrorConstructor.mock.calls[0][3].getId()).toBe(convictedId);
89
- }
90
- }
91
- };
56
+
92
57
 
@@ -1,13 +1,16 @@
1
1
  import {afterEach, beforeEach, describe, expect, jest, test,} from '@jest/globals';
2
2
  import {CodeTest, DTErrorTest, MessageTest, TimestampTest,} from './DTError.double';
3
3
  import {DTComponentStub, IDTest as ComponentIdTest} from './DTComponent.double';
4
+ import {DTError} from "../../src";
4
5
 
5
6
  /************************* TESTS SUITES *******************************/
6
- describe('class DYOToolsError', () => {
7
+ describe('class DTError', () => {
7
8
  let errorTest: DTErrorTest;
8
9
 
9
10
  beforeEach(() => {
10
- errorTest = new DTErrorTest(CodeTest, MessageTest);
11
+ const initiatorStub = new DTComponentStub('initiator');
12
+ const convictedStub = new DTComponentStub('convicted');
13
+ errorTest = new DTErrorTest(CodeTest, MessageTest, initiatorStub, convictedStub, new Date(TimestampTest));
11
14
  });
12
15
 
13
16
  afterEach(() => {
@@ -16,30 +19,30 @@ describe('class DYOToolsError', () => {
16
19
 
17
20
  describe('constructor()', () => {
18
21
  test('creation with standard field (code, message and timestamp)', () => {
19
- const newError = new DTErrorTest(CodeTest, MessageTest);
22
+ const newError = new DTError(CodeTest, MessageTest);
20
23
  const currentDate = new Date();
21
24
 
22
- expect(newError.th_get_code()).toBe(CodeTest);
23
- expect(newError.th_get_message()).toBe(MessageTest);
24
- expect(newError.th_get_timestamp().toDateString()).toBe(currentDate.toDateString());
25
- expect(newError.th_get_timestamp().toTimeString()).toBe(currentDate.toTimeString());
26
- expect(newError.th_get_initiator()).toBeUndefined();
27
- expect(newError.th_get_convicted()).toBeUndefined();
25
+ expect(newError.getCode()).toBe(CodeTest);
26
+ expect(newError.getMessage()).toBe(MessageTest);
27
+ expect(newError.getTimestamp().toDateString()).toBe(currentDate.toDateString());
28
+ expect(newError.getTimestamp().toTimeString()).toBe(currentDate.toTimeString());
29
+ expect(newError.getInitiator()).toBeUndefined();
30
+ expect(newError.getConvicted()).toBeUndefined();
28
31
  });
29
32
 
30
33
  test('creation with initiator component', () => {
31
- const initiatorMock = new DTComponentStub('initiator');
32
- const newError = new DTErrorTest(CodeTest, MessageTest, initiatorMock);
34
+ const initiatorStub = new DTComponentStub('initiator');
35
+ const newError = new DTErrorTest(CodeTest, MessageTest, initiatorStub);
33
36
 
34
- expect(newError.th_get_initiator().getId()).toBe(`${ComponentIdTest}-initiator`);
37
+ expect(newError._getInitiatorId()).toBe(`${ComponentIdTest}-initiator`);
35
38
  });
36
39
 
37
40
  test('creation with initiator and convicted component', () => {
38
- const initiatorMock = new DTComponentStub('initiator');
39
- const convictedMock = new DTComponentStub('convicted');
40
- const newError = new DTErrorTest(CodeTest, MessageTest, initiatorMock, convictedMock);
41
+ const initiatorStub = new DTComponentStub('initiator');
42
+ const convictedStub = new DTComponentStub('convicted');
43
+ const newError = new DTErrorTest(CodeTest, MessageTest, initiatorStub, convictedStub);
41
44
 
42
- expect(newError.th_get_convicted().getId()).toBe(`${ComponentIdTest}-convicted`);
45
+ expect(newError._getConvictedId()).toBe(`${ComponentIdTest}-convicted`);
43
46
  });
44
47
  });
45
48
 
@@ -57,33 +60,19 @@ describe('class DYOToolsError', () => {
57
60
 
58
61
  describe('getTimestamp()', () => {
59
62
  test('return timestamp property', () => {
60
- errorTest.th_set_timestamp(new Date(TimestampTest));
61
-
62
63
  expect(errorTest.getTimestamp().getTime()).toBe(TimestampTest);
63
64
  });
64
65
  });
65
66
 
66
67
  describe('getInitiator()', () => {
67
- test('return empty initiator component by default', () => {
68
- expect(errorTest.getInitiator()).toBeUndefined();
69
- });
70
-
71
68
  test('return initiator component when set', () => {
72
- errorTest.th_set_initiator(new DTComponentStub('initiator'));
73
-
74
- expect(errorTest.getInitiator().getId()).toBe(`${ComponentIdTest}-initiator`);
69
+ expect(errorTest._getInitiatorId()).toBe(`${ComponentIdTest}-initiator`);
75
70
  });
76
71
  });
77
72
 
78
73
  describe('getConvicted()', () => {
79
- test('return empty convicted component by default', () => {
80
- expect(errorTest.getConvicted()).toBeUndefined();
81
- });
82
-
83
74
  test('return convicted component when set', () => {
84
- errorTest.th_set_convicted(new DTComponentStub('convicted'));
85
-
86
- expect(errorTest.getConvicted().getId()).toBe(`${ComponentIdTest}-convicted`);
75
+ expect(errorTest._getConvictedId()).toBe(`${ComponentIdTest}-convicted`);
87
76
  });
88
77
  });
89
78
  });
@@ -1,19 +1,15 @@
1
1
  import {expect} from '@jest/globals';
2
- import {DTElement, DTManager} from '../../src';
2
+ import {DTBunch, DTManager} from '../../src';
3
3
  import {
4
- bunch1IdTest,
5
4
  bunch1toObjectTest,
6
- bunch2IdTest,
7
- bunch2toObjectTest,
8
- bunch3IdTest,
9
- bunch3toObjectTest,
10
- defaultOptions,
5
+ DTBunchStub,
11
6
  DTBunchStubLibrary,
12
- DTBunchTest,
13
- generateMockedElements,
7
+ generateStubElements,
8
+ IDTest as IDTestBunch,
14
9
  } from './DTBunch.double';
15
- import {DTAcceptedMetaData, DTManagerItemsType, DTManagerOptions, DTManagerToObject} from '../../src/types';
16
- import DYOFinder from '../../src/libs/DYOFinder';
10
+ import {DTManagerItemsType, DTManagerItemType, DTManagerOptions, DTManagerToObject} from '../../src/types';
11
+ import {DTElementStub,} from "./DTElement.double";
12
+ import {managerDefaultOptions} from "../../src/constants";
17
13
 
18
14
  /** ****************** STUB PROPERTIES CONSTANTS
19
15
  * Fixed properties to use with double classes, avoid auto generated and easy checking on test
@@ -43,83 +39,86 @@ export const manager1ToObject: DTManagerToObject = {
43
39
  * Helper test class, inherits the main component
44
40
  * Providing methods to property access and other facilities, in order to avoid using class methods
45
41
  * **** */
46
- export class DTManagerTest extends DTManager<DTElement<DTAcceptedMetaData>> {
47
- th_get_id(): string {
48
- return this._id;
49
- }
50
-
51
- th_set_id(id: string): void {
42
+ export class DTManagerTest extends DTManager<DTElementStub> {
43
+ constructor(
44
+ id: string = IDTest,
45
+ key: string | undefined = undefined,
46
+ elements: DTElementStub[] = [],
47
+ scopes: string[] = [],
48
+ options: Partial<DTManagerOptions> = managerDefaultOptions,
49
+ stubLibrary: boolean = true,
50
+ ) {
51
+ super(key, elements, scopes, options);
52
52
  this._id = id;
53
+ if (stubLibrary) {
54
+ this._library = new DTBunchStubLibrary(elements);
55
+ }
53
56
  }
54
57
 
55
- th_get_key(): string {
56
- return this._key;
57
- }
58
-
59
- th_set_key(key: string): void {
60
- this._key = key;
61
- }
62
-
63
- th_get_componentType(): string {
64
- return this._componentType;
65
- }
66
-
67
- th_get_domain(): string {
68
- return this._domain;
69
- }
70
-
71
- th_set_domain(domain: string): void {
72
- this._domain = domain;
73
- }
74
-
75
- th_get_items(): any {
58
+ _getItems(): DTManagerItemsType<DTElementStub> {
76
59
  return this._items;
77
60
  }
78
61
 
79
- th_set_items(items: DTManagerItemsType<DTElement<DTAcceptedMetaData>>): void {
80
- this._items = items;
81
- }
82
-
83
- th_get_single_item(id: string): any {
62
+ _getItem(id: string): DTManagerItemType<DTElementStub> | undefined {
84
63
  return this._items[id];
85
64
  }
86
65
 
87
- th_get_scopes(): any {
88
- return this._scopes;
89
- }
90
-
91
- th_set_scopes(scopes: any): void {
92
- this._scopes = scopes;
93
- }
94
-
95
- th_get_library(): any {
96
- return this._library;
97
- }
98
-
99
- th_set_library(library: any): void {
100
- this._library = library;
66
+ _getFinder() {
67
+ return this._finder;
101
68
  }
102
69
 
103
- th_set_options(options: any): void {
104
- this._options = {
105
- ...this._options,
106
- ...options,
70
+ populate() {
71
+ const stubElements = generateStubElements(5);
72
+
73
+ // Library
74
+ this._library = new DTBunchStubLibrary(stubElements);
75
+ this._library.setContext<DTManagerTest>(this);
76
+
77
+ // Bunches
78
+ const bunch1 = new DTBunchStub();
79
+ bunch1._setId(`${IDTestBunch}_1`);
80
+ bunch1.setContext<DTManagerTest>(this);
81
+ const bunch2 = new DTBunchStub();
82
+ bunch2._setId(`${IDTestBunch}_2`);
83
+ bunch2.setContext<DTManagerTest>(this);
84
+ const bunch3 = new DTBunchStub([], { virtualContainer: true });
85
+ bunch3._setId(`${IDTestBunch}_3`);
86
+ bunch3.setContext<DTManagerTest>(this);
87
+ this._items = {
88
+ [bunch1.getId()]: {
89
+ scope: 'default',
90
+ item: bunch1 as DTBunch<DTElementStub>,
91
+ },
92
+ [bunch2.getId()]: {
93
+ scope: ScopesTest[0],
94
+ item: bunch2 as DTBunch<DTElementStub>,
95
+ },
96
+ [bunch3.getId()]: {
97
+ scope: 'virtual',
98
+ item: bunch3 as DTBunch<DTElementStub>,
99
+ },
107
100
  };
108
- }
109
101
 
110
- th_get_finder(): DYOFinder {
111
- return this._finder;
102
+ // Add items in Bunch
103
+ bunch1.addMany(stubElements);
112
104
  }
105
+ }
106
+
107
+ export class DTManagerTestDomain extends DTManagerTest {
108
+ protected _domain = DomainTest;
113
109
 
114
- th_get_options(): DTManagerOptions {
115
- return this._options;
110
+ constructor(
111
+ id: string = IDTest,
112
+ key: string | undefined = undefined,
113
+ ) {
114
+ super(id, key);
116
115
  }
117
116
  }
118
117
 
119
118
  /** ****************** STUB CLASS
120
119
  * Stub class, for using in other component
121
120
  * **** */
122
- export class DTManagerStub extends DTManagerTest {
121
+ export class DTManagerStub extends DTManager<DTElementStub> {
123
122
  constructor() {
124
123
  super();
125
124
  this._id = IDTest;
@@ -133,84 +132,18 @@ export class DTManagerStub extends DTManagerTest {
133
132
  ];
134
133
  }
135
134
 
136
- getId(): string {
137
- return IDTest;
138
- }
139
-
140
- getKey(): string {
141
- return KeyTest;
135
+ _setId(id: string) {
136
+ this._id = id;
142
137
  }
143
- }
144
138
 
145
- export class DTManagerStubDomain extends DTManagerTest {
146
- protected _domain = DomainTest;
147
-
148
- getDomain(): string {
149
- return DomainTest;
139
+ _setKey(key: string) {
140
+ this._key = key;
150
141
  }
151
142
  }
152
143
 
153
- /** ****************** HELPER METHODS
154
- * Additional helper methods to use with testing
155
- * **** */
156
- // Add mocked bunches and elements to a Manager
157
- export function populateManager(manager: DTManagerTest): DTManagerTest {
158
- const mockedElements = generateMockedElements(5);
159
-
160
- // Library
161
- manager.th_set_library(new DTBunchStubLibrary(mockedElements));
162
-
163
- // Scopes
164
- manager.th_set_scopes(ScopesTest);
165
-
166
- // Bunches
167
- const bunch1 = new DTBunchTest();
168
- bunch1.th_set_items(mockedElements);
169
- bunch1.th_set_id(bunch1IdTest);
170
- jest.spyOn(bunch1, 'getId').mockImplementation(() => bunch1IdTest);
171
- jest.spyOn(bunch1, 'getOptions').mockImplementation(() => ({ ...defaultOptions }));
172
- jest.spyOn(bunch1, 'getAll').mockImplementation(function () { return this._items; });
173
- jest.spyOn(bunch1, 'toObject').mockImplementation(() => bunch1toObjectTest);
174
-
175
- const bunch2 = new DTBunchTest();
176
- bunch2.th_set_items([]);
177
- bunch2.th_set_id(bunch2IdTest);
178
- jest.spyOn(bunch2, 'getId').mockImplementation(() => bunch2IdTest);
179
- jest.spyOn(bunch2, 'getOptions').mockImplementation(() => ({ ...defaultOptions }));
180
- jest.spyOn(bunch2, 'getAll').mockImplementation(function () { return this._items; });
181
- jest.spyOn(bunch2, 'toObject').mockImplementation(() => bunch2toObjectTest);
182
-
183
- const bunch3 = new DTBunchTest();
184
- bunch3.th_set_items([]);
185
- bunch3.th_set_id(bunch3IdTest);
186
- bunch3.th_set_options({ virtualContainer: true });
187
- jest.spyOn(bunch3, 'getId').mockImplementation(() => bunch3IdTest);
188
- jest.spyOn(bunch3, 'getOptions').mockImplementation(() => ({ ...defaultOptions, virtualContainer: true }));
189
- jest.spyOn(bunch3, 'getAll').mockImplementation(function () { return this._items; });
190
- jest.spyOn(bunch3, 'toObject').mockImplementation(() => bunch3toObjectTest);
191
-
192
- const items: DTManagerItemsType<DTElement<DTAcceptedMetaData>> = {
193
- [bunch1.th_get_id()]: {
194
- scope: 'default',
195
- item: bunch1,
196
- },
197
- [bunch2.th_get_id()]: {
198
- scope: ScopesTest[0],
199
- item: bunch2,
200
- },
201
- [bunch3.th_get_id()]: {
202
- scope: 'virtual',
203
- item: bunch3,
204
- },
205
- };
206
- manager.th_set_items(items);
207
-
208
- return manager;
209
- }
210
-
211
144
  export const checkManagerItem = (managerTest: DTManagerTest, bunchId: string, scope: string): void => {
212
- expect(managerTest.th_get_single_item(bunchId)).toBeDefined();
213
- expect(Object.keys(managerTest.th_get_single_item(bunchId))).toStrictEqual(['scope', 'item']);
214
- expect(managerTest.th_get_single_item(bunchId).scope).toBe(scope);
215
- expect(managerTest.th_get_single_item(bunchId).item.th_get_id()).toBe(bunchId);
145
+ expect(managerTest._getItem(bunchId)).toBeDefined();
146
+ expect(Object.keys(managerTest._getItem(bunchId))).toStrictEqual(['scope', 'item']);
147
+ expect(managerTest._getItem(bunchId)?.scope).toBe(scope);
148
+ expect(managerTest._getItem(bunchId)?.item?.getId()).toBe(bunchId);
216
149
  };