dyo-tools 0.4.0 → 0.4.1

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 (157) hide show
  1. package/{dist/index.d.ts → index.d.ts} +1 -0
  2. package/{dist/index.d.ts.map → index.d.ts.map} +1 -1
  3. package/{dist/index.js → index.js} +1 -0
  4. package/package.json +6 -56
  5. package/.c8rc.json +0 -4
  6. package/.eslintignore +0 -2
  7. package/.eslintrc.json +0 -47
  8. package/Makefile +0 -34
  9. package/README.md +0 -0
  10. package/babel.config.js +0 -1
  11. package/docs/.nojekyll +0 -1
  12. package/docs/assets/highlight.css +0 -29
  13. package/docs/assets/main.js +0 -59
  14. package/docs/assets/search.js +0 -1
  15. package/docs/assets/style.css +0 -1414
  16. package/docs/index.html +0 -1
  17. package/integration/data/components/DTHero.ts +0 -42
  18. package/integration/data/components/DTHeroManager.ts +0 -11
  19. package/integration/data/components/DTHeroPlayZone.ts +0 -6
  20. package/integration/data/components/DTHeroPlayerHand.ts +0 -11
  21. package/integration/data/components/index.ts +0 -5
  22. package/integration/data/in/heroIn.helper.ts +0 -8
  23. package/integration/data/in/playerIn.helper.ts +0 -13
  24. package/integration/data/out/heroOut.helper.ts +0 -48
  25. package/integration/endings/synchronisation.ending.ts +0 -25
  26. package/integration/scenes/drawCard.scene.ts +0 -31
  27. package/integration/scenes/empty.scene.ts +0 -6
  28. package/integration/scenes/playCard.scene.ts +0 -23
  29. package/integration/scenes/playerLeave.scene.ts +0 -33
  30. package/integration/stages/baseDix.stage.ts +0 -137
  31. package/integration/stages/syncDix.stage.ts +0 -36
  32. package/integration/tests/scenario1.spec.ts +0 -55
  33. package/integration/types/index.ts +0 -24
  34. package/jest-integration.config.ts +0 -25
  35. package/jest.config.ts +0 -26
  36. package/src/constants.ts +0 -87
  37. package/src/core/DTAction.ts +0 -54
  38. package/src/core/DTBunch.ts +0 -531
  39. package/src/core/DTComponent.ts +0 -258
  40. package/src/core/DTComponentPhysical.ts +0 -88
  41. package/src/core/DTComponentWithMeta.ts +0 -98
  42. package/src/core/DTElement.ts +0 -111
  43. package/src/core/DTError.ts +0 -78
  44. package/src/core/DTManager.ts +0 -555
  45. package/src/core/DTMaster.ts +0 -366
  46. package/src/core/DTModule.ts +0 -96
  47. package/src/index.ts +0 -17
  48. package/src/libs/DYOFinder.ts +0 -175
  49. package/src/libs/dix/DIXModule.module.ts +0 -98
  50. package/src/libs/player/DTPlayer.element.ts +0 -9
  51. package/src/libs/player/DTPlayer.manager.ts +0 -70
  52. package/src/types/core.ts +0 -204
  53. package/src/types/index.ts +0 -2
  54. package/src/types/player.ts +0 -5
  55. package/test/core/DTAction.double.ts +0 -62
  56. package/test/core/DTAction.spec.ts +0 -68
  57. package/test/core/DTBunch.double.ts +0 -175
  58. package/test/core/DTBunch.spec.ts +0 -822
  59. package/test/core/DTComponent.double.ts +0 -179
  60. package/test/core/DTComponent.spec.ts +0 -297
  61. package/test/core/DTComponentPhysical.double.ts +0 -62
  62. package/test/core/DTComponentPhysical.spec.ts +0 -81
  63. package/test/core/DTComponentWithMeta.double.ts +0 -122
  64. package/test/core/DTComponentWithMeta.spec.ts +0 -129
  65. package/test/core/DTElement.double.ts +0 -142
  66. package/test/core/DTElement.spec.ts +0 -123
  67. package/test/core/DTError.double.ts +0 -57
  68. package/test/core/DTError.spec.ts +0 -78
  69. package/test/core/DTManager.double.ts +0 -149
  70. package/test/core/DTManager.spec.ts +0 -874
  71. package/test/core/DTMaster.double.ts +0 -117
  72. package/test/core/DTMaster.spec.ts +0 -537
  73. package/test/core/DTModule.double.ts +0 -67
  74. package/test/core/DTModule.spec.ts +0 -124
  75. package/test/core/copy.spec.ts +0 -222
  76. package/test/libs/DYOFinder.double.ts +0 -152
  77. package/test/libs/DYOFinder.spec.ts +0 -194
  78. package/test/libs/player/DTPlayer.element.double.ts +0 -55
  79. package/test/libs/player/DTPlayer.element.spec.ts +0 -28
  80. package/test/libs/player/DTPlayer.manager.double.ts +0 -92
  81. package/test/libs/player/DTPlayer.manager.spec.ts +0 -178
  82. package/tsconfig.dev.json +0 -19
  83. package/tsconfig.json +0 -18
  84. /package/{dist/constants.d.ts → constants.d.ts} +0 -0
  85. /package/{dist/constants.d.ts.map → constants.d.ts.map} +0 -0
  86. /package/{dist/constants.js → constants.js} +0 -0
  87. /package/{dist/constants.js.map → constants.js.map} +0 -0
  88. /package/{dist/core → core}/DTAction.d.ts +0 -0
  89. /package/{dist/core → core}/DTAction.d.ts.map +0 -0
  90. /package/{dist/core → core}/DTAction.js +0 -0
  91. /package/{dist/core → core}/DTAction.js.map +0 -0
  92. /package/{dist/core → core}/DTBunch.d.ts +0 -0
  93. /package/{dist/core → core}/DTBunch.d.ts.map +0 -0
  94. /package/{dist/core → core}/DTBunch.js +0 -0
  95. /package/{dist/core → core}/DTBunch.js.map +0 -0
  96. /package/{dist/core → core}/DTComponent.d.ts +0 -0
  97. /package/{dist/core → core}/DTComponent.d.ts.map +0 -0
  98. /package/{dist/core → core}/DTComponent.js +0 -0
  99. /package/{dist/core → core}/DTComponent.js.map +0 -0
  100. /package/{dist/core → core}/DTComponentPhysical.d.ts +0 -0
  101. /package/{dist/core → core}/DTComponentPhysical.d.ts.map +0 -0
  102. /package/{dist/core → core}/DTComponentPhysical.js +0 -0
  103. /package/{dist/core → core}/DTComponentPhysical.js.map +0 -0
  104. /package/{dist/core → core}/DTComponentWithMeta.d.ts +0 -0
  105. /package/{dist/core → core}/DTComponentWithMeta.d.ts.map +0 -0
  106. /package/{dist/core → core}/DTComponentWithMeta.js +0 -0
  107. /package/{dist/core → core}/DTComponentWithMeta.js.map +0 -0
  108. /package/{dist/core → core}/DTElement.d.ts +0 -0
  109. /package/{dist/core → core}/DTElement.d.ts.map +0 -0
  110. /package/{dist/core → core}/DTElement.js +0 -0
  111. /package/{dist/core → core}/DTElement.js.map +0 -0
  112. /package/{dist/core → core}/DTError.d.ts +0 -0
  113. /package/{dist/core → core}/DTError.d.ts.map +0 -0
  114. /package/{dist/core → core}/DTError.js +0 -0
  115. /package/{dist/core → core}/DTError.js.map +0 -0
  116. /package/{dist/core → core}/DTManager.d.ts +0 -0
  117. /package/{dist/core → core}/DTManager.d.ts.map +0 -0
  118. /package/{dist/core → core}/DTManager.js +0 -0
  119. /package/{dist/core → core}/DTManager.js.map +0 -0
  120. /package/{dist/core → core}/DTMaster.d.ts +0 -0
  121. /package/{dist/core → core}/DTMaster.d.ts.map +0 -0
  122. /package/{dist/core → core}/DTMaster.js +0 -0
  123. /package/{dist/core → core}/DTMaster.js.map +0 -0
  124. /package/{dist/core → core}/DTModule.d.ts +0 -0
  125. /package/{dist/core → core}/DTModule.d.ts.map +0 -0
  126. /package/{dist/core → core}/DTModule.js +0 -0
  127. /package/{dist/core → core}/DTModule.js.map +0 -0
  128. /package/{dist/index.js.map → index.js.map} +0 -0
  129. /package/{dist/libs → libs}/DYOFinder.d.ts +0 -0
  130. /package/{dist/libs → libs}/DYOFinder.d.ts.map +0 -0
  131. /package/{dist/libs → libs}/DYOFinder.js +0 -0
  132. /package/{dist/libs → libs}/DYOFinder.js.map +0 -0
  133. /package/{dist/libs → libs}/dix/DIXModule.module.d.ts +0 -0
  134. /package/{dist/libs → libs}/dix/DIXModule.module.d.ts.map +0 -0
  135. /package/{dist/libs → libs}/dix/DIXModule.module.js +0 -0
  136. /package/{dist/libs → libs}/player/DTPlayer.element.d.ts +0 -0
  137. /package/{dist/libs → libs}/player/DTPlayer.element.d.ts.map +0 -0
  138. /package/{dist/libs → libs}/player/DTPlayer.element.js +0 -0
  139. /package/{dist/libs → libs}/player/DTPlayer.element.js.map +0 -0
  140. /package/{dist/libs → libs}/player/DTPlayer.manager.d.ts +0 -0
  141. /package/{dist/libs → libs}/player/DTPlayer.manager.d.ts.map +0 -0
  142. /package/{dist/libs → libs}/player/DTPlayer.manager.js +0 -0
  143. /package/{dist/libs → libs}/player/DTPlayer.manager.js.map +0 -0
  144. /package/{dist/tsconfig.dev.tsbuildinfo → tsconfig.dev.tsbuildinfo} +0 -0
  145. /package/{dist/tsconfig.tsbuildinfo → tsconfig.tsbuildinfo} +0 -0
  146. /package/{dist/types → types}/core.d.ts +0 -0
  147. /package/{dist/types → types}/core.d.ts.map +0 -0
  148. /package/{dist/types → types}/core.js +0 -0
  149. /package/{dist/types → types}/core.js.map +0 -0
  150. /package/{dist/types → types}/index.d.ts +0 -0
  151. /package/{dist/types → types}/index.d.ts.map +0 -0
  152. /package/{dist/types → types}/index.js +0 -0
  153. /package/{dist/types → types}/index.js.map +0 -0
  154. /package/{dist/types → types}/player.d.ts +0 -0
  155. /package/{dist/types → types}/player.d.ts.map +0 -0
  156. /package/{dist/types → types}/player.js +0 -0
  157. /package/{dist/types → types}/player.js.map +0 -0
@@ -1,874 +0,0 @@
1
- import {afterEach, beforeEach, describe, expect, jest, test,} from '@jest/globals';
2
- import {
3
- checkManagerItem,
4
- DomainTest,
5
- DTManagerTest,
6
- DTManagerTestDomain,
7
- IDTest,
8
- KeyTest,
9
- ScopesTest,
10
- } from './DTManager.double';
11
- import {
12
- bunch1toObjectTest,
13
- bunch2toObjectTest,
14
- bunch3toObjectTest,
15
- DTBunchStub,
16
- DTBunchStubLibrary,
17
- generateStubElements,
18
- IDTest as IDTestBunch,
19
- IDTestLibrary,
20
- KeyTest as KeyTestBunch,
21
- } from './DTBunch.double';
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';
26
- import {FilterOperatorType} from '../../src/types';
27
- import {OwnerTest} from './DTComponentPhysical.double';
28
- import {DTElementStub} from "./DTElement.double";
29
- import MockedFunction = jest.MockedFunction;
30
-
31
- /** *********************** TESTS SUITES ****************************** */
32
- describe('class DTManager', () => {
33
- let managerTest: DTManagerTest;
34
-
35
- beforeEach(() => {
36
- managerTest = new DTManagerTest();
37
- });
38
-
39
- afterEach(() => {
40
- jest.resetAllMocks();
41
- });
42
-
43
- describe('inheritance', () => {
44
- test('check good inheritance for class', () => {
45
- expect(DTManager.prototype instanceof DTComponent).toBeTruthy();
46
- });
47
- });
48
-
49
- describe('_componentType', () => {
50
- test('componentType must be "manager"', () => {
51
- expect(managerTest.getComponentType()).toBe('manager');
52
- });
53
- });
54
-
55
- describe('constructor()', () => {
56
- beforeEach(() => {
57
- jest.resetAllMocks();
58
- });
59
-
60
- test('creation simple with key', () => {
61
- const newManager = new DTManagerTest(IDTest, KeyTest, [], [], {}, false);
62
-
63
- expect(newManager._getItems()).toStrictEqual({});
64
- expect(newManager.getScopes()).toStrictEqual(['default', 'virtual']);
65
-
66
- // Library tests
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,
74
- });
75
- expect(library.getContext()).toStrictEqual(newManager);
76
- });
77
-
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
- // });
87
-
88
- test('creation with elements for library', () => {
89
- const elements = generateStubElements(5);
90
- const newManager = new DTManagerTest(IDTest, KeyTest, elements);
91
-
92
- // Library tests
93
- const library = newManager.getLibrary();
94
- expect(library).toBeDefined();
95
- expect(library.getAll()).toStrictEqual(elements);
96
- });
97
-
98
- test('creation with extended scopes', () => {
99
- const newManager = new DTManagerTest(IDTest, KeyTest, [], ScopesTest);
100
-
101
- expect(newManager.getScopes()).toStrictEqual([
102
- 'default',
103
- 'virtual',
104
- ...ScopesTest,
105
- ]);
106
- });
107
- });
108
-
109
- describe('getFinderConfiguration()', () => {
110
- const baseOperators = [
111
- FilterOperatorType.EQ,
112
- FilterOperatorType.IN,
113
- FilterOperatorType.NIN,
114
- FilterOperatorType.NE,
115
- ];
116
- const advancedOperators = [
117
- ...baseOperators,
118
- FilterOperatorType.GTE,
119
- FilterOperatorType.LTE,
120
- FilterOperatorType.CONTAINS,
121
- FilterOperatorType.NCONTAINS,
122
- ];
123
-
124
- test('check finder configuration for id attribute', () => {
125
- const finderConfigurationToCheck = managerTest.getFinderConfiguration().id;
126
-
127
- expect(finderConfigurationToCheck.operators).toStrictEqual(baseOperators);
128
- expect(finderConfigurationToCheck.getValue(new DTBunchStub())).toBe(IDTestBunch);
129
- expect(finderConfigurationToCheck.objectSearch).toBe(false);
130
- });
131
-
132
- test('check finder configuration for key attribute', () => {
133
- const finderConfigurationToCheck = managerTest.getFinderConfiguration().key;
134
-
135
- expect(finderConfigurationToCheck.operators).toStrictEqual(baseOperators);
136
- expect(finderConfigurationToCheck.getValue(new DTBunchStub())).toBe(KeyTestBunch);
137
- expect(finderConfigurationToCheck.objectSearch).toBe(false);
138
- });
139
-
140
- test('check finder configuration for owner attribute - empty owner', () => {
141
- const bunch = new DTBunchStub();
142
- jest.spyOn(bunch, 'getOwner').mockImplementation(() => undefined);
143
-
144
- const finderConfigurationToCheck = managerTest.getFinderConfiguration().owner;
145
-
146
- expect(finderConfigurationToCheck.operators).toStrictEqual(baseOperators);
147
- expect(finderConfigurationToCheck.getValue(bunch)).toBeUndefined();
148
- expect(finderConfigurationToCheck.objectSearch).toBe(false);
149
- });
150
-
151
- test('check finder configuration for owner attribute - with owner', () => {
152
- const bunch = new DTBunchStub();
153
- jest.spyOn(bunch, 'getOwner').mockReturnValue(OwnerTest);
154
-
155
- const finderConfigurationToCheck = managerTest.getFinderConfiguration().owner;
156
-
157
- expect(finderConfigurationToCheck.operators).toStrictEqual(baseOperators);
158
- expect(finderConfigurationToCheck.getValue(bunch)).toBe(OwnerTest);
159
- expect(finderConfigurationToCheck.objectSearch).toBe(false);
160
- });
161
-
162
- test('check finder configuration for meta attribute', () => {
163
- const bunch = new DTBunchStub();
164
- jest.spyOn(bunch, 'getManyMeta').mockImplementation(() => BunchMetaData);
165
-
166
- const finderConfigurationToCheck = managerTest.getFinderConfiguration().meta;
167
-
168
- expect(finderConfigurationToCheck.operators).toStrictEqual(advancedOperators);
169
- expect(finderConfigurationToCheck.getValue(bunch)).toStrictEqual(BunchMetaData);
170
- expect(finderConfigurationToCheck.objectSearch).toBe(true);
171
- });
172
-
173
- test('check finder configuration for scope attribute', () => {
174
- const bunch = new DTBunchStub();
175
- jest.spyOn(managerTest, 'getScope').mockImplementation(() => ScopesTest[0]);
176
-
177
- const finderConfigurationToCheck = managerTest.getFinderConfiguration().scope;
178
-
179
- expect(finderConfigurationToCheck.operators).toStrictEqual(baseOperators);
180
- expect(finderConfigurationToCheck.getValue(bunch, managerTest)).toStrictEqual(ScopesTest[0]);
181
- expect(finderConfigurationToCheck.objectSearch).toBe(false);
182
- });
183
- });
184
-
185
- describe('getLibrary()', () => {
186
- test('return current manager Library', () => {
187
- const library: DTBunchStubLibrary = managerTest.getLibrary() as DTBunchStubLibrary;
188
-
189
- expect(library).toBeDefined();
190
- expect(library.getId()).toBe(IDTestLibrary);
191
- });
192
- });
193
-
194
- describe('getScopes()', () => {
195
- test('return manager scopes', () => {
196
- managerTest = new DTManagerTest(IDTest, KeyTest, [], ScopesTest)
197
-
198
- expect(managerTest.getScopes()).toStrictEqual([
199
- 'default',
200
- 'virtual',
201
- ...ScopesTest,
202
- ]);
203
- });
204
- });
205
-
206
- describe('getMaster()', () => {
207
- test('call get context with master accessor', () => {
208
- const contextSpy = jest.spyOn(managerTest, 'getContext');
209
- managerTest.getMaster();
210
-
211
- expect(contextSpy.mock.calls.length).toBe(1);
212
- expect(contextSpy.mock.calls[0][0]).toBe('master');
213
- });
214
- });
215
-
216
- describe('isValidScope()', () => {
217
- beforeEach(() => {
218
- managerTest = new DTManagerTest(IDTest, KeyTest, [], ScopesTest);
219
- });
220
-
221
- test('return true if scope exists', () => {
222
- expect(managerTest.isValidScope(ScopesTest[0])).toBe(true);
223
- });
224
-
225
- test('return false if scope doesn\'t exist', () => {
226
- expect(managerTest.isValidScope('invalid_scope')).toBe(false);
227
- });
228
- });
229
-
230
- describe('add()', () => {
231
- let bunchToAdd: DTBunch<DTElementStub>;
232
-
233
- beforeEach(() => {
234
- managerTest = new DTManagerTest(IDTest, KeyTest, [], ScopesTest);
235
- bunchToAdd = new DTBunchStub() as DTBunch<DTElementStub>;
236
- });
237
-
238
- test('add a new item - empty bunch in default scope', () => {
239
- managerTest.add(bunchToAdd);
240
-
241
- expect(Object.keys(managerTest._getItems()).length).toBe(1);
242
- checkManagerItem(managerTest, IDTestBunch, 'default');
243
- });
244
-
245
- test('add a new item - empty bunch in specific scope', () => {
246
- managerTest.add(bunchToAdd, ScopesTest[0]);
247
-
248
- expect(Object.keys(managerTest._getItems()).length).toBe(1);
249
- checkManagerItem(managerTest, IDTestBunch, ScopesTest[0]);
250
- });
251
-
252
- test('add a new item - virtual bunch in virtual scope', () => {
253
- bunchToAdd = new DTBunchStub([], { virtualContainer: true }) as DTBunch<DTElementStub>;
254
-
255
- managerTest.add(bunchToAdd);
256
-
257
- expect(Object.keys(managerTest._getItems()).length).toBe(1);
258
- checkManagerItem(managerTest, IDTestBunch, 'virtual');
259
- });
260
-
261
- test('trigger error if not existing scope for bunch', () => {
262
- const errorScope = 'not-existing-scope';
263
- let errorThrown: DTError | undefined;
264
- try {
265
- managerTest.add(bunchToAdd, errorScope);
266
- } catch(error) {
267
- errorThrown = error;
268
- }
269
-
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
- }
278
- });
279
-
280
- test('trigger error if invalid scope for virtual bunch', () => {
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
- }
288
-
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
- }
297
- });
298
-
299
- test('trigger error if invalid virtual scope for bunch', () => {
300
- let errorThrown: DTError | undefined;
301
- try {
302
- managerTest.add(bunchToAdd, 'virtual');
303
- } catch(error) {
304
- errorThrown = error;
305
- }
306
-
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
- }
315
- });
316
-
317
- test('trigger conflict error when adding two same bunch ids', () => {
318
- managerTest.add(bunchToAdd);
319
- let errorThrown: DTError | undefined;
320
- try {
321
- managerTest.add(bunchToAdd);
322
- } catch(error) {
323
- errorThrown = error;
324
- }
325
-
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
- }
334
- });
335
-
336
- test('add bunch elements into library - simple case', () => {
337
- const bunchElements = generateStubElements(5);
338
- bunchToAdd = new DTBunchStub(bunchElements, { virtualContainer: true }) as DTBunch<DTElementStub>;
339
-
340
- managerTest.add(bunchToAdd);
341
-
342
- const library = managerTest.getLibrary();
343
- expect(library.getAll()).toStrictEqual(bunchElements);
344
- });
345
-
346
- test('add bunch elements into library - not adding existing elements in library', () => {
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>;
351
-
352
- managerTest.add(bunchToAdd);
353
-
354
- const library = managerTest.getLibrary();
355
- expect(library.getAll().map(e => e.getId())).toStrictEqual(bunchElements.map(e => e.getId()));
356
- });
357
-
358
- test('set context when adding an item - default case', () => {
359
- managerTest.add(bunchToAdd);
360
-
361
- expect(bunchToAdd.getContext()?.getId()).toBe(IDTest);
362
- });
363
-
364
- test('set context when adding an item - remove from old manager', () => {
365
- const oldManagerTest = new DTManagerTest(IDTest + '_old');
366
- bunchToAdd.setContext(oldManagerTest);
367
- const removeSpy = jest.spyOn(oldManagerTest, 'remove');
368
-
369
- managerTest.add(bunchToAdd);
370
-
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);
374
- });
375
-
376
- test('set context when adding an item - update context with manager for all library elements', () => {
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');
382
-
383
- managerTest.add(bunchToAdd);
384
-
385
- expect(contextSpy.mock.calls.length).toBe(1);
386
- expect(contextSpy.mock.calls[0][0]).toStrictEqual(managerTest);
387
- });
388
- });
389
-
390
- describe('addMany()', () => {
391
- let mockedAdd: MockedFunction<(item: any, scope?: string) => void>;
392
- let bunchesToAdd: DTBunchStub[];
393
- let addSpy: any;
394
-
395
- beforeEach(() => {
396
- managerTest = new DTManagerTest(IDTest, KeyTest, [], ScopesTest, { errors: false });
397
- addSpy = jest.spyOn(managerTest, 'add').mockImplementation(() => {});
398
-
399
- // Bunches to add
400
- const bunchToAdd1 = new DTBunchStub();
401
- bunchToAdd1._setId(`${IDTestBunch}_1`);
402
- const bunchToAdd2 = new DTBunchStub();
403
- bunchToAdd2._setId(`${IDTestBunch}_2`);
404
- const bunchToAdd3 = new DTBunchStub();
405
- bunchToAdd3._setId(`${IDTestBunch}_3`);
406
- bunchesToAdd = [bunchToAdd1, bunchToAdd2, bunchToAdd3];
407
- });
408
-
409
- test('add many items - use add method - default case', () => {
410
- managerTest.addMany(bunchesToAdd);
411
-
412
- expect(addSpy.mock.calls.length).toBe(3);
413
- let itemCount = 0;
414
- for (const addCalls of addSpy.mock.calls) {
415
- expect(addCalls[0].getId()).toBe(bunchesToAdd[itemCount].getId());
416
- expect(addCalls[1]).toBeUndefined();
417
- itemCount += 1;
418
- }
419
- });
420
-
421
- test('add many items - use add method - with scope case', () => {
422
- managerTest.addMany(bunchesToAdd, ScopesTest[0]);
423
-
424
- expect(addSpy.mock.calls.length).toBe(3);
425
- let itemCount = 0;
426
- for (const addCalls of addSpy.mock.calls) {
427
- expect(addCalls[0].getId()).toBe(bunchesToAdd[itemCount].getId());
428
- expect(addCalls[1]).toBe(ScopesTest[0]);
429
- itemCount += 1;
430
- }
431
- });
432
-
433
- test('errors when adding many items at index - default case - add no items and throw error', () => {
434
- addSpy = jest.spyOn(managerTest, 'add')
435
- .mockImplementationOnce(function (item) {
436
- this._items[`${IDTestBunch}_1`] = {
437
- scope: 'default',
438
- item,
439
- };
440
- })
441
- .mockImplementationOnce(() => {
442
- throw new DTErrorStub();
443
- })
444
- .mockImplementationOnce(function (item) {
445
- this._items[`${IDTestBunch}_3`] = {
446
- scope: 'default',
447
- item,
448
- };
449
- });
450
- let errorThrown: DTError | undefined;
451
- try {
452
- managerTest.addMany(bunchesToAdd);
453
- } catch(error) {
454
- errorThrown = error;
455
- }
456
-
457
- expect(errorThrown).toBeDefined();
458
- expect(Object.keys(managerTest._getItems()).length).toBe(0);
459
- });
460
-
461
- test('errors when adding many items at index - errors case - add success items and stack errors for others', () => {
462
- addSpy = jest.spyOn(managerTest, 'add')
463
- .mockImplementationOnce(function (item) {
464
- this._items[`${IDTestBunch}_1`] = {
465
- scope: 'default',
466
- item,
467
- };
468
- })
469
- .mockImplementationOnce(function () {
470
- this._errors = [new DTErrorStub()];
471
- })
472
- .mockImplementationOnce(function (item) {
473
- this._items[`${IDTestBunch}_3`] = {
474
- scope: 'default',
475
- item,
476
- };
477
- });
478
-
479
- managerTest.addMany(bunchesToAdd);
480
-
481
- expect(addSpy.mock.calls.length).toBe(3);
482
- expect(Object.keys(managerTest._getItems()).length).toBe(2);
483
- });
484
- });
485
-
486
- describe('moveToScope()', () => {
487
- beforeEach(() => {
488
- managerTest = new DTManagerTest(IDTest, KeyTest, [], ScopesTest);
489
- managerTest.populate();
490
- });
491
-
492
- test('move to default scope', () => {
493
- managerTest.moveToScope(`${IDTestBunch}_2`, 'default');
494
-
495
- expect(Object.keys(managerTest._getItems()).length).toBe(3);
496
- checkManagerItem(managerTest, `${IDTestBunch}_2`, 'default');
497
- });
498
-
499
- test('move to existing scope', () => {
500
- managerTest.moveToScope(`${IDTestBunch}_2`, ScopesTest[1]);
501
-
502
- expect(Object.keys(managerTest._getItems()).length).toBe(3);
503
- checkManagerItem(managerTest, `${IDTestBunch}_2`, ScopesTest[1]);
504
- });
505
-
506
- test('move to non-existing scope - trigger invalid_scope error', () => {
507
- let errorThrown: DTError | undefined;
508
- try {
509
- managerTest.moveToScope(`${IDTestBunch}_2`, 'invalid_scope');
510
- } catch(error) {
511
- errorThrown = error;
512
- }
513
-
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
- }
522
- });
523
-
524
- test('move non-virtual bunch to virtual scope - trigger forbidden_virtual_scope error', () => {
525
- let errorThrown: DTError | undefined;
526
- try {
527
- managerTest.moveToScope(`${IDTestBunch}_2`, 'virtual');
528
- } catch(error) {
529
- errorThrown = error;
530
- }
531
-
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
- }
540
- });
541
-
542
- test('move virtual bunch to non-virtual scope - trigger forbidden_scope error', () => {
543
- let errorThrown: DTError | undefined;
544
- try {
545
- managerTest.moveToScope(`${IDTestBunch}_3`, ScopesTest[0]);
546
- } catch(error) {
547
- errorThrown = error;
548
- }
549
-
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
- }
558
- });
559
-
560
- test('move to same scope - nothing append', () => {
561
- managerTest.moveToScope(`${IDTestBunch}_1`, 'default');
562
-
563
- expect(Object.keys(managerTest._getItems()).length).toBe(3);
564
- checkManagerItem(managerTest, `${IDTestBunch}_1`, 'default');
565
- });
566
-
567
- test('move an non-existing bunch id - trigger invalid_id error', () => {
568
- let errorThrown: DTError | undefined;
569
- try {
570
- managerTest.moveToScope(`${IDTestBunch}_5`, ScopesTest[0]);
571
- } catch(error) {
572
- errorThrown = error;
573
- }
574
-
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
- }
582
- });
583
- });
584
-
585
- describe('get()', () => {
586
- beforeEach(() => {
587
- managerTest.populate();
588
- });
589
-
590
- test('return a bunch by its id', () => {
591
- const bunch = managerTest.get(`${IDTestBunch}_1`) as DTBunchStub;
592
-
593
- expect(bunch).toBeDefined();
594
- expect(bunch.getId()).toBe(`${IDTestBunch}_1`);
595
- });
596
-
597
- test('return undefined if bunch is not found', () => {
598
- const bunch = managerTest.get(`${IDTestBunch}_5`);
599
-
600
- expect(bunch).toBeUndefined();
601
- });
602
- });
603
-
604
- describe('getAll()', () => {
605
- beforeEach(() => {
606
- managerTest.populate();
607
- });
608
-
609
- test('return all bunch items', () => {
610
- const bunches = managerTest.getAll() as DTBunchStub[];
611
-
612
- const bunchesIds = bunches.map((bunch) => bunch.getId());
613
- expect(bunchesIds.length).toBe(3);
614
- expect(bunchesIds.includes(`${IDTestBunch}_1`)).toBeTruthy();
615
- expect(bunchesIds.includes(`${IDTestBunch}_2`)).toBeTruthy();
616
- expect(bunchesIds.includes(`${IDTestBunch}_3`)).toBeTruthy();
617
- });
618
-
619
- test('return empty array if no bunch', () => {
620
- managerTest = new DTManagerTest();
621
-
622
- const bunches = managerTest.getAll();
623
-
624
- expect(bunches.length).toBe(0);
625
- });
626
-
627
- test('scope argument : return only bunches into the scope', () => {
628
- const bunches = managerTest.getAll(ScopesTest[0]) as DTBunchStub[];
629
-
630
- const bunchesIds = bunches.map((bunch) => bunch.getId());
631
- expect(bunchesIds.length).toBe(1);
632
- expect(bunchesIds.includes(`${IDTestBunch}_2`)).toBeTruthy();
633
- });
634
-
635
- test('scope argument : return empty array if no bunch into the scope', () => {
636
- const bunches = managerTest.getAll(ScopesTest[1]);
637
-
638
- expect(bunches.length).toBe(0);
639
- });
640
-
641
- test('scope argument : return empty array if invalid scope is passed', () => {
642
- const bunches = managerTest.getAll('invalid_scope');
643
-
644
- expect(bunches.length).toBe(0);
645
- });
646
- });
647
-
648
- describe('getScope()', () => {
649
- beforeEach(() => {
650
- managerTest.populate();
651
- });
652
-
653
- test('get scope for an existing bunch id', () => {
654
- const scope1 = managerTest.getScope(`${IDTestBunch}_1`);
655
- const scope2 = managerTest.getScope(`${IDTestBunch}_2`);
656
- const scope3 = managerTest.getScope(`${IDTestBunch}_3`);
657
-
658
- expect(scope1).toBe('default');
659
- expect(scope2).toBe(ScopesTest[0]);
660
- expect(scope3).toBe('virtual');
661
- });
662
-
663
- test('get undefined scope for an non-existing bunch id', () => {
664
- const scope = managerTest.getScope(`${IDTestBunch}_5`);
665
-
666
- expect(scope).toBeUndefined();
667
- });
668
- });
669
-
670
- describe('remove()', () => {
671
- beforeEach(() => {
672
- managerTest.populate();
673
- });
674
-
675
- test('remove one item using removeMany', () => {
676
- const removeManySpy = jest.spyOn(managerTest, 'removeMany');
677
-
678
- managerTest.remove(`${IDTestBunch}_2`);
679
-
680
- expect(removeManySpy.mock.calls.length).toBe(1);
681
- expect(removeManySpy.mock.calls[0][0]).toStrictEqual([`${IDTestBunch}_2`]);
682
- });
683
- });
684
-
685
- describe('removeMany()', () => {
686
- beforeEach(() => {
687
- managerTest.populate();
688
- });
689
-
690
- test('remove multiple bunches from manager', () => {
691
- managerTest.removeMany([`${IDTestBunch}_1`, `${IDTestBunch}_2`]);
692
-
693
- const newItems = managerTest._getItems();
694
- expect(Object.keys(newItems).length).toBe(1);
695
- expect(Object.keys(newItems)).toStrictEqual([`${IDTestBunch}_3`]);
696
- });
697
-
698
- test('remove non-existing bunches - nothing happen', () => {
699
- managerTest.removeMany([`${IDTestBunch}_5`, `${IDTestBunch}_7`]);
700
-
701
- const newItems = managerTest._getItems();
702
- expect(Object.keys(newItems).length).toBe(3);
703
- expect(Object.keys(newItems)).toStrictEqual([`${IDTestBunch}_1`, `${IDTestBunch}_2`, `${IDTestBunch}_3`]);
704
- });
705
-
706
- test('remove multiple bunches from manager - no removal from library by default', () => {
707
- managerTest.removeMany([`${IDTestBunch}_1`, `${IDTestBunch}_2`]);
708
-
709
- const library = managerTest.getLibrary();
710
- expect(library.getAll().length).toBe(5);
711
- });
712
-
713
- test('remove multiple bunches from manager - libraryDeletion option', () => {
714
- managerTest.removeMany([`${IDTestBunch}_1`, `${IDTestBunch}_2`], { libraryDeletion: true });
715
-
716
- const library = managerTest.getLibrary();
717
- expect(library.getAll().length).toBe(0);
718
- });
719
-
720
- test('remove context when removing a bunch - standard case', () => {
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');
725
-
726
- managerTest.removeMany([`${IDTestBunch}_1`, `${IDTestBunch}_2`]);
727
-
728
- expect(bunch1RemoveContextSpy.mock.calls.length).toBe(1);
729
- expect(bunch2RemoveContextSpy.mock.calls.length).toBe(1);
730
- });
731
-
732
- test('remove a bunch with elements - remove container for all library elements', () => {
733
- managerTest.removeMany([`${IDTestBunch}_1`]);
734
-
735
- const library = managerTest.getLibrary();
736
- for (let element of library.getAll()) {
737
- expect(element.getContext()?.getId()).toBe(IDTest);
738
- expect(element.getContainer()).toBeUndefined();
739
- }
740
- });
741
- });
742
-
743
- describe('removeAll()', () => {
744
- beforeEach(() => {
745
- managerTest.populate();
746
- });
747
-
748
- test('remove all items using removeMany', () => {
749
- const removeManySpy = jest.spyOn(managerTest, 'removeMany');
750
- managerTest.removeAll();
751
-
752
- expect((managerTest.removeMany as any).mock.calls.length).toBe(1);
753
- expect((managerTest.removeMany as any).mock.calls[0][0]).toStrictEqual([`${IDTestBunch}_1`, `${IDTestBunch}_2`, `${IDTestBunch}_3`]);
754
- });
755
- });
756
-
757
- describe('find()', () => {
758
- let findSpy;
759
-
760
- beforeEach(() => {
761
- findSpy = jest.spyOn(managerTest._getFinder(), 'execute');
762
- });
763
-
764
- test('find items using DYOFinder - empty case', () => {
765
- managerTest.find({});
766
-
767
- expect((findSpy as any).mock.calls.length).toBe(1);
768
- expect((findSpy as any).mock.calls[0][0]).toStrictEqual({});
769
- });
770
-
771
- test('find items using DYOFinder', () => {
772
- const testFilters = { id: { $eq: 'id_bunch' }, key: { $ne: 'key_test' } };
773
- managerTest.find(testFilters);
774
-
775
- expect((findSpy as any).mock.calls.length).toBe(1);
776
- expect((findSpy as any).mock.calls[0][0]).toStrictEqual(testFilters);
777
- });
778
- });
779
-
780
- describe('reloadLibrary()', () => {
781
- beforeEach(() => {
782
- managerTest.populate();
783
- const library = managerTest.getLibrary();
784
- library.removeAll();
785
- });
786
-
787
- test('synchronize bunches items into an empty library - one bunch with items', () => {
788
- const expectedAddedItemIds = generateStubElements(5).map((e) => e.getId());
789
- managerTest.reloadLibrary();
790
-
791
- const library = managerTest.getLibrary();
792
- expect(library.getAll().map((e) => e.getId())).toEqual(expectedAddedItemIds);
793
- });
794
-
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();
802
-
803
- managerTest.reloadLibrary();
804
-
805
- expect(library.getAll().map((e) => e.getId())).toEqual(newItems.map(e => e.getId()));
806
- });
807
- });
808
-
809
- describe('toObject()', () => {
810
- beforeEach(() => {
811
- managerTest = new DTManagerTest(IDTest, KeyTest);
812
- })
813
-
814
- test('toObject output standard', () => {
815
- const toObjectManager = managerTest.toObject();
816
-
817
- expect(Object.keys(toObjectManager)).toStrictEqual(['id', 'key', 'type', 'items']);
818
- expect(toObjectManager.id).toBe(IDTest);
819
- expect(toObjectManager.key).toBe(KeyTest);
820
- expect(toObjectManager.type).toBe('manager');
821
- expect(toObjectManager.items.length).toBe(0);
822
- });
823
-
824
- test('toObject output with items', () => {
825
- managerTest.populate();
826
-
827
- const toObjectManager = managerTest.toObject();
828
-
829
- expect(Object.keys(toObjectManager)).toStrictEqual(['id', 'key', 'type', 'items']);
830
- expect(toObjectManager.items.length).toBe(3);
831
- expect(toObjectManager.items).toStrictEqual([
832
- { scope: 'default', ...bunch1toObjectTest },
833
- { scope: ScopesTest[0], ...bunch2toObjectTest },
834
- { scope: 'virtual', ...bunch3toObjectTest },
835
- ]);
836
- });
837
- });
838
-
839
- describe('toString()', () => {
840
- beforeEach(() => {
841
- managerTest = new DTManagerTest(IDTest, KeyTest);
842
- })
843
-
844
- test('string output standard', () => {
845
- const toStringManager = managerTest.toString();
846
-
847
- expect(toStringManager).toBe(`Component ${KeyTest} - Type: Manager - Library: 0 - Items: 0`);
848
- });
849
-
850
- test('string output with domain', () => {
851
- managerTest = new DTManagerTestDomain(IDTest, KeyTest);
852
-
853
- const toStringManager = managerTest.toString();
854
-
855
- expect(toStringManager).toBe(`Component ${DomainTest} ${KeyTest} - Type: Manager - Library: 0 - Items: 0`);
856
- });
857
-
858
- test('string output with library', () => {
859
- managerTest = new DTManagerTest(IDTest, KeyTest, generateStubElements(5));
860
-
861
- const toStringManager = managerTest.toString();
862
-
863
- expect(toStringManager).toBe(`Component ${KeyTest} - Type: Manager - Library: 5 - Items: 0`);
864
- });
865
-
866
- test('string output with library and items', () => {
867
- managerTest.populate();
868
-
869
- const toStringManager = managerTest.toString();
870
-
871
- expect(toStringManager).toBe(`Component ${KeyTest} - Type: Manager - Library: 5 - Items: 3`);
872
- });
873
- });
874
- });