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.
- package/{dist/index.d.ts → index.d.ts} +1 -0
- package/{dist/index.d.ts.map → index.d.ts.map} +1 -1
- package/{dist/index.js → index.js} +1 -0
- package/package.json +6 -56
- package/.c8rc.json +0 -4
- package/.eslintignore +0 -2
- package/.eslintrc.json +0 -47
- package/Makefile +0 -34
- package/README.md +0 -0
- package/babel.config.js +0 -1
- package/docs/.nojekyll +0 -1
- package/docs/assets/highlight.css +0 -29
- package/docs/assets/main.js +0 -59
- package/docs/assets/search.js +0 -1
- package/docs/assets/style.css +0 -1414
- package/docs/index.html +0 -1
- package/integration/data/components/DTHero.ts +0 -42
- package/integration/data/components/DTHeroManager.ts +0 -11
- package/integration/data/components/DTHeroPlayZone.ts +0 -6
- package/integration/data/components/DTHeroPlayerHand.ts +0 -11
- package/integration/data/components/index.ts +0 -5
- package/integration/data/in/heroIn.helper.ts +0 -8
- package/integration/data/in/playerIn.helper.ts +0 -13
- package/integration/data/out/heroOut.helper.ts +0 -48
- package/integration/endings/synchronisation.ending.ts +0 -25
- package/integration/scenes/drawCard.scene.ts +0 -31
- package/integration/scenes/empty.scene.ts +0 -6
- package/integration/scenes/playCard.scene.ts +0 -23
- package/integration/scenes/playerLeave.scene.ts +0 -33
- package/integration/stages/baseDix.stage.ts +0 -137
- package/integration/stages/syncDix.stage.ts +0 -36
- package/integration/tests/scenario1.spec.ts +0 -55
- package/integration/types/index.ts +0 -24
- package/jest-integration.config.ts +0 -25
- package/jest.config.ts +0 -26
- package/src/constants.ts +0 -87
- package/src/core/DTAction.ts +0 -54
- package/src/core/DTBunch.ts +0 -531
- package/src/core/DTComponent.ts +0 -258
- package/src/core/DTComponentPhysical.ts +0 -88
- package/src/core/DTComponentWithMeta.ts +0 -98
- package/src/core/DTElement.ts +0 -111
- package/src/core/DTError.ts +0 -78
- package/src/core/DTManager.ts +0 -555
- package/src/core/DTMaster.ts +0 -366
- package/src/core/DTModule.ts +0 -96
- package/src/index.ts +0 -17
- package/src/libs/DYOFinder.ts +0 -175
- package/src/libs/dix/DIXModule.module.ts +0 -98
- package/src/libs/player/DTPlayer.element.ts +0 -9
- package/src/libs/player/DTPlayer.manager.ts +0 -70
- package/src/types/core.ts +0 -204
- package/src/types/index.ts +0 -2
- package/src/types/player.ts +0 -5
- package/test/core/DTAction.double.ts +0 -62
- package/test/core/DTAction.spec.ts +0 -68
- package/test/core/DTBunch.double.ts +0 -175
- package/test/core/DTBunch.spec.ts +0 -822
- package/test/core/DTComponent.double.ts +0 -179
- package/test/core/DTComponent.spec.ts +0 -297
- package/test/core/DTComponentPhysical.double.ts +0 -62
- package/test/core/DTComponentPhysical.spec.ts +0 -81
- package/test/core/DTComponentWithMeta.double.ts +0 -122
- package/test/core/DTComponentWithMeta.spec.ts +0 -129
- package/test/core/DTElement.double.ts +0 -142
- package/test/core/DTElement.spec.ts +0 -123
- package/test/core/DTError.double.ts +0 -57
- package/test/core/DTError.spec.ts +0 -78
- package/test/core/DTManager.double.ts +0 -149
- package/test/core/DTManager.spec.ts +0 -874
- package/test/core/DTMaster.double.ts +0 -117
- package/test/core/DTMaster.spec.ts +0 -537
- package/test/core/DTModule.double.ts +0 -67
- package/test/core/DTModule.spec.ts +0 -124
- package/test/core/copy.spec.ts +0 -222
- package/test/libs/DYOFinder.double.ts +0 -152
- package/test/libs/DYOFinder.spec.ts +0 -194
- package/test/libs/player/DTPlayer.element.double.ts +0 -55
- package/test/libs/player/DTPlayer.element.spec.ts +0 -28
- package/test/libs/player/DTPlayer.manager.double.ts +0 -92
- package/test/libs/player/DTPlayer.manager.spec.ts +0 -178
- package/tsconfig.dev.json +0 -19
- package/tsconfig.json +0 -18
- /package/{dist/constants.d.ts → constants.d.ts} +0 -0
- /package/{dist/constants.d.ts.map → constants.d.ts.map} +0 -0
- /package/{dist/constants.js → constants.js} +0 -0
- /package/{dist/constants.js.map → constants.js.map} +0 -0
- /package/{dist/core → core}/DTAction.d.ts +0 -0
- /package/{dist/core → core}/DTAction.d.ts.map +0 -0
- /package/{dist/core → core}/DTAction.js +0 -0
- /package/{dist/core → core}/DTAction.js.map +0 -0
- /package/{dist/core → core}/DTBunch.d.ts +0 -0
- /package/{dist/core → core}/DTBunch.d.ts.map +0 -0
- /package/{dist/core → core}/DTBunch.js +0 -0
- /package/{dist/core → core}/DTBunch.js.map +0 -0
- /package/{dist/core → core}/DTComponent.d.ts +0 -0
- /package/{dist/core → core}/DTComponent.d.ts.map +0 -0
- /package/{dist/core → core}/DTComponent.js +0 -0
- /package/{dist/core → core}/DTComponent.js.map +0 -0
- /package/{dist/core → core}/DTComponentPhysical.d.ts +0 -0
- /package/{dist/core → core}/DTComponentPhysical.d.ts.map +0 -0
- /package/{dist/core → core}/DTComponentPhysical.js +0 -0
- /package/{dist/core → core}/DTComponentPhysical.js.map +0 -0
- /package/{dist/core → core}/DTComponentWithMeta.d.ts +0 -0
- /package/{dist/core → core}/DTComponentWithMeta.d.ts.map +0 -0
- /package/{dist/core → core}/DTComponentWithMeta.js +0 -0
- /package/{dist/core → core}/DTComponentWithMeta.js.map +0 -0
- /package/{dist/core → core}/DTElement.d.ts +0 -0
- /package/{dist/core → core}/DTElement.d.ts.map +0 -0
- /package/{dist/core → core}/DTElement.js +0 -0
- /package/{dist/core → core}/DTElement.js.map +0 -0
- /package/{dist/core → core}/DTError.d.ts +0 -0
- /package/{dist/core → core}/DTError.d.ts.map +0 -0
- /package/{dist/core → core}/DTError.js +0 -0
- /package/{dist/core → core}/DTError.js.map +0 -0
- /package/{dist/core → core}/DTManager.d.ts +0 -0
- /package/{dist/core → core}/DTManager.d.ts.map +0 -0
- /package/{dist/core → core}/DTManager.js +0 -0
- /package/{dist/core → core}/DTManager.js.map +0 -0
- /package/{dist/core → core}/DTMaster.d.ts +0 -0
- /package/{dist/core → core}/DTMaster.d.ts.map +0 -0
- /package/{dist/core → core}/DTMaster.js +0 -0
- /package/{dist/core → core}/DTMaster.js.map +0 -0
- /package/{dist/core → core}/DTModule.d.ts +0 -0
- /package/{dist/core → core}/DTModule.d.ts.map +0 -0
- /package/{dist/core → core}/DTModule.js +0 -0
- /package/{dist/core → core}/DTModule.js.map +0 -0
- /package/{dist/index.js.map → index.js.map} +0 -0
- /package/{dist/libs → libs}/DYOFinder.d.ts +0 -0
- /package/{dist/libs → libs}/DYOFinder.d.ts.map +0 -0
- /package/{dist/libs → libs}/DYOFinder.js +0 -0
- /package/{dist/libs → libs}/DYOFinder.js.map +0 -0
- /package/{dist/libs → libs}/dix/DIXModule.module.d.ts +0 -0
- /package/{dist/libs → libs}/dix/DIXModule.module.d.ts.map +0 -0
- /package/{dist/libs → libs}/dix/DIXModule.module.js +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.element.d.ts +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.element.d.ts.map +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.element.js +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.element.js.map +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.manager.d.ts +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.manager.d.ts.map +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.manager.js +0 -0
- /package/{dist/libs → libs}/player/DTPlayer.manager.js.map +0 -0
- /package/{dist/tsconfig.dev.tsbuildinfo → tsconfig.dev.tsbuildinfo} +0 -0
- /package/{dist/tsconfig.tsbuildinfo → tsconfig.tsbuildinfo} +0 -0
- /package/{dist/types → types}/core.d.ts +0 -0
- /package/{dist/types → types}/core.d.ts.map +0 -0
- /package/{dist/types → types}/core.js +0 -0
- /package/{dist/types → types}/core.js.map +0 -0
- /package/{dist/types → types}/index.d.ts +0 -0
- /package/{dist/types → types}/index.d.ts.map +0 -0
- /package/{dist/types → types}/index.js +0 -0
- /package/{dist/types → types}/index.js.map +0 -0
- /package/{dist/types → types}/player.d.ts +0 -0
- /package/{dist/types → types}/player.d.ts.map +0 -0
- /package/{dist/types → types}/player.js +0 -0
- /package/{dist/types → types}/player.js.map +0 -0
|
@@ -1,117 +0,0 @@
|
|
|
1
|
-
import {expect, jest} from "@jest/globals";
|
|
2
|
-
import {DTMaster} from "../../src";
|
|
3
|
-
import {DTManagerStub, IDTest as IDManagerTest, manager1IDTest, manager1KeyTest} from "./DTManager.double";
|
|
4
|
-
import {action1IDTest, action1KeyTest, DTActionStub, IDTest as IDActionTest} from "./DTAction.double";
|
|
5
|
-
import {DTModuleStub, IDTest as IDModuleTest, module1IDTest, module1KeyTest} from "./DTModule.double";
|
|
6
|
-
|
|
7
|
-
/** ****************** STUB PROPERTIES CONSTANTS
|
|
8
|
-
* Fixed properties to use with double classes, avoid auto generated and easy checking on test
|
|
9
|
-
* **** */
|
|
10
|
-
export const IDTest = 'DTMaster-id-1234567';
|
|
11
|
-
export const KeyTest = 'DTMaster-key-1234567';
|
|
12
|
-
|
|
13
|
-
/** ****************** HELPER TEST CLASS
|
|
14
|
-
* Helper test class, inherits the main component
|
|
15
|
-
* Providing methods to property access and other facilities, in order to avoid using class methods
|
|
16
|
-
* **** */
|
|
17
|
-
export class DTMasterTest extends DTMaster {
|
|
18
|
-
constructor(
|
|
19
|
-
id: string = IDTest,
|
|
20
|
-
key: string = KeyTest,
|
|
21
|
-
managers: Record<string, DTManagerStub> = {},
|
|
22
|
-
actions: Record<string, DTActionStub> = {},
|
|
23
|
-
modules: Record<string, DTModuleStub> = {},
|
|
24
|
-
) {
|
|
25
|
-
super(key);
|
|
26
|
-
this._id = id;
|
|
27
|
-
this._managers = managers;
|
|
28
|
-
this._actions = actions;
|
|
29
|
-
this._modules = modules;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
_getManagers() {
|
|
33
|
-
return this._managers;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
_getActions() {
|
|
37
|
-
return this._actions;
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
_getModules() {
|
|
41
|
-
return this._modules;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
populate() {
|
|
45
|
-
// Managers
|
|
46
|
-
const manager1 = new DTManagerStub();
|
|
47
|
-
const manager2 = new DTManagerStub();
|
|
48
|
-
manager2._setId(manager1IDTest);
|
|
49
|
-
manager2._setKey(manager1KeyTest);
|
|
50
|
-
|
|
51
|
-
this._managers = {
|
|
52
|
-
[IDManagerTest]: manager1,
|
|
53
|
-
[manager1IDTest]: manager2
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
// Actions
|
|
57
|
-
const action1 = new DTActionStub();
|
|
58
|
-
const action2 = new DTActionStub();
|
|
59
|
-
action2._setId(action1IDTest);
|
|
60
|
-
action2._setKey(action1KeyTest);
|
|
61
|
-
|
|
62
|
-
this._actions = {
|
|
63
|
-
[IDActionTest]: action1,
|
|
64
|
-
[action1IDTest]: action2
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
// Modules
|
|
68
|
-
const module1 = new DTModuleStub();
|
|
69
|
-
const module2 = new DTModuleStub();
|
|
70
|
-
module2._setId(module1IDTest);
|
|
71
|
-
module2._setKey(module1KeyTest);
|
|
72
|
-
module2.disable();
|
|
73
|
-
|
|
74
|
-
this._modules = {
|
|
75
|
-
[IDModuleTest]: module1,
|
|
76
|
-
[module1IDTest]: module2
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
/** ****************** STUB CLASS
|
|
83
|
-
* Stub class, for using in other component
|
|
84
|
-
* **** */
|
|
85
|
-
|
|
86
|
-
/** ****************** HELPER METHODS
|
|
87
|
-
* Additional helper methods to use with testing
|
|
88
|
-
* **** */
|
|
89
|
-
export const checkMasterManagers = (master: DTMasterTest, ids: string[]) => {
|
|
90
|
-
let i = 0;
|
|
91
|
-
expect(Object.keys(master._getManagers()).length).toBe(ids.length);
|
|
92
|
-
for (let [id, manager] of Object.entries(master._getManagers())) {
|
|
93
|
-
expect(id).toBe(ids[i]);
|
|
94
|
-
expect(manager.getId()).toBe(ids[i]);
|
|
95
|
-
i++;
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
export const checkMasterActions = (master: DTMasterTest, ids: string[]) => {
|
|
100
|
-
let i = 0;
|
|
101
|
-
expect(Object.keys(master._getActions()).length).toBe(ids.length);
|
|
102
|
-
for (let [id, action] of Object.entries(master._getActions())) {
|
|
103
|
-
expect(id).toBe(ids[i]);
|
|
104
|
-
expect(action.getId()).toBe(ids[i]);
|
|
105
|
-
i++;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
export const checkMasterModules = (master: DTMasterTest, ids: string[]) => {
|
|
110
|
-
let i = 0;
|
|
111
|
-
expect(Object.keys(master._getModules()).length).toBe(ids.length);
|
|
112
|
-
for (let [id, module] of Object.entries(master._getModules())) {
|
|
113
|
-
expect(id).toBe(ids[i]);
|
|
114
|
-
expect(module.getId()).toBe(ids[i]);
|
|
115
|
-
i++;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
@@ -1,537 +0,0 @@
|
|
|
1
|
-
import {afterEach, beforeEach, describe, expect, jest, test} from "@jest/globals";
|
|
2
|
-
import {DTComponent, DTError, DTMaster} from "../../src";
|
|
3
|
-
import {
|
|
4
|
-
checkMasterActions,
|
|
5
|
-
checkMasterManagers,
|
|
6
|
-
checkMasterModules,
|
|
7
|
-
DTMasterTest,
|
|
8
|
-
IDTest,
|
|
9
|
-
KeyTest
|
|
10
|
-
} from "./DTMaster.double";
|
|
11
|
-
import {
|
|
12
|
-
DTManagerStub,
|
|
13
|
-
IDTest as manager1IDTest,
|
|
14
|
-
manager1IDTest as manager2IDTest,
|
|
15
|
-
manager1KeyTest as manager2KeyTest,
|
|
16
|
-
manager1ToObject
|
|
17
|
-
} from "./DTManager.double";
|
|
18
|
-
import {
|
|
19
|
-
action1IDTest as action2IDTest,
|
|
20
|
-
action1KeyTest as action2KeyTest,
|
|
21
|
-
action1ToObject,
|
|
22
|
-
DTActionStub,
|
|
23
|
-
IDTest as action1IDTest,
|
|
24
|
-
KeyTest as action1KeyTest
|
|
25
|
-
} from "./DTAction.double";
|
|
26
|
-
import {
|
|
27
|
-
DTModuleStub,
|
|
28
|
-
IDTest as module1IDTest,
|
|
29
|
-
module1IDTest as module2IDTest,
|
|
30
|
-
module1KeyTest as module2KeyTest,
|
|
31
|
-
module1ToObject
|
|
32
|
-
} from "./DTModule.double";
|
|
33
|
-
|
|
34
|
-
/** *********************** TESTS SUITES ****************************** */
|
|
35
|
-
describe('class DTMaster', () => {
|
|
36
|
-
let masterTest: DTMasterTest;
|
|
37
|
-
|
|
38
|
-
beforeEach(() => {
|
|
39
|
-
masterTest = new DTMasterTest();
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
afterEach(() => {
|
|
43
|
-
jest.resetAllMocks();
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
describe('inheritance', () => {
|
|
47
|
-
test('check good inheritance for class', () => {
|
|
48
|
-
expect(DTMaster.prototype instanceof DTComponent).toBeTruthy();
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
describe('_componentType', () => {
|
|
53
|
-
test('componentType must be "master"', () => {
|
|
54
|
-
expect(masterTest.getComponentType()).toBe('master');
|
|
55
|
-
});
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
describe('constructor()', () => {
|
|
59
|
-
beforeEach(() => {
|
|
60
|
-
jest.resetAllMocks();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
test('simple creation with key', () => {
|
|
64
|
-
const newMaster = new DTMasterTest(IDTest, KeyTest);
|
|
65
|
-
|
|
66
|
-
expect(newMaster._getManagers()).toStrictEqual({});
|
|
67
|
-
expect(newMaster._getActions()).toStrictEqual({});
|
|
68
|
-
expect(newMaster._getModules()).toStrictEqual({});
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
describe('addManager()', () => {
|
|
74
|
-
let managerToAdd: DTManagerStub;
|
|
75
|
-
|
|
76
|
-
beforeEach(() => {
|
|
77
|
-
managerToAdd = new DTManagerStub();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
test('add a new manager - standard case', () => {
|
|
81
|
-
masterTest.addManager(managerToAdd);
|
|
82
|
-
|
|
83
|
-
checkMasterManagers(masterTest, [manager1IDTest]);
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
test('trigger error when adding two managers with same id', () => {
|
|
87
|
-
masterTest.addManager(managerToAdd);
|
|
88
|
-
let errorThrown: DTError | undefined;
|
|
89
|
-
try {
|
|
90
|
-
masterTest.addManager(managerToAdd);
|
|
91
|
-
} catch(error) {
|
|
92
|
-
errorThrown = error;
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
expect(errorThrown).toBeDefined();
|
|
96
|
-
expect(Object.keys(masterTest._getManagers()).length).toBe(1);
|
|
97
|
-
if (errorThrown) {
|
|
98
|
-
expect(errorThrown.getCode()).toBe('id_conflict');
|
|
99
|
-
expect(errorThrown.getMessage()).toBe('Manager with same id already exists in the Master instance');
|
|
100
|
-
expect(errorThrown.getInitiator().getId()).toBe(IDTest);
|
|
101
|
-
expect(errorThrown.getConvicted().getId()).toBe(managerToAdd.getId());
|
|
102
|
-
}
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
test('trigger error when adding two managers with same key', () => {
|
|
106
|
-
const firstManager = new DTManagerStub();
|
|
107
|
-
firstManager._setId(manager2IDTest);
|
|
108
|
-
masterTest.addManager(firstManager);
|
|
109
|
-
let errorThrown: DTError | undefined;
|
|
110
|
-
try {
|
|
111
|
-
masterTest.addManager(managerToAdd);
|
|
112
|
-
} catch(error) {
|
|
113
|
-
errorThrown = error;
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
expect(errorThrown).toBeDefined();
|
|
117
|
-
expect(Object.keys(masterTest._getManagers()).length).toBe(1);
|
|
118
|
-
if (errorThrown) {
|
|
119
|
-
expect(errorThrown.getCode()).toBe('key_conflict');
|
|
120
|
-
expect(errorThrown.getMessage()).toBe('Manager with same key already exists in the Master instance');
|
|
121
|
-
expect(errorThrown.getInitiator().getId()).toBe(IDTest);
|
|
122
|
-
expect(errorThrown.getConvicted().getId()).toBe(managerToAdd.getId());
|
|
123
|
-
}
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
test('set context when adding a new manager', () => {
|
|
127
|
-
const setContextSpy = jest.spyOn(managerToAdd, 'setContext');
|
|
128
|
-
|
|
129
|
-
masterTest.addManager(managerToAdd);
|
|
130
|
-
|
|
131
|
-
expect(setContextSpy.mock.calls.length).toBe(1);
|
|
132
|
-
expect(setContextSpy.mock.calls[0][0].getId()).toBe(IDTest);
|
|
133
|
-
});
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
describe('getManager()', () => {
|
|
137
|
-
beforeEach(() => {
|
|
138
|
-
masterTest.populate();
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
test('return a manager by its id', () => {
|
|
142
|
-
const manager = masterTest.getManager(manager1IDTest);
|
|
143
|
-
|
|
144
|
-
expect(manager).toBeDefined();
|
|
145
|
-
expect(manager.getId()).toBe(manager1IDTest);
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
test('return a manager by its key', () => {
|
|
149
|
-
const manager = masterTest.getManager(manager2KeyTest);
|
|
150
|
-
|
|
151
|
-
expect(manager).toBeDefined();
|
|
152
|
-
expect(manager.getKey()).toBe(manager2KeyTest);
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
test('return undefined if manager is not found', () => {
|
|
156
|
-
const manager = masterTest.getManager('unexisting-id');
|
|
157
|
-
|
|
158
|
-
expect(manager).toBeUndefined();
|
|
159
|
-
});
|
|
160
|
-
});
|
|
161
|
-
|
|
162
|
-
describe('removeManager()', () => {
|
|
163
|
-
beforeEach(() => {
|
|
164
|
-
masterTest.populate();
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
test('remove a manager by its id', () => {
|
|
168
|
-
masterTest.removeManager(manager1IDTest);
|
|
169
|
-
|
|
170
|
-
expect(Object.keys(masterTest._getManagers()).length).toBe(1);
|
|
171
|
-
expect(Object.keys(masterTest._getManagers())[0]).toBe(manager2IDTest);
|
|
172
|
-
});
|
|
173
|
-
|
|
174
|
-
test('remove a manager by its key', () => {
|
|
175
|
-
masterTest.removeManager(manager2KeyTest);
|
|
176
|
-
|
|
177
|
-
expect(Object.keys(masterTest._getManagers()).length).toBe(1);
|
|
178
|
-
expect(Object.keys(masterTest._getManagers())[0]).toBe(manager1IDTest);
|
|
179
|
-
});
|
|
180
|
-
|
|
181
|
-
test('no removal if manager is not found', () => {
|
|
182
|
-
masterTest.removeManager('unexisting-id');
|
|
183
|
-
|
|
184
|
-
expect(Object.keys(masterTest._getManagers()).length).toBe(2);
|
|
185
|
-
expect(Object.keys(masterTest._getManagers())[0]).toBe(manager1IDTest);
|
|
186
|
-
expect(Object.keys(masterTest._getManagers())[1]).toBe(manager2IDTest);
|
|
187
|
-
});
|
|
188
|
-
});
|
|
189
|
-
|
|
190
|
-
describe('addAction()', () => {
|
|
191
|
-
let actionToAdd: DTActionStub;
|
|
192
|
-
|
|
193
|
-
beforeEach(() => {
|
|
194
|
-
actionToAdd = new DTActionStub();
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
test('add a new action - standard case', () => {
|
|
198
|
-
masterTest.addAction(actionToAdd);
|
|
199
|
-
|
|
200
|
-
checkMasterActions(masterTest, [action1IDTest]);
|
|
201
|
-
});
|
|
202
|
-
|
|
203
|
-
test('trigger error when adding two actions with same id', () => {
|
|
204
|
-
masterTest.addAction(actionToAdd);
|
|
205
|
-
let errorThrown: DTError | undefined;
|
|
206
|
-
try {
|
|
207
|
-
masterTest.addAction(actionToAdd);
|
|
208
|
-
} catch(error) {
|
|
209
|
-
errorThrown = error;
|
|
210
|
-
}
|
|
211
|
-
|
|
212
|
-
expect(errorThrown).toBeDefined();
|
|
213
|
-
expect(Object.keys(masterTest._getActions()).length).toBe(1);
|
|
214
|
-
if (errorThrown) {
|
|
215
|
-
expect(errorThrown.getCode()).toBe('id_conflict');
|
|
216
|
-
expect(errorThrown.getMessage()).toBe('Action with same id already exists in the Master instance');
|
|
217
|
-
expect(errorThrown.getInitiator().getId()).toBe(IDTest);
|
|
218
|
-
expect(errorThrown.getConvicted().getId()).toBe(actionToAdd.getId());
|
|
219
|
-
}
|
|
220
|
-
});
|
|
221
|
-
|
|
222
|
-
test('trigger error when adding two actions with same key', () => {
|
|
223
|
-
const firstAction = new DTActionStub();
|
|
224
|
-
firstAction._setId(action2IDTest);
|
|
225
|
-
masterTest.addAction(firstAction);
|
|
226
|
-
let errorThrown: DTError | undefined;
|
|
227
|
-
try {
|
|
228
|
-
masterTest.addAction(actionToAdd);
|
|
229
|
-
} catch(error) {
|
|
230
|
-
errorThrown = error;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
expect(errorThrown).toBeDefined();
|
|
234
|
-
expect(Object.keys(masterTest._getActions()).length).toBe(1);
|
|
235
|
-
if (errorThrown) {
|
|
236
|
-
expect(errorThrown.getCode()).toBe('key_conflict');
|
|
237
|
-
expect(errorThrown.getMessage()).toBe('Action with same key already exists in the Master instance');
|
|
238
|
-
expect(errorThrown.getInitiator().getId()).toBe(IDTest);
|
|
239
|
-
expect(errorThrown.getConvicted().getId()).toBe(actionToAdd.getId());
|
|
240
|
-
}
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
test('set context when adding a new action', () => {
|
|
244
|
-
const setContextSpy = jest.spyOn(actionToAdd, 'setContext');
|
|
245
|
-
|
|
246
|
-
masterTest.addAction(actionToAdd);
|
|
247
|
-
|
|
248
|
-
expect(setContextSpy.mock.calls.length).toBe(1);
|
|
249
|
-
expect(setContextSpy.mock.calls[0][0].getId()).toBe(IDTest);
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
describe('getAction()', () => {
|
|
254
|
-
beforeEach(() => {
|
|
255
|
-
masterTest.populate();
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
test('return an action by its id', () => {
|
|
259
|
-
const action = masterTest.getAction(action1IDTest);
|
|
260
|
-
|
|
261
|
-
expect(action).toBeDefined();
|
|
262
|
-
expect(action.getId()).toBe(action1IDTest);
|
|
263
|
-
});
|
|
264
|
-
|
|
265
|
-
test('return an action by its key', () => {
|
|
266
|
-
const action = masterTest.getAction(action2KeyTest);
|
|
267
|
-
|
|
268
|
-
expect(action).toBeDefined();
|
|
269
|
-
expect(action.getId()).toBe(action2IDTest);
|
|
270
|
-
});
|
|
271
|
-
|
|
272
|
-
test('return undefined if action is not found', () => {
|
|
273
|
-
const action = masterTest.getAction('unexisting-id');
|
|
274
|
-
|
|
275
|
-
expect(action).toBeUndefined();
|
|
276
|
-
});
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
describe('removeAction()', () => {
|
|
280
|
-
beforeEach(() => {
|
|
281
|
-
masterTest.populate();
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
test('remove an action by its id', () => {
|
|
285
|
-
masterTest.removeAction(action1IDTest);
|
|
286
|
-
|
|
287
|
-
expect(Object.keys(masterTest._getActions()).length).toBe(1);
|
|
288
|
-
expect(Object.keys(masterTest._getActions())[0]).toBe(action2IDTest);
|
|
289
|
-
});
|
|
290
|
-
|
|
291
|
-
test('remove an action by its key', () => {
|
|
292
|
-
masterTest.removeAction(action2KeyTest);
|
|
293
|
-
|
|
294
|
-
expect(Object.keys(masterTest._getActions()).length).toBe(1);
|
|
295
|
-
expect(Object.keys(masterTest._getActions())[0]).toBe(action1IDTest);
|
|
296
|
-
});
|
|
297
|
-
|
|
298
|
-
test('no removal if action is not found', () => {
|
|
299
|
-
masterTest.removeAction('unexisting-id');
|
|
300
|
-
|
|
301
|
-
expect(Object.keys(masterTest._getActions()).length).toBe(2);
|
|
302
|
-
expect(Object.keys(masterTest._getActions())[0]).toBe(action1IDTest);
|
|
303
|
-
expect(Object.keys(masterTest._getActions())[1]).toBe(action2IDTest);
|
|
304
|
-
});
|
|
305
|
-
});
|
|
306
|
-
|
|
307
|
-
describe('executeAction()', () => {
|
|
308
|
-
beforeEach(() => {
|
|
309
|
-
masterTest.populate();
|
|
310
|
-
});
|
|
311
|
-
|
|
312
|
-
test('call execute method with payload for action by its id', async () => {
|
|
313
|
-
const payload = 'execute action from master by id';
|
|
314
|
-
const expectedPayload = `${action1KeyTest} : execute action from master by id`;
|
|
315
|
-
|
|
316
|
-
await expect(masterTest.executeAction(action1IDTest, payload)).rejects.toBe(expectedPayload);
|
|
317
|
-
});
|
|
318
|
-
|
|
319
|
-
test('call execute method with payload for action by its key', async () => {
|
|
320
|
-
const payload = 'execute action from master by key';
|
|
321
|
-
const expectedPayload = `${action2KeyTest} : execute action from master by key`;
|
|
322
|
-
|
|
323
|
-
await expect(masterTest.executeAction(action2KeyTest, payload)).rejects.toBe(expectedPayload);
|
|
324
|
-
});
|
|
325
|
-
|
|
326
|
-
test('no call of execute if action not found', async () => {
|
|
327
|
-
const payload = 'execute action from master';
|
|
328
|
-
|
|
329
|
-
// The assertion here only test that the execute method is not called, so there is no promise rejection
|
|
330
|
-
await expect(masterTest.executeAction('unexisting-id', payload)).resolves.toBeUndefined();
|
|
331
|
-
});
|
|
332
|
-
});
|
|
333
|
-
|
|
334
|
-
describe('addModule()', () => {
|
|
335
|
-
let moduleToAdd: DTModuleStub;
|
|
336
|
-
|
|
337
|
-
beforeEach(() => {
|
|
338
|
-
moduleToAdd = new DTModuleStub();
|
|
339
|
-
});
|
|
340
|
-
|
|
341
|
-
test('add a new module - standard case', () => {
|
|
342
|
-
masterTest.addModule(moduleToAdd);
|
|
343
|
-
|
|
344
|
-
checkMasterModules(masterTest, [module1IDTest]);
|
|
345
|
-
});
|
|
346
|
-
|
|
347
|
-
test('trigger error when adding two modules with same id', () => {
|
|
348
|
-
masterTest.addModule(moduleToAdd);
|
|
349
|
-
let errorThrown: DTError | undefined;
|
|
350
|
-
try {
|
|
351
|
-
masterTest.addModule(moduleToAdd);
|
|
352
|
-
} catch(error) {
|
|
353
|
-
errorThrown = error;
|
|
354
|
-
}
|
|
355
|
-
|
|
356
|
-
expect(errorThrown).toBeDefined();
|
|
357
|
-
expect(Object.keys(masterTest._getModules()).length).toBe(1);
|
|
358
|
-
if (errorThrown) {
|
|
359
|
-
expect(errorThrown.getCode()).toBe('id_conflict');
|
|
360
|
-
expect(errorThrown.getMessage()).toBe('Module with same id already exists in the Master instance');
|
|
361
|
-
expect(errorThrown.getInitiator().getId()).toBe(IDTest);
|
|
362
|
-
expect(errorThrown.getConvicted().getId()).toBe(moduleToAdd.getId());
|
|
363
|
-
}
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
test('trigger error when adding two modules with same key', () => {
|
|
367
|
-
const firstModule = new DTModuleStub();
|
|
368
|
-
firstModule._setId(module2IDTest);
|
|
369
|
-
masterTest.addModule(firstModule);
|
|
370
|
-
let errorThrown: DTError | undefined;
|
|
371
|
-
try {
|
|
372
|
-
masterTest.addModule(moduleToAdd);
|
|
373
|
-
} catch(error) {
|
|
374
|
-
errorThrown = error;
|
|
375
|
-
}
|
|
376
|
-
|
|
377
|
-
expect(errorThrown).toBeDefined();
|
|
378
|
-
expect(Object.keys(masterTest._getModules()).length).toBe(1);
|
|
379
|
-
if (errorThrown) {
|
|
380
|
-
expect(errorThrown.getCode()).toBe('key_conflict');
|
|
381
|
-
expect(errorThrown.getMessage()).toBe('Module with same key already exists in the Master instance');
|
|
382
|
-
expect(errorThrown.getInitiator().getId()).toBe(IDTest);
|
|
383
|
-
expect(errorThrown.getConvicted().getId()).toBe(moduleToAdd.getId());
|
|
384
|
-
}
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
test('set context when adding a new module', () => {
|
|
388
|
-
const setContextSpy = jest.spyOn(moduleToAdd, 'setContext');
|
|
389
|
-
|
|
390
|
-
masterTest.addModule(moduleToAdd);
|
|
391
|
-
|
|
392
|
-
expect(setContextSpy.mock.calls.length).toBe(1);
|
|
393
|
-
expect(setContextSpy.mock.calls[0][0].getId()).toBe(IDTest);
|
|
394
|
-
});
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
describe('getModule()', () => {
|
|
398
|
-
beforeEach(() => {
|
|
399
|
-
masterTest.populate();
|
|
400
|
-
});
|
|
401
|
-
|
|
402
|
-
test('return a module by its id', () => {
|
|
403
|
-
const module = masterTest.getModule(module1IDTest);
|
|
404
|
-
|
|
405
|
-
expect(module).toBeDefined();
|
|
406
|
-
expect(module.getId()).toBe(module1IDTest);
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
test('return a module by its key', () => {
|
|
410
|
-
const module = masterTest.getModule(module2KeyTest);
|
|
411
|
-
|
|
412
|
-
expect(module).toBeDefined();
|
|
413
|
-
expect(module.getId()).toBe(module2IDTest);
|
|
414
|
-
});
|
|
415
|
-
|
|
416
|
-
test('return undefined if module is not found', () => {
|
|
417
|
-
const module = masterTest.getModule('unexisting-id');
|
|
418
|
-
|
|
419
|
-
expect(module).toBeUndefined();
|
|
420
|
-
});
|
|
421
|
-
});
|
|
422
|
-
|
|
423
|
-
describe('removeModule()', () => {
|
|
424
|
-
beforeEach(() => {
|
|
425
|
-
masterTest.populate();
|
|
426
|
-
});
|
|
427
|
-
|
|
428
|
-
test('remove a module by its id', () => {
|
|
429
|
-
masterTest.removeModule(module1IDTest);
|
|
430
|
-
|
|
431
|
-
expect(Object.keys(masterTest._getModules()).length).toBe(1);
|
|
432
|
-
expect(Object.keys(masterTest._getModules())[0]).toBe(module2IDTest);
|
|
433
|
-
});
|
|
434
|
-
|
|
435
|
-
test('remove a module by its key', () => {
|
|
436
|
-
masterTest.removeModule(module2KeyTest);
|
|
437
|
-
|
|
438
|
-
expect(Object.keys(masterTest._getModules()).length).toBe(1);
|
|
439
|
-
expect(Object.keys(masterTest._getModules())[0]).toBe(module1IDTest);
|
|
440
|
-
});
|
|
441
|
-
|
|
442
|
-
test('no removal if module is not found', () => {
|
|
443
|
-
masterTest.removeModule('unexisting-id');
|
|
444
|
-
|
|
445
|
-
expect(Object.keys(masterTest._getModules()).length).toBe(2);
|
|
446
|
-
expect(Object.keys(masterTest._getModules())[0]).toBe(module1IDTest);
|
|
447
|
-
expect(Object.keys(masterTest._getModules())[1]).toBe(module2IDTest);
|
|
448
|
-
});
|
|
449
|
-
});
|
|
450
|
-
|
|
451
|
-
describe('toString()', () => {
|
|
452
|
-
test('string output standard', () => {
|
|
453
|
-
const toStringMaster = masterTest.toString();
|
|
454
|
-
const expectedString = `Component ${KeyTest} - Type: Master - Managers: 0 - Actions: 0 - Modules: 0`;
|
|
455
|
-
|
|
456
|
-
expect(toStringMaster).toBe(expectedString);
|
|
457
|
-
});
|
|
458
|
-
|
|
459
|
-
test('string output standard with all components', () => {
|
|
460
|
-
masterTest.populate();
|
|
461
|
-
|
|
462
|
-
const toStringMaster = masterTest.toString();
|
|
463
|
-
const expectedString = `Component ${KeyTest} - Type: Master - Managers: 2 - Actions: 2 - Modules: 2`;
|
|
464
|
-
|
|
465
|
-
expect(toStringMaster).toBe(expectedString);
|
|
466
|
-
});
|
|
467
|
-
|
|
468
|
-
test('string output without actions and modules', () => {
|
|
469
|
-
masterTest = new DTMasterTest(IDTest, KeyTest, {
|
|
470
|
-
[manager1IDTest]: new DTManagerStub(),
|
|
471
|
-
[manager2IDTest]: new DTManagerStub(),
|
|
472
|
-
});
|
|
473
|
-
|
|
474
|
-
const toStringMaster = masterTest.toString();
|
|
475
|
-
const expectedString = `Component ${KeyTest} - Type: Master - Managers: 2 - Actions: 0 - Modules: 0`;
|
|
476
|
-
|
|
477
|
-
expect(toStringMaster).toBe(expectedString);
|
|
478
|
-
});
|
|
479
|
-
});
|
|
480
|
-
|
|
481
|
-
describe('toObject()', () => {
|
|
482
|
-
|
|
483
|
-
test('toObject output standard', () => {
|
|
484
|
-
const toObjectMaster = masterTest.toObject();
|
|
485
|
-
|
|
486
|
-
expect(Object.keys(toObjectMaster)).toStrictEqual(['id', 'key', 'type', 'managers', 'actions', 'modules']);
|
|
487
|
-
expect(toObjectMaster.id).toBe(IDTest);
|
|
488
|
-
expect(toObjectMaster.key).toBe(KeyTest);
|
|
489
|
-
expect(toObjectMaster.type).toBe('master');
|
|
490
|
-
expect(toObjectMaster.managers).toStrictEqual([]);
|
|
491
|
-
expect(toObjectMaster.actions).toStrictEqual([]);
|
|
492
|
-
expect(toObjectMaster.modules).toStrictEqual([]);
|
|
493
|
-
});
|
|
494
|
-
|
|
495
|
-
test('toObject output with managers', () => {
|
|
496
|
-
const manager1 = new DTManagerStub();
|
|
497
|
-
jest.spyOn(manager1, 'toObject').mockImplementation(() => manager1ToObject);
|
|
498
|
-
masterTest = new DTMasterTest(IDTest, KeyTest, {
|
|
499
|
-
[manager1IDTest]: manager1,
|
|
500
|
-
});
|
|
501
|
-
|
|
502
|
-
const toObjectMaster = masterTest.toObject();
|
|
503
|
-
|
|
504
|
-
expect(toObjectMaster.id).toBe(IDTest);
|
|
505
|
-
expect(toObjectMaster.key).toBe(KeyTest);
|
|
506
|
-
expect(toObjectMaster.type).toBe('master');
|
|
507
|
-
expect(toObjectMaster.managers).toStrictEqual([ manager1ToObject ]);
|
|
508
|
-
expect(toObjectMaster.actions).toStrictEqual([]);
|
|
509
|
-
expect(toObjectMaster.modules).toStrictEqual([]);
|
|
510
|
-
});
|
|
511
|
-
|
|
512
|
-
test('toObject output with managers, actions and modules', () => {
|
|
513
|
-
const manager1 = new DTManagerStub();
|
|
514
|
-
jest.spyOn(manager1, 'toObject').mockImplementation(() => manager1ToObject);
|
|
515
|
-
const action1 = new DTActionStub();
|
|
516
|
-
jest.spyOn(action1, 'toObject').mockImplementation(() => action1ToObject);
|
|
517
|
-
const module1 = new DTModuleStub();
|
|
518
|
-
jest.spyOn(module1, 'toObject').mockImplementation(() => module1ToObject);
|
|
519
|
-
masterTest = new DTMasterTest(IDTest, KeyTest, {
|
|
520
|
-
[manager1IDTest]: manager1,
|
|
521
|
-
}, {
|
|
522
|
-
[action1IDTest]: action1,
|
|
523
|
-
}, {
|
|
524
|
-
[module1IDTest]: module1,
|
|
525
|
-
});
|
|
526
|
-
|
|
527
|
-
const toObjectMaster = masterTest.toObject();
|
|
528
|
-
|
|
529
|
-
expect(toObjectMaster.id).toBe(IDTest);
|
|
530
|
-
expect(toObjectMaster.key).toBe(KeyTest);
|
|
531
|
-
expect(toObjectMaster.type).toBe('master');
|
|
532
|
-
expect(toObjectMaster.managers).toStrictEqual([ manager1ToObject ]);
|
|
533
|
-
expect(toObjectMaster.actions).toStrictEqual([ action1ToObject ]);
|
|
534
|
-
expect(toObjectMaster.modules).toStrictEqual([ module1ToObject ]);
|
|
535
|
-
});
|
|
536
|
-
});
|
|
537
|
-
});
|