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
@@ -2,51 +2,34 @@ import {afterEach, beforeEach, describe, expect, jest, test,} from '@jest/global
2
2
  import {
3
3
  checkManagerItem,
4
4
  DomainTest,
5
- DTManagerStubDomain,
6
5
  DTManagerTest,
6
+ DTManagerTestDomain,
7
7
  IDTest,
8
8
  KeyTest,
9
- populateManager,
10
9
  ScopesTest,
11
10
  } from './DTManager.double';
12
- import DTManager from '../../src/core/DTManager';
13
11
  import {
14
- bunch1IdTest,
15
12
  bunch1toObjectTest,
16
- bunch2IdTest,
17
13
  bunch2toObjectTest,
18
14
  bunch3toObjectTest,
19
15
  DTBunchStub,
20
16
  DTBunchStubLibrary,
21
- DTBunchTest,
22
- generateMockedElements,
17
+ generateStubElements,
23
18
  IDTest as IDTestBunch,
24
19
  IDTestLibrary,
25
20
  KeyTest as KeyTestBunch,
26
21
  } from './DTBunch.double';
27
- import {mockOverriddenMethods} from './DTComponent.double';
28
- import {DTComponent, DTComponentPhysical, DTElement} from '../../src';
29
- import DYOToolsError from '../../src/core/DTError';
30
- import {checkCallForMockedDTError, DTErrorStub} from './DTError.double';
31
- import {BunchMetaData, IMetaDataTest} from './DTComponentWithMeta.double';
32
- import {componentManagerDefaultFinderConfiguration, managerDefaultOptions} from '../../src/constants';
22
+ import {DTBunch, DTComponent, DTError, DTManager} from '../../src';
23
+ import {DTErrorStub} from './DTError.double';
24
+ import {BunchMetaData} from './DTComponentWithMeta.double';
25
+ import {bunchDefaultOptions} from '../../src/constants';
33
26
  import {FilterOperatorType} from '../../src/types';
34
27
  import {OwnerTest} from './DTComponentPhysical.double';
28
+ import {DTElementStub} from "./DTElement.double";
35
29
  import MockedFunction = jest.MockedFunction;
36
30
 
37
- /** ****************** MOCK DEPENDENCIES
38
- * Dependencies used by the component are mocked with Jest
39
- * **** */
40
- jest.mock('../../src/core/DTElement');
41
- jest.mock('../../src/core/DTBunch');
42
- jest.mock('../../src/core/DTComponent');
43
- jest.mock('../../src/core/DTError');
44
- jest.mock('../../src/libs/DYOFinder');
45
- // Add specific mock for inherited methods to have a basic implementation
46
- mockOverriddenMethods(DTComponent);
47
-
48
31
  /** *********************** TESTS SUITES ****************************** */
49
- describe('class DYOToolsManager', () => {
32
+ describe('class DTManager', () => {
50
33
  let managerTest: DTManagerTest;
51
34
 
52
35
  beforeEach(() => {
@@ -65,7 +48,7 @@ describe('class DYOToolsManager', () => {
65
48
 
66
49
  describe('_componentType', () => {
67
50
  test('componentType must be "manager"', () => {
68
- expect(managerTest.th_get_componentType()).toBe('manager');
51
+ expect(managerTest.getComponentType()).toBe('manager');
69
52
  });
70
53
  });
71
54
 
@@ -75,94 +58,52 @@ describe('class DYOToolsManager', () => {
75
58
  });
76
59
 
77
60
  test('creation simple with key', () => {
78
- const newManager = new DTManagerTest(KeyTest);
79
- const parentConstructorMock = (DTComponentPhysical.prototype.constructor as MockedFunction<(key: string, options: any) => void>).mock;
80
-
81
- expect(parentConstructorMock.calls.length).toBe(1);
82
- expect(parentConstructorMock.calls[0][0]).toBe(KeyTest);
83
- expect(parentConstructorMock.calls[0][1]).toStrictEqual(managerDefaultOptions);
61
+ const newManager = new DTManagerTest(IDTest, KeyTest, [], [], {}, false);
84
62
 
85
- expect(newManager.th_get_items()).toStrictEqual({});
86
- expect(newManager.th_get_scopes()).toStrictEqual(['default', 'virtual']);
63
+ expect(newManager._getItems()).toStrictEqual({});
64
+ expect(newManager.getScopes()).toStrictEqual(['default', 'virtual']);
87
65
 
88
66
  // Library tests
89
- expect(newManager.th_get_library().constructor.mock.calls.length).toBe(1);
90
- expect(newManager.th_get_library().constructor.mock.calls[0][0]).toBe('library');
91
- expect(newManager.th_get_library().constructor.mock.calls[0][1]).toStrictEqual([]);
92
- expect(newManager.th_get_library().constructor.mock.calls[0][2].virtualContainer).toBe(true);
93
- expect(newManager.th_get_library().setContext.mock.calls.length).toBe(1);
94
- expect(newManager.th_get_library().setContext.mock.calls[0][0]).toStrictEqual(newManager);
95
-
96
- // Finder initialization
97
- expect((newManager.th_get_finder() as any).constructor.mock.calls.length).toBe(1);
98
- expect((newManager.th_get_finder() as any).constructor.mock.calls[0][0]).toStrictEqual(newManager);
99
- expect((newManager.th_get_finder() as any).constructor.mock.calls[0][1]).toStrictEqual(componentManagerDefaultFinderConfiguration);
100
- });
101
-
102
- test('creation simple without key - use domain if defined', () => {
103
- // Warning : this method doesn't really work because of Javascript
104
- // The property _domain set is only available after constructing (not during)
105
-
106
- const newManager = new DTManager();
107
- const newManagerWithDomain = new DTManagerStubDomain();
108
- const newManagerWithDomain2 = new DTManagerStubDomain(null);
109
-
110
- jest.spyOn(newManager, 'getKey').mockImplementation(function () {
111
- return this._key;
112
- });
113
- jest.spyOn(newManagerWithDomain, 'getKey').mockImplementation(function () {
114
- return this._key;
115
- });
116
- jest.spyOn(newManagerWithDomain2, 'getKey').mockImplementation(function () {
117
- return this._key;
67
+ const library = newManager.getLibrary();
68
+ expect(library).toBeDefined();
69
+ expect(library.getKey()).toBe('library');
70
+ expect(library.getAll()).toStrictEqual([]);
71
+ expect(library.getOptions()).toStrictEqual({
72
+ ...bunchDefaultOptions,
73
+ virtualContainer: true,
118
74
  });
119
-
120
- expect(newManager.getKey() === DomainTest).toBe(false);
121
- expect(newManagerWithDomain.getKey() === DomainTest).toStrictEqual(true);
122
- expect(newManagerWithDomain2.getKey() === DomainTest).toStrictEqual(true);
75
+ expect(library.getContext()).toStrictEqual(newManager);
123
76
  });
124
77
 
125
- test('creation with elements for library', () => {
126
- const mockedElements = generateMockedElements(5);
127
- const newManager = new DTManagerTest(KeyTest, mockedElements);
78
+ // test('creation simple without key - use domain if defined', () => {
79
+ // const newManager = new DTManagerTest();
80
+ // const newManagerWithDomain = new DTManagerTestDomain();
81
+ // const newManagerWithDomain2 = new DTManagerTestDomain(IDTest, undefined);
82
+ //
83
+ // expect(newManager.getKey() === DomainTest).toBe(false);
84
+ // expect(newManagerWithDomain.getKey() === DomainTest).toStrictEqual(true);
85
+ // expect(newManagerWithDomain2.getKey() === DomainTest).toStrictEqual(true);
86
+ // });
128
87
 
129
- expect(newManager.th_get_items()).toStrictEqual({});
130
- expect(newManager.th_get_scopes()).toStrictEqual(['default', 'virtual']);
88
+ test('creation with elements for library', () => {
89
+ const elements = generateStubElements(5);
90
+ const newManager = new DTManagerTest(IDTest, KeyTest, elements);
131
91
 
132
92
  // Library tests
133
- expect(newManager.th_get_library().constructor.mock.calls.length).toBe(1);
134
- expect(newManager.th_get_library().constructor.mock.calls[0][0]).toBe('library');
135
- expect(newManager.th_get_library().constructor.mock.calls[0][1].length).toStrictEqual(5);
136
- expect(newManager.th_get_library().constructor.mock.calls[0][1].map((item) => item.getId()))
137
- .toStrictEqual(mockedElements.map((item) => item.getId()));
138
- expect(newManager.th_get_library().constructor.mock.calls[0][2].virtualContainer).toBe(true);
139
- expect(newManager.th_get_library().setContext.mock.calls.length).toBe(1);
140
- expect(newManager.th_get_library().setContext.mock.calls[0][0]).toStrictEqual(newManager);
93
+ const library = newManager.getLibrary();
94
+ expect(library).toBeDefined();
95
+ expect(library.getAll()).toStrictEqual(elements);
141
96
  });
142
97
 
143
98
  test('creation with extended scopes', () => {
144
- const mockedElements = generateMockedElements(5);
145
- const newManager = new DTManagerTest(null, mockedElements, ScopesTest);
99
+ const newManager = new DTManagerTest(IDTest, KeyTest, [], ScopesTest);
146
100
 
147
- expect(newManager.th_get_items()).toStrictEqual({});
148
- expect(newManager.th_get_scopes()).toStrictEqual([
101
+ expect(newManager.getScopes()).toStrictEqual([
149
102
  'default',
150
103
  'virtual',
151
104
  ...ScopesTest,
152
105
  ]);
153
106
  });
154
-
155
- test('creation with specific options', () => {
156
- const mockedElements = generateMockedElements(5);
157
- const options = { errors: true, libraryDeletion: true };
158
- const parentConstructorMock = (DTComponentPhysical.prototype.constructor as MockedFunction<(key: string, options: any) => void>).mock;
159
-
160
- const newManager = new DTManagerTest(null, mockedElements, ScopesTest, options);
161
-
162
- expect(parentConstructorMock.calls.length).toBe(1);
163
- expect(parentConstructorMock.calls[0][0]).toBe(null);
164
- expect(parentConstructorMock.calls[0][1]).toStrictEqual(options);
165
- });
166
107
  });
167
108
 
168
109
  describe('getFinderConfiguration()', () => {
@@ -243,34 +184,38 @@ describe('class DYOToolsManager', () => {
243
184
 
244
185
  describe('getLibrary()', () => {
245
186
  test('return current manager Library', () => {
246
- managerTest.th_set_library(new DTBunchStubLibrary());
247
-
248
187
  const library: DTBunchStubLibrary = managerTest.getLibrary() as DTBunchStubLibrary;
249
- expect(library).toBeTruthy();
188
+
189
+ expect(library).toBeDefined();
250
190
  expect(library.getId()).toBe(IDTestLibrary);
251
191
  });
252
192
  });
253
193
 
254
194
  describe('getScopes()', () => {
255
195
  test('return manager scopes', () => {
256
- managerTest.th_set_scopes(ScopesTest);
196
+ managerTest = new DTManagerTest(IDTest, KeyTest, [], ScopesTest)
257
197
 
258
- expect(managerTest.getScopes()).toStrictEqual(ScopesTest);
198
+ expect(managerTest.getScopes()).toStrictEqual([
199
+ 'default',
200
+ 'virtual',
201
+ ...ScopesTest,
202
+ ]);
259
203
  });
260
204
  });
261
205
 
262
206
  describe('getMaster()', () => {
263
207
  test('call get context with master accessor', () => {
208
+ const contextSpy = jest.spyOn(managerTest, 'getContext');
264
209
  managerTest.getMaster();
265
210
 
266
- expect((managerTest.getContext as any).mock.calls.length).toBe(1);
267
- expect((managerTest.getContext as any).mock.calls[0][0]).toBe('master');
211
+ expect(contextSpy.mock.calls.length).toBe(1);
212
+ expect(contextSpy.mock.calls[0][0]).toBe('master');
268
213
  });
269
214
  });
270
215
 
271
216
  describe('isValidScope()', () => {
272
217
  beforeEach(() => {
273
- managerTest.th_set_scopes(ScopesTest);
218
+ managerTest = new DTManagerTest(IDTest, KeyTest, [], ScopesTest);
274
219
  });
275
220
 
276
221
  test('return true if scope exists', () => {
@@ -283,223 +228,191 @@ describe('class DYOToolsManager', () => {
283
228
  });
284
229
 
285
230
  describe('add()', () => {
286
- let bunchToAdd: DTBunchStub;
231
+ let bunchToAdd: DTBunch<DTElementStub>;
287
232
 
288
233
  beforeEach(() => {
289
- jest.spyOn(managerTest, 'getId').mockReturnValue(IDTest);
290
- jest.spyOn(managerTest, 'isValidScope').mockReturnValue(true);
291
-
292
- // Bunch to add
293
- bunchToAdd = new DTBunchStub();
294
- jest.spyOn(bunchToAdd, 'getAll').mockImplementation(function () {
295
- return this._items;
296
- });
297
- jest.spyOn(bunchToAdd, 'getOptions').mockImplementation(function () {
298
- return this._options;
299
- });
300
- jest.spyOn(bunchToAdd, 'getContext').mockImplementation(function () {
301
- return this._context;
302
- });
303
-
304
- // Add tests scopes
305
- managerTest.th_set_scopes([...managerTest.th_get_scopes(), ...ScopesTest]);
234
+ managerTest = new DTManagerTest(IDTest, KeyTest, [], ScopesTest);
235
+ bunchToAdd = new DTBunchStub() as DTBunch<DTElementStub>;
306
236
  });
307
237
 
308
238
  test('add a new item - empty bunch in default scope', () => {
309
239
  managerTest.add(bunchToAdd);
310
240
 
311
- expect(Object.keys(managerTest.th_get_items()).length).toBe(1);
241
+ expect(Object.keys(managerTest._getItems()).length).toBe(1);
312
242
  checkManagerItem(managerTest, IDTestBunch, 'default');
313
243
  });
314
244
 
315
245
  test('add a new item - empty bunch in specific scope', () => {
316
246
  managerTest.add(bunchToAdd, ScopesTest[0]);
317
247
 
318
- expect(Object.keys(managerTest.th_get_items()).length).toBe(1);
248
+ expect(Object.keys(managerTest._getItems()).length).toBe(1);
319
249
  checkManagerItem(managerTest, IDTestBunch, ScopesTest[0]);
320
250
  });
321
251
 
322
252
  test('add a new item - virtual bunch in virtual scope', () => {
323
- bunchToAdd.th_set_options({ virtualContainer: true });
253
+ bunchToAdd = new DTBunchStub([], { virtualContainer: true }) as DTBunch<DTElementStub>;
324
254
 
325
255
  managerTest.add(bunchToAdd);
326
256
 
327
- expect(Object.keys(managerTest.th_get_items()).length).toBe(1);
257
+ expect(Object.keys(managerTest._getItems()).length).toBe(1);
328
258
  checkManagerItem(managerTest, IDTestBunch, 'virtual');
329
259
  });
330
260
 
331
261
  test('trigger error if not existing scope for bunch', () => {
332
262
  const errorScope = 'not-existing-scope';
333
- const mockedTriggerError = DTManager.prototype.triggerError as MockedFunction<(error: DYOToolsError) => void>;
334
- jest.spyOn(managerTest, 'isValidScope').mockReturnValue(false);
335
-
336
- managerTest.add(bunchToAdd, errorScope);
263
+ let errorThrown: DTError | undefined;
264
+ try {
265
+ managerTest.add(bunchToAdd, errorScope);
266
+ } catch(error) {
267
+ errorThrown = error;
268
+ }
337
269
 
338
- expect(Object.keys(managerTest.th_get_items()).length).toBe(0);
339
- expect((managerTest.isValidScope as any).mock.calls.length).toBe(1);
340
- expect((managerTest.isValidScope as any).mock.calls[0][0]).toBe(errorScope);
341
- expect(mockedTriggerError.mock.calls.length).toBe(1);
342
- checkCallForMockedDTError(
343
- 'invalid_scope',
344
- "Scope provided doesn't exist in the manager",
345
- IDTest,
346
- bunchToAdd.getId(),
347
- );
270
+ expect(errorThrown).toBeDefined();
271
+ expect(Object.keys(managerTest._getItems()).length).toBe(0);
272
+ if (errorThrown) {
273
+ expect(errorThrown.getCode()).toBe('invalid_scope');
274
+ expect(errorThrown.getMessage()).toBe('Scope provided doesn\'t exist in the manager');
275
+ expect(errorThrown.getInitiator().getId()).toBe(IDTest);
276
+ expect(errorThrown.getConvicted().getId()).toBe(bunchToAdd.getId());
277
+ }
348
278
  });
349
279
 
350
280
  test('trigger error if invalid scope for virtual bunch', () => {
351
- bunchToAdd.th_set_options({ virtualContainer: true });
352
- const mockedTriggerError = DTManager.prototype.triggerError as MockedFunction<(error: DYOToolsError) => void>;
353
-
354
- managerTest.add(bunchToAdd, ScopesTest[0]);
281
+ bunchToAdd = new DTBunchStub([], { virtualContainer: true }) as DTBunch<DTElementStub>;
282
+ let errorThrown: DTError | undefined;
283
+ try {
284
+ managerTest.add(bunchToAdd, ScopesTest[0]);
285
+ } catch(error) {
286
+ errorThrown = error;
287
+ }
355
288
 
356
- expect(Object.keys(managerTest.th_get_items()).length).toBe(0);
357
- expect(mockedTriggerError.mock.calls.length).toBe(1);
358
- checkCallForMockedDTError(
359
- 'forbidden_scope',
360
- 'Scope provided cannot be associated to a virtual bunch',
361
- IDTest,
362
- bunchToAdd.getId(),
363
- );
289
+ expect(errorThrown).toBeDefined();
290
+ expect(Object.keys(managerTest._getItems()).length).toBe(0);
291
+ if (errorThrown) {
292
+ expect(errorThrown.getCode()).toBe('forbidden_scope');
293
+ expect(errorThrown.getMessage()).toBe('Scope provided cannot be associated to a virtual bunch');
294
+ expect(errorThrown.getInitiator().getId()).toBe(IDTest);
295
+ expect(errorThrown.getConvicted().getId()).toBe(bunchToAdd.getId());
296
+ }
364
297
  });
365
298
 
366
299
  test('trigger error if invalid virtual scope for bunch', () => {
367
- const mockedTriggerError = DTManager.prototype.triggerError as MockedFunction<(error: DYOToolsError) => void>;
368
-
369
- managerTest.add(bunchToAdd, 'virtual');
300
+ let errorThrown: DTError | undefined;
301
+ try {
302
+ managerTest.add(bunchToAdd, 'virtual');
303
+ } catch(error) {
304
+ errorThrown = error;
305
+ }
370
306
 
371
- expect(Object.keys(managerTest.th_get_items()).length).toBe(0);
372
- expect(mockedTriggerError.mock.calls.length).toBe(1);
373
- checkCallForMockedDTError(
374
- 'forbidden_virtual_scope',
375
- 'Virtual Scope provided cannot be associated to a physical bunch',
376
- IDTest,
377
- bunchToAdd.getId(),
378
- );
307
+ expect(errorThrown).toBeDefined();
308
+ expect(Object.keys(managerTest._getItems()).length).toBe(0);
309
+ if (errorThrown) {
310
+ expect(errorThrown.getCode()).toBe('forbidden_virtual_scope');
311
+ expect(errorThrown.getMessage()).toBe('Virtual Scope provided cannot be associated to a physical bunch');
312
+ expect(errorThrown.getInitiator().getId()).toBe(IDTest);
313
+ expect(errorThrown.getConvicted().getId()).toBe(bunchToAdd.getId());
314
+ }
379
315
  });
380
316
 
381
317
  test('trigger conflict error when adding two same bunch ids', () => {
382
- const mockedTriggerError = DTManager.prototype.triggerError as MockedFunction<(error: DYOToolsError) => void>;
383
-
384
- managerTest.add(bunchToAdd);
385
318
  managerTest.add(bunchToAdd);
319
+ let errorThrown: DTError | undefined;
320
+ try {
321
+ managerTest.add(bunchToAdd);
322
+ } catch(error) {
323
+ errorThrown = error;
324
+ }
386
325
 
387
- expect(Object.keys(managerTest.th_get_items()).length).toBe(1);
388
- expect(mockedTriggerError.mock.calls.length).toBe(1);
389
- checkCallForMockedDTError(
390
- 'id_conflict',
391
- 'Bunch with same id already exists in the manager',
392
- IDTest,
393
- bunchToAdd.getId(),
394
- );
326
+ expect(errorThrown).toBeDefined();
327
+ expect(Object.keys(managerTest._getItems()).length).toBe(1);
328
+ if (errorThrown) {
329
+ expect(errorThrown.getCode()).toBe('id_conflict');
330
+ expect(errorThrown.getMessage()).toBe('Bunch with same id already exists in the manager');
331
+ expect(errorThrown.getInitiator().getId()).toBe(IDTest);
332
+ expect(errorThrown.getConvicted().getId()).toBe(bunchToAdd.getId());
333
+ }
395
334
  });
396
335
 
397
336
  test('add bunch elements into library - simple case', () => {
398
- const bunchElements = generateMockedElements(5);
399
- const bunchElementsKeys = bunchElements.map((item: DTElement<IMetaDataTest>) => item.getKey());
400
- bunchToAdd.th_set_items(bunchElements);
337
+ const bunchElements = generateStubElements(5);
338
+ bunchToAdd = new DTBunchStub(bunchElements, { virtualContainer: true }) as DTBunch<DTElementStub>;
401
339
 
402
340
  managerTest.add(bunchToAdd);
403
341
 
404
- expect(managerTest.th_get_single_item(IDTestBunch).item.getAllKeys()).toStrictEqual(bunchElementsKeys);
405
- expect(managerTest.th_get_library().add.mock.calls.length).toBe(5);
406
- let itemCount = 0;
407
- for (const addCalls of managerTest.th_get_library().add.mock.calls) {
408
- expect(addCalls[0].getKey()).toBe(bunchElements[itemCount].getKey());
409
- expect(addCalls[1]).toBeUndefined();
410
- itemCount += 1;
411
- }
342
+ const library = managerTest.getLibrary();
343
+ expect(library.getAll()).toStrictEqual(bunchElements);
412
344
  });
413
345
 
414
346
  test('add bunch elements into library - not adding existing elements in library', () => {
415
- const bunchElements = generateMockedElements(5);
416
- const bunchElementsInLibrary = generateMockedElements(2);
417
- const bunchElementsKeys = bunchElements.map((item: DTElement<IMetaDataTest>) => item.getKey());
418
- bunchToAdd.th_set_items(bunchElements);
419
- managerTest.th_set_library(new DTBunchStubLibrary(bunchElementsInLibrary));
347
+ const bunchElements = generateStubElements(5);
348
+ const bunchElementsInLibrary = generateStubElements(2);
349
+ managerTest = new DTManagerTest(IDTest, KeyTest, bunchElementsInLibrary);
350
+ bunchToAdd = new DTBunchStub(bunchElements, { virtualContainer: true }) as DTBunch<DTElementStub>;
420
351
 
421
352
  managerTest.add(bunchToAdd);
422
353
 
423
- expect(managerTest.th_get_single_item(IDTestBunch).item.getAllKeys()).toStrictEqual(bunchElementsKeys);
424
- expect(managerTest.th_get_library().add.mock.calls.length).toBe(3);
425
- let itemCount = 2;
426
- for (const addCalls of managerTest.th_get_library().add.mock.calls) {
427
- expect(addCalls[0].getKey()).toBe(bunchElements[itemCount].getKey());
428
- expect(addCalls[1]).toBeUndefined();
429
- itemCount += 1;
430
- }
354
+ const library = managerTest.getLibrary();
355
+ expect(library.getAll().map(e => e.getId())).toStrictEqual(bunchElements.map(e => e.getId()));
431
356
  });
432
357
 
433
358
  test('set context when adding an item - default case', () => {
434
- managerTest.th_set_id(IDTest);
435
-
436
359
  managerTest.add(bunchToAdd);
437
360
 
438
- expect((bunchToAdd.setContext as any).mock.calls.length).toBe(1);
439
- expect((bunchToAdd.setContext as any).mock.calls[0][0].th_get_id()).toBe(IDTest);
361
+ expect(bunchToAdd.getContext()?.getId()).toBe(IDTest);
440
362
  });
441
363
 
442
364
  test('set context when adding an item - remove from old manager', () => {
443
- const oldManagerTest = new DTManagerTest();
444
- bunchToAdd.th_set_context(oldManagerTest);
445
- oldManagerTest.th_set_items({ [bunchToAdd.getId()]: { scope: 'default', item: bunchToAdd } });
446
- managerTest.th_set_id(IDTest);
447
- oldManagerTest.th_set_id(`${IDTest}-old`);
448
- jest.spyOn(oldManagerTest, 'remove');
449
- jest.spyOn(oldManagerTest, 'getComponentType').mockImplementation(() => 'manager');
365
+ const oldManagerTest = new DTManagerTest(IDTest + '_old');
366
+ bunchToAdd.setContext(oldManagerTest);
367
+ const removeSpy = jest.spyOn(oldManagerTest, 'remove');
450
368
 
451
369
  managerTest.add(bunchToAdd);
452
370
 
453
- expect((oldManagerTest.remove as any).mock.calls.length).toBe(1);
454
- expect((oldManagerTest.remove as any).mock.calls[0][0]).toBe(bunchToAdd.getId());
455
- expect(Object.keys(managerTest.th_get_items()).length).toBe(1);
456
- checkManagerItem(managerTest, IDTestBunch, 'default');
371
+ expect(removeSpy.mock.calls.length).toBe(1);
372
+ expect(removeSpy.mock.calls[0][0]).toBe(bunchToAdd.getId());
373
+ expect(bunchToAdd.getContext()?.getId()).toBe(IDTest);
457
374
  });
458
375
 
459
376
  test('set context when adding an item - update context with manager for all library elements', () => {
460
- const oldManagerTest = new DTManagerTest();
461
- const bunchElements = generateMockedElements(5);
462
- bunchToAdd.th_set_items(bunchElements);
463
- bunchToAdd.th_set_context(oldManagerTest);
377
+ const elementAdded = generateStubElements(1);
378
+ const oldManagerTest = new DTManagerTest(IDTest + '_old', KeyTest);
379
+ bunchToAdd = new DTBunchStub(elementAdded) as DTBunch<DTElementStub>;
380
+ oldManagerTest.add(bunchToAdd);
381
+ const contextSpy = jest.spyOn(elementAdded[0], 'setContext');
464
382
 
465
383
  managerTest.add(bunchToAdd);
466
384
 
467
- for (const element of bunchElements) {
468
- expect((element.setContext as any).mock.calls.length).toBe(1);
469
- expect((element.setContext as any).mock.calls[0][0]).toStrictEqual(managerTest);
470
- }
385
+ expect(contextSpy.mock.calls.length).toBe(1);
386
+ expect(contextSpy.mock.calls[0][0]).toStrictEqual(managerTest);
471
387
  });
472
388
  });
473
389
 
474
390
  describe('addMany()', () => {
475
391
  let mockedAdd: MockedFunction<(item: any, scope?: string) => void>;
476
392
  let bunchesToAdd: DTBunchStub[];
393
+ let addSpy: any;
477
394
 
478
395
  beforeEach(() => {
479
- jest.spyOn(managerTest, 'add').mockImplementation(() => {});
480
- mockedAdd = managerTest.add as MockedFunction<(item: any, scope?: string) => void>;
396
+ managerTest = new DTManagerTest(IDTest, KeyTest, [], ScopesTest, { errors: false });
397
+ addSpy = jest.spyOn(managerTest, 'add').mockImplementation(() => {});
481
398
 
482
399
  // Bunches to add
483
400
  const bunchToAdd1 = new DTBunchStub();
484
- bunchToAdd1.th_set_id(`${IDTestBunch}_1`);
401
+ bunchToAdd1._setId(`${IDTestBunch}_1`);
485
402
  const bunchToAdd2 = new DTBunchStub();
486
- bunchToAdd2.th_set_id(`${IDTestBunch}_2`);
403
+ bunchToAdd2._setId(`${IDTestBunch}_2`);
487
404
  const bunchToAdd3 = new DTBunchStub();
488
- bunchToAdd3.th_set_id(`${IDTestBunch}_3`);
405
+ bunchToAdd3._setId(`${IDTestBunch}_3`);
489
406
  bunchesToAdd = [bunchToAdd1, bunchToAdd2, bunchToAdd3];
490
-
491
- // Add tests scopes and options
492
- managerTest.th_set_scopes([...managerTest.th_get_scopes(), ...ScopesTest]);
493
- managerTest.th_set_options({ errors: false });
494
407
  });
495
408
 
496
409
  test('add many items - use add method - default case', () => {
497
410
  managerTest.addMany(bunchesToAdd);
498
411
 
499
- expect(mockedAdd.mock.calls.length).toBe(3);
412
+ expect(addSpy.mock.calls.length).toBe(3);
500
413
  let itemCount = 0;
501
- for (const addCalls of mockedAdd.mock.calls) {
502
- expect(addCalls[0].th_get_id()).toBe(bunchesToAdd[itemCount].th_get_id());
414
+ for (const addCalls of addSpy.mock.calls) {
415
+ expect(addCalls[0].getId()).toBe(bunchesToAdd[itemCount].getId());
503
416
  expect(addCalls[1]).toBeUndefined();
504
417
  itemCount += 1;
505
418
  }
@@ -508,17 +421,17 @@ describe('class DYOToolsManager', () => {
508
421
  test('add many items - use add method - with scope case', () => {
509
422
  managerTest.addMany(bunchesToAdd, ScopesTest[0]);
510
423
 
511
- expect(mockedAdd.mock.calls.length).toBe(3);
424
+ expect(addSpy.mock.calls.length).toBe(3);
512
425
  let itemCount = 0;
513
- for (const addCalls of mockedAdd.mock.calls) {
514
- expect(addCalls[0].th_get_id()).toBe(bunchesToAdd[itemCount].th_get_id());
426
+ for (const addCalls of addSpy.mock.calls) {
427
+ expect(addCalls[0].getId()).toBe(bunchesToAdd[itemCount].getId());
515
428
  expect(addCalls[1]).toBe(ScopesTest[0]);
516
429
  itemCount += 1;
517
430
  }
518
431
  });
519
432
 
520
433
  test('errors when adding many items at index - default case - add no items and throw error', () => {
521
- jest.spyOn(managerTest, 'add')
434
+ addSpy = jest.spyOn(managerTest, 'add')
522
435
  .mockImplementationOnce(function (item) {
523
436
  this._items[`${IDTestBunch}_1`] = {
524
437
  scope: 'default',
@@ -534,15 +447,19 @@ describe('class DYOToolsManager', () => {
534
447
  item,
535
448
  };
536
449
  });
450
+ let errorThrown: DTError | undefined;
451
+ try {
452
+ managerTest.addMany(bunchesToAdd);
453
+ } catch(error) {
454
+ errorThrown = error;
455
+ }
537
456
 
538
- expect(() => { managerTest.addMany(bunchesToAdd); }).toThrow();
539
- expect(mockedAdd.mock.calls.length).toBe(2);
540
- expect(Object.keys(managerTest.th_get_items()).length).toBe(0);
457
+ expect(errorThrown).toBeDefined();
458
+ expect(Object.keys(managerTest._getItems()).length).toBe(0);
541
459
  });
542
460
 
543
461
  test('errors when adding many items at index - errors case - add success items and stack errors for others', () => {
544
- managerTest.th_set_options({ errors: true });
545
- jest.spyOn(managerTest, 'add')
462
+ addSpy = jest.spyOn(managerTest, 'add')
546
463
  .mockImplementationOnce(function (item) {
547
464
  this._items[`${IDTestBunch}_1`] = {
548
465
  scope: 'default',
@@ -561,111 +478,120 @@ describe('class DYOToolsManager', () => {
561
478
 
562
479
  managerTest.addMany(bunchesToAdd);
563
480
 
564
- expect(mockedAdd.mock.calls.length).toBe(3);
565
- expect(Object.keys(managerTest.th_get_items()).length).toBe(2);
481
+ expect(addSpy.mock.calls.length).toBe(3);
482
+ expect(Object.keys(managerTest._getItems()).length).toBe(2);
566
483
  });
567
484
  });
568
485
 
569
486
  describe('moveToScope()', () => {
570
487
  beforeEach(() => {
571
- populateManager(managerTest);
572
-
573
- jest.spyOn(managerTest, 'getId').mockReturnValue(IDTest);
574
- jest.spyOn(managerTest, 'isValidScope').mockReturnValue(true);
488
+ managerTest = new DTManagerTest(IDTest, KeyTest, [], ScopesTest);
489
+ managerTest.populate();
575
490
  });
576
491
 
577
492
  test('move to default scope', () => {
578
493
  managerTest.moveToScope(`${IDTestBunch}_2`, 'default');
579
494
 
580
- expect(Object.keys(managerTest.th_get_items()).length).toBe(3);
495
+ expect(Object.keys(managerTest._getItems()).length).toBe(3);
581
496
  checkManagerItem(managerTest, `${IDTestBunch}_2`, 'default');
582
497
  });
583
498
 
584
499
  test('move to existing scope', () => {
585
500
  managerTest.moveToScope(`${IDTestBunch}_2`, ScopesTest[1]);
586
501
 
587
- expect(Object.keys(managerTest.th_get_items()).length).toBe(3);
502
+ expect(Object.keys(managerTest._getItems()).length).toBe(3);
588
503
  checkManagerItem(managerTest, `${IDTestBunch}_2`, ScopesTest[1]);
589
504
  });
590
505
 
591
506
  test('move to non-existing scope - trigger invalid_scope error', () => {
592
- const mockedTriggerError = DTManager.prototype.triggerError as MockedFunction<(error: DYOToolsError) => void>;
593
- jest.spyOn(managerTest, 'isValidScope').mockReturnValue(false);
594
-
595
- managerTest.moveToScope(`${IDTestBunch}_2`, 'invalid_scope');
507
+ let errorThrown: DTError | undefined;
508
+ try {
509
+ managerTest.moveToScope(`${IDTestBunch}_2`, 'invalid_scope');
510
+ } catch(error) {
511
+ errorThrown = error;
512
+ }
596
513
 
597
- expect(Object.keys(managerTest.th_get_items()).length).toBe(3);
598
- expect(mockedTriggerError.mock.calls.length).toBe(1);
599
- checkCallForMockedDTError(
600
- 'invalid_scope',
601
- "Scope provided doesn't exist in the manager",
602
- IDTest,
603
- `${IDTestBunch}_2`,
604
- );
514
+ expect(errorThrown).toBeDefined();
515
+ expect(Object.keys(managerTest._getItems()).length).toBe(3);
516
+ if (errorThrown) {
517
+ expect(errorThrown.getCode()).toBe('invalid_scope');
518
+ expect(errorThrown.getMessage()).toBe('Scope provided doesn\'t exist in the manager');
519
+ expect(errorThrown.getInitiator().getId()).toBe(IDTest);
520
+ expect(errorThrown.getConvicted().getId()).toBe(`${IDTestBunch}_2`);
521
+ }
605
522
  });
606
523
 
607
524
  test('move non-virtual bunch to virtual scope - trigger forbidden_virtual_scope error', () => {
608
- const mockedTriggerError = DTManager.prototype.triggerError as MockedFunction<(error: DYOToolsError) => void>;
609
-
610
- managerTest.moveToScope(`${IDTestBunch}_2`, 'virtual');
525
+ let errorThrown: DTError | undefined;
526
+ try {
527
+ managerTest.moveToScope(`${IDTestBunch}_2`, 'virtual');
528
+ } catch(error) {
529
+ errorThrown = error;
530
+ }
611
531
 
612
- expect(Object.keys(managerTest.th_get_items()).length).toBe(3);
613
- expect(mockedTriggerError.mock.calls.length).toBe(1);
614
- checkCallForMockedDTError(
615
- 'forbidden_virtual_scope',
616
- 'Virtual Scope provided cannot be associated to a physical bunch',
617
- IDTest,
618
- `${IDTestBunch}_2`,
619
- );
532
+ expect(errorThrown).toBeDefined();
533
+ expect(Object.keys(managerTest._getItems()).length).toBe(3);
534
+ if (errorThrown) {
535
+ expect(errorThrown.getCode()).toBe('forbidden_virtual_scope');
536
+ expect(errorThrown.getMessage()).toBe('Virtual Scope provided cannot be associated to a physical bunch');
537
+ expect(errorThrown.getInitiator().getId()).toBe(IDTest);
538
+ expect(errorThrown.getConvicted().getId()).toBe(`${IDTestBunch}_2`);
539
+ }
620
540
  });
621
541
 
622
542
  test('move virtual bunch to non-virtual scope - trigger forbidden_scope error', () => {
623
- const mockedTriggerError = DTManager.prototype.triggerError as MockedFunction<(error: DYOToolsError) => void>;
624
-
625
- managerTest.moveToScope(`${IDTestBunch}_3`, ScopesTest[0]);
543
+ let errorThrown: DTError | undefined;
544
+ try {
545
+ managerTest.moveToScope(`${IDTestBunch}_3`, ScopesTest[0]);
546
+ } catch(error) {
547
+ errorThrown = error;
548
+ }
626
549
 
627
- expect(Object.keys(managerTest.th_get_items()).length).toBe(3);
628
- expect(mockedTriggerError.mock.calls.length).toBe(1);
629
- checkCallForMockedDTError(
630
- 'forbidden_scope',
631
- 'Scope provided cannot be associated to a virtual bunch',
632
- IDTest,
633
- `${IDTestBunch}_3`,
634
- );
550
+ expect(errorThrown).toBeDefined();
551
+ expect(Object.keys(managerTest._getItems()).length).toBe(3);
552
+ if (errorThrown) {
553
+ expect(errorThrown.getCode()).toBe('forbidden_scope');
554
+ expect(errorThrown.getMessage()).toBe('Scope provided cannot be associated to a virtual bunch');
555
+ expect(errorThrown.getInitiator().getId()).toBe(IDTest);
556
+ expect(errorThrown.getConvicted().getId()).toBe(`${IDTestBunch}_3`);
557
+ }
635
558
  });
636
559
 
637
560
  test('move to same scope - nothing append', () => {
638
561
  managerTest.moveToScope(`${IDTestBunch}_1`, 'default');
639
562
 
640
- expect(Object.keys(managerTest.th_get_items()).length).toBe(3);
563
+ expect(Object.keys(managerTest._getItems()).length).toBe(3);
641
564
  checkManagerItem(managerTest, `${IDTestBunch}_1`, 'default');
642
565
  });
643
566
 
644
567
  test('move an non-existing bunch id - trigger invalid_id error', () => {
645
- const mockedTriggerError = DTManager.prototype.triggerError as MockedFunction<(error: DYOToolsError) => void>;
646
-
647
- managerTest.moveToScope(`${IDTestBunch}_5`, ScopesTest[0]);
568
+ let errorThrown: DTError | undefined;
569
+ try {
570
+ managerTest.moveToScope(`${IDTestBunch}_5`, ScopesTest[0]);
571
+ } catch(error) {
572
+ errorThrown = error;
573
+ }
648
574
 
649
- expect(Object.keys(managerTest.th_get_items()).length).toBe(3);
650
- expect(mockedTriggerError.mock.calls.length).toBe(1);
651
- checkCallForMockedDTError(
652
- 'invalid_id',
653
- 'Bunch id provided doesn\'t exist in the manager',
654
- IDTest,
655
- );
575
+ expect(errorThrown).toBeDefined();
576
+ expect(Object.keys(managerTest._getItems()).length).toBe(3);
577
+ if (errorThrown) {
578
+ expect(errorThrown.getCode()).toBe('invalid_id');
579
+ expect(errorThrown.getMessage()).toBe('Bunch id provided doesn\'t exist in the manager');
580
+ expect(errorThrown.getInitiator().getId()).toBe(IDTest);
581
+ }
656
582
  });
657
583
  });
658
584
 
659
585
  describe('get()', () => {
660
586
  beforeEach(() => {
661
- populateManager(managerTest);
587
+ managerTest.populate();
662
588
  });
663
589
 
664
590
  test('return a bunch by its id', () => {
665
- const bunch = managerTest.get(`${IDTestBunch}_1`) as DTBunchTest;
591
+ const bunch = managerTest.get(`${IDTestBunch}_1`) as DTBunchStub;
666
592
 
667
593
  expect(bunch).toBeDefined();
668
- expect(bunch.th_get_id()).toBe(`${IDTestBunch}_1`);
594
+ expect(bunch.getId()).toBe(`${IDTestBunch}_1`);
669
595
  });
670
596
 
671
597
  test('return undefined if bunch is not found', () => {
@@ -677,13 +603,13 @@ describe('class DYOToolsManager', () => {
677
603
 
678
604
  describe('getAll()', () => {
679
605
  beforeEach(() => {
680
- populateManager(managerTest);
606
+ managerTest.populate();
681
607
  });
682
608
 
683
609
  test('return all bunch items', () => {
684
- const bunches = managerTest.getAll() as DTBunchTest[];
610
+ const bunches = managerTest.getAll() as DTBunchStub[];
685
611
 
686
- const bunchesIds = bunches.map((bunch) => bunch.th_get_id());
612
+ const bunchesIds = bunches.map((bunch) => bunch.getId());
687
613
  expect(bunchesIds.length).toBe(3);
688
614
  expect(bunchesIds.includes(`${IDTestBunch}_1`)).toBeTruthy();
689
615
  expect(bunchesIds.includes(`${IDTestBunch}_2`)).toBeTruthy();
@@ -691,7 +617,7 @@ describe('class DYOToolsManager', () => {
691
617
  });
692
618
 
693
619
  test('return empty array if no bunch', () => {
694
- managerTest.th_set_items({});
620
+ managerTest = new DTManagerTest();
695
621
 
696
622
  const bunches = managerTest.getAll();
697
623
 
@@ -699,9 +625,9 @@ describe('class DYOToolsManager', () => {
699
625
  });
700
626
 
701
627
  test('scope argument : return only bunches into the scope', () => {
702
- const bunches = managerTest.getAll(ScopesTest[0]) as DTBunchTest[];
628
+ const bunches = managerTest.getAll(ScopesTest[0]) as DTBunchStub[];
703
629
 
704
- const bunchesIds = bunches.map((bunch) => bunch.th_get_id());
630
+ const bunchesIds = bunches.map((bunch) => bunch.getId());
705
631
  expect(bunchesIds.length).toBe(1);
706
632
  expect(bunchesIds.includes(`${IDTestBunch}_2`)).toBeTruthy();
707
633
  });
@@ -721,7 +647,7 @@ describe('class DYOToolsManager', () => {
721
647
 
722
648
  describe('getScope()', () => {
723
649
  beforeEach(() => {
724
- populateManager(managerTest);
650
+ managerTest.populate();
725
651
  });
726
652
 
727
653
  test('get scope for an existing bunch id', () => {
@@ -743,28 +669,28 @@ describe('class DYOToolsManager', () => {
743
669
 
744
670
  describe('remove()', () => {
745
671
  beforeEach(() => {
746
- populateManager(managerTest);
747
-
748
- jest.spyOn(managerTest, 'removeMany');
672
+ managerTest.populate();
749
673
  });
750
674
 
751
675
  test('remove one item using removeMany', () => {
676
+ const removeManySpy = jest.spyOn(managerTest, 'removeMany');
677
+
752
678
  managerTest.remove(`${IDTestBunch}_2`);
753
679
 
754
- expect((managerTest.removeMany as any).mock.calls.length).toBe(1);
755
- expect((managerTest.removeMany as any).mock.calls[0][0]).toStrictEqual([`${IDTestBunch}_2`]);
680
+ expect(removeManySpy.mock.calls.length).toBe(1);
681
+ expect(removeManySpy.mock.calls[0][0]).toStrictEqual([`${IDTestBunch}_2`]);
756
682
  });
757
683
  });
758
684
 
759
685
  describe('removeMany()', () => {
760
686
  beforeEach(() => {
761
- populateManager(managerTest);
687
+ managerTest.populate();
762
688
  });
763
689
 
764
690
  test('remove multiple bunches from manager', () => {
765
691
  managerTest.removeMany([`${IDTestBunch}_1`, `${IDTestBunch}_2`]);
766
692
 
767
- const newItems = managerTest.th_get_items();
693
+ const newItems = managerTest._getItems();
768
694
  expect(Object.keys(newItems).length).toBe(1);
769
695
  expect(Object.keys(newItems)).toStrictEqual([`${IDTestBunch}_3`]);
770
696
  });
@@ -772,7 +698,7 @@ describe('class DYOToolsManager', () => {
772
698
  test('remove non-existing bunches - nothing happen', () => {
773
699
  managerTest.removeMany([`${IDTestBunch}_5`, `${IDTestBunch}_7`]);
774
700
 
775
- const newItems = managerTest.th_get_items();
701
+ const newItems = managerTest._getItems();
776
702
  expect(Object.keys(newItems).length).toBe(3);
777
703
  expect(Object.keys(newItems)).toStrictEqual([`${IDTestBunch}_1`, `${IDTestBunch}_2`, `${IDTestBunch}_3`]);
778
704
  });
@@ -780,123 +706,110 @@ describe('class DYOToolsManager', () => {
780
706
  test('remove multiple bunches from manager - no removal from library by default', () => {
781
707
  managerTest.removeMany([`${IDTestBunch}_1`, `${IDTestBunch}_2`]);
782
708
 
783
- expect(managerTest.th_get_library().remove.mock.calls.length).toBe(0);
709
+ const library = managerTest.getLibrary();
710
+ expect(library.getAll().length).toBe(5);
784
711
  });
785
712
 
786
713
  test('remove multiple bunches from manager - libraryDeletion option', () => {
787
- const libraryElementsIdToRemove = managerTest.th_get_library().th_get_items().map((item: any) => item.getId());
788
714
  managerTest.removeMany([`${IDTestBunch}_1`, `${IDTestBunch}_2`], { libraryDeletion: true });
789
715
 
790
- expect(managerTest.th_get_library().remove.mock.calls.length).toBe(5);
791
- expect(managerTest.th_get_library().remove.mock.calls.map((call: any) => call[0])).toEqual(libraryElementsIdToRemove);
716
+ const library = managerTest.getLibrary();
717
+ expect(library.getAll().length).toBe(0);
792
718
  });
793
719
 
794
720
  test('remove context when removing a bunch - standard case', () => {
795
- const bunch1 = managerTest.th_get_single_item(`${IDTestBunch}_1`).item;
796
- const bunch2 = managerTest.th_get_single_item(`${IDTestBunch}_2`).item;
721
+ const bunch1 = managerTest._getItem(`${IDTestBunch}_1`).item;
722
+ const bunch2 = managerTest._getItem(`${IDTestBunch}_2`).item;
723
+ const bunch1RemoveContextSpy = jest.spyOn(bunch1, 'removeContext');
724
+ const bunch2RemoveContextSpy = jest.spyOn(bunch2, 'removeContext');
797
725
 
798
726
  managerTest.removeMany([`${IDTestBunch}_1`, `${IDTestBunch}_2`]);
799
727
 
800
- expect((bunch1.removeContext as any).mock.calls.length).toBe(1);
801
- expect((bunch2.removeContext as any).mock.calls.length).toBe(1);
728
+ expect(bunch1RemoveContextSpy.mock.calls.length).toBe(1);
729
+ expect(bunch2RemoveContextSpy.mock.calls.length).toBe(1);
802
730
  });
803
731
 
804
- test('remove context when removing a bunch - remove context for all library elements', () => {
805
- const bunch1 = managerTest.th_get_single_item(`${IDTestBunch}_1`).item;
806
- const bunchElements = generateMockedElements(5);
807
- bunch1.th_set_items(bunchElements);
808
- bunch1.th_set_context(managerTest);
809
-
732
+ test('remove a bunch with elements - remove container for all library elements', () => {
810
733
  managerTest.removeMany([`${IDTestBunch}_1`]);
811
734
 
812
- for (let element of bunchElements) {
813
- expect((element.removeContext as any).mock.calls.length).toBe(1);
735
+ const library = managerTest.getLibrary();
736
+ for (let element of library.getAll()) {
737
+ expect(element.getContext()?.getId()).toBe(IDTest);
738
+ expect(element.getContainer()).toBeUndefined();
814
739
  }
815
740
  });
816
741
  });
817
742
 
818
743
  describe('removeAll()', () => {
819
744
  beforeEach(() => {
820
- populateManager(managerTest);
821
-
822
- jest.spyOn(managerTest, 'removeMany');
745
+ managerTest.populate();
823
746
  });
824
747
 
825
748
  test('remove all items using removeMany', () => {
826
- const bunchesIdToRemove = Object.keys(managerTest.th_get_items());
749
+ const removeManySpy = jest.spyOn(managerTest, 'removeMany');
827
750
  managerTest.removeAll();
828
751
 
829
752
  expect((managerTest.removeMany as any).mock.calls.length).toBe(1);
830
- expect((managerTest.removeMany as any).mock.calls[0][0]).toStrictEqual(bunchesIdToRemove);
753
+ expect((managerTest.removeMany as any).mock.calls[0][0]).toStrictEqual([`${IDTestBunch}_1`, `${IDTestBunch}_2`, `${IDTestBunch}_3`]);
831
754
  });
832
755
  });
833
756
 
834
757
  describe('find()', () => {
758
+ let findSpy;
759
+
760
+ beforeEach(() => {
761
+ findSpy = jest.spyOn(managerTest._getFinder(), 'execute');
762
+ });
763
+
835
764
  test('find items using DYOFinder - empty case', () => {
836
765
  managerTest.find({});
837
766
 
838
- expect((managerTest.th_get_finder() as any).execute.mock.calls.length).toBe(1);
839
- expect((managerTest.th_get_finder() as any).execute.mock.calls[0][0]).toStrictEqual({});
767
+ expect((findSpy as any).mock.calls.length).toBe(1);
768
+ expect((findSpy as any).mock.calls[0][0]).toStrictEqual({});
840
769
  });
841
770
 
842
771
  test('find items using DYOFinder', () => {
843
772
  const testFilters = { id: { $eq: 'id_bunch' }, key: { $ne: 'key_test' } };
844
773
  managerTest.find(testFilters);
845
774
 
846
- expect((managerTest.th_get_finder() as any).execute.mock.calls.length).toBe(1);
847
- expect((managerTest.th_get_finder() as any).execute.mock.calls[0][0]).toStrictEqual(testFilters);
775
+ expect((findSpy as any).mock.calls.length).toBe(1);
776
+ expect((findSpy as any).mock.calls[0][0]).toStrictEqual(testFilters);
848
777
  });
849
778
  });
850
779
 
851
780
  describe('reloadLibrary()', () => {
852
781
  beforeEach(() => {
853
- populateManager(managerTest);
782
+ managerTest.populate();
783
+ const library = managerTest.getLibrary();
784
+ library.removeAll();
854
785
  });
855
786
 
856
- const extractIdsFromLibraryAddCalls = () => (managerTest.th_get_library().add as any).mock.calls.map((call) => call[0].getId());
857
-
858
787
  test('synchronize bunches items into an empty library - one bunch with items', () => {
859
- const items = managerTest.th_get_library().th_get_items();
860
- managerTest.th_get_library().th_set_items([]);
861
- const expectedAddedItemIds = items.map((item: any) => item.getId());
862
-
863
- managerTest.reloadLibrary();
864
-
865
- expect(extractIdsFromLibraryAddCalls()).toEqual(expectedAddedItemIds);
866
- });
867
-
868
- test('synchronize bunches items into an empty library - multiple bunches with items', () => {
869
- const items = managerTest.th_get_library().th_get_items();
870
- managerTest.th_get_library().th_set_items([]);
871
- managerTest.th_get_single_item(bunch1IdTest).item.th_set_items([items[0], items[1], items[2]]);
872
- managerTest.th_get_single_item(bunch2IdTest).item.th_set_items([items[3], items[4]]);
873
- const expectedAddedItemIds = items.map((item: any) => item.getId());
874
-
788
+ const expectedAddedItemIds = generateStubElements(5).map((e) => e.getId());
875
789
  managerTest.reloadLibrary();
876
790
 
877
- expect(extractIdsFromLibraryAddCalls()).toEqual(expectedAddedItemIds);
791
+ const library = managerTest.getLibrary();
792
+ expect(library.getAll().map((e) => e.getId())).toEqual(expectedAddedItemIds);
878
793
  });
879
794
 
880
- test('synchronize bunches items into an empty library - pass already existing ids', () => {
881
- jest.spyOn(managerTest.th_get_library(), 'removeAll').mockImplementation(function () {
882
- this._items = [];
883
- });
884
- const items = managerTest.th_get_library().th_get_items();
885
- managerTest.th_get_library().th_set_items([items[0], items[1], items[2]]);
886
- managerTest.th_get_single_item(bunch1IdTest).item.th_set_items(items);
887
- const expectedAddedItemIds = items.map((item: any) => item.getId());
795
+ test('synchronize bunches items into an empty library - multiple bunches with items and existing ids', () => {
796
+ const newItems = generateStubElements(7);
797
+ const newBunch = new DTBunchStub(newItems);
798
+ newBunch._setId(IDTest + '_new');
799
+ const library = managerTest.getLibrary();
800
+ managerTest.add(newBunch);
801
+ library.removeAll();
888
802
 
889
803
  managerTest.reloadLibrary();
890
804
 
891
- expect(extractIdsFromLibraryAddCalls()).toEqual(expectedAddedItemIds);
805
+ expect(library.getAll().map((e) => e.getId())).toEqual(newItems.map(e => e.getId()));
892
806
  });
893
807
  });
894
808
 
895
809
  describe('toObject()', () => {
896
810
  beforeEach(() => {
897
- managerTest.th_set_id(IDTest);
898
- managerTest.th_set_key(KeyTest);
899
- });
811
+ managerTest = new DTManagerTest(IDTest, KeyTest);
812
+ })
900
813
 
901
814
  test('toObject output standard', () => {
902
815
  const toObjectManager = managerTest.toObject();
@@ -909,7 +822,7 @@ describe('class DYOToolsManager', () => {
909
822
  });
910
823
 
911
824
  test('toObject output with items', () => {
912
- populateManager(managerTest);
825
+ managerTest.populate();
913
826
 
914
827
  const toObjectManager = managerTest.toObject();
915
828
 
@@ -925,20 +838,17 @@ describe('class DYOToolsManager', () => {
925
838
 
926
839
  describe('toString()', () => {
927
840
  beforeEach(() => {
928
- managerTest.th_set_key(KeyTest);
929
- });
841
+ managerTest = new DTManagerTest(IDTest, KeyTest);
842
+ })
930
843
 
931
844
  test('string output standard', () => {
932
- managerTest.th_set_library(new DTBunchStubLibrary());
933
-
934
845
  const toStringManager = managerTest.toString();
935
846
 
936
847
  expect(toStringManager).toBe(`Component ${KeyTest} - Type: Manager - Library: 0 - Items: 0`);
937
848
  });
938
849
 
939
850
  test('string output with domain', () => {
940
- managerTest.th_set_library(new DTBunchStubLibrary());
941
- managerTest.th_set_domain(DomainTest);
851
+ managerTest = new DTManagerTestDomain(IDTest, KeyTest);
942
852
 
943
853
  const toStringManager = managerTest.toString();
944
854
 
@@ -946,8 +856,7 @@ describe('class DYOToolsManager', () => {
946
856
  });
947
857
 
948
858
  test('string output with library', () => {
949
- populateManager(managerTest);
950
- managerTest.th_set_items({});
859
+ managerTest = new DTManagerTest(IDTest, KeyTest, generateStubElements(5));
951
860
 
952
861
  const toStringManager = managerTest.toString();
953
862
 
@@ -955,7 +864,7 @@ describe('class DYOToolsManager', () => {
955
864
  });
956
865
 
957
866
  test('string output with library and items', () => {
958
- populateManager(managerTest);
867
+ managerTest.populate();
959
868
 
960
869
  const toStringManager = managerTest.toString();
961
870