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