dyo-tools 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (93) hide show
  1. package/.c8rc.json +4 -0
  2. package/.eslintignore +2 -0
  3. package/.eslintrc.json +47 -0
  4. package/LICENSE +21 -0
  5. package/Makefile +34 -0
  6. package/README.md +0 -7
  7. package/babel.config.js +1 -0
  8. package/cucumber-report.html +48 -0
  9. package/cucumber.js +9 -0
  10. package/dist/constants.d.ts +6 -0
  11. package/dist/constants.js +63 -0
  12. package/dist/constants.js.map +1 -0
  13. package/dist/core/DTBunch.d.ts +11 -15
  14. package/dist/core/DTBunch.js +27 -106
  15. package/dist/core/DTBunch.js.map +1 -1
  16. package/dist/core/DTComponent.d.ts +13 -5
  17. package/dist/core/DTComponent.js +39 -1
  18. package/dist/core/DTComponent.js.map +1 -1
  19. package/dist/core/DTComponentPhysical.d.ts +10 -0
  20. package/dist/core/DTComponentPhysical.js +16 -0
  21. package/dist/core/DTComponentPhysical.js.map +1 -0
  22. package/dist/core/DTComponentWithMeta.d.ts +2 -2
  23. package/dist/core/DTComponentWithMeta.js.map +1 -1
  24. package/dist/core/DTElement.d.ts +2 -7
  25. package/dist/core/DTElement.js +3 -12
  26. package/dist/core/DTElement.js.map +1 -1
  27. package/dist/core/DTManager.d.ts +31 -0
  28. package/dist/core/DTManager.js +180 -0
  29. package/dist/core/DTManager.js.map +1 -0
  30. package/dist/core/DTPlayer.js +1 -1
  31. package/dist/core/DTPlayer.js.map +1 -1
  32. package/dist/index.d.ts +2 -0
  33. package/dist/index.js +5 -1
  34. package/dist/index.js.map +1 -1
  35. package/dist/libs/DYOFinder.d.ts +10 -0
  36. package/dist/libs/DYOFinder.js +96 -0
  37. package/dist/libs/DYOFinder.js.map +1 -0
  38. package/dist/tsconfig.tsbuildinfo +1 -1321
  39. package/dist/types/index.d.ts +64 -24
  40. package/dist/types/index.js.map +1 -1
  41. package/docs/.nojekyll +1 -0
  42. package/docs/assets/highlight.css +29 -0
  43. package/docs/assets/main.js +58 -0
  44. package/docs/assets/search.js +1 -0
  45. package/docs/assets/style.css +1367 -0
  46. package/docs/index.html +46 -0
  47. package/e2e/0.2.0/epic1.feature +29 -0
  48. package/e2e/0.2.0/epic2.feature +22 -0
  49. package/e2e/0.2.0/epic3.feature +25 -0
  50. package/e2e/0.2.0/resources/dominion.js +195 -0
  51. package/e2e/0.2.0/resources/utils.js +27 -0
  52. package/e2e/0.2.0/support/steps.js +108 -0
  53. package/e2e/future/epic4.feature +39 -0
  54. package/e2e/future/resources/dominion.js +238 -0
  55. package/e2e/future/resources/utils.js +27 -0
  56. package/jest.config.js +6 -0
  57. package/package.json +33 -23
  58. package/src/constants.ts +85 -0
  59. package/src/core/DTBunch.ts +461 -0
  60. package/src/core/DTComponent.ts +225 -0
  61. package/src/core/DTComponentPhysical.ts +39 -0
  62. package/src/core/DTComponentWithMeta.ts +65 -0
  63. package/src/core/DTElement.ts +69 -0
  64. package/src/core/DTError.ts +78 -0
  65. package/src/core/DTManager.ts +446 -0
  66. package/src/core/DTPlayer.ts +57 -0
  67. package/src/index.ts +9 -0
  68. package/src/libs/DYOFinder.ts +175 -0
  69. package/src/types/index.ts +162 -0
  70. package/test/core/DTBunch.double.ts +253 -0
  71. package/test/core/DTBunch.spec.ts +895 -0
  72. package/test/core/DTComponent.double.ts +164 -0
  73. package/test/core/DTComponent.spec.ts +295 -0
  74. package/test/core/DTComponentPhysical.double.ts +76 -0
  75. package/test/core/DTComponentPhysical.spec.ts +64 -0
  76. package/test/core/DTComponentWithMeta.double.ts +115 -0
  77. package/test/core/DTComponentWithMeta.spec.ts +124 -0
  78. package/test/core/DTElement.double.ts +147 -0
  79. package/test/core/DTElement.spec.ts +102 -0
  80. package/test/core/DTError.double.ts +92 -0
  81. package/test/core/DTError.spec.ts +89 -0
  82. package/test/core/DTManager.double.ts +192 -0
  83. package/test/core/DTManager.spec.ts +902 -0
  84. package/test/core/DTPlayer.double.ts +64 -0
  85. package/test/core/DTPlayer.spec.ts +80 -0
  86. package/test/core/copy.spec.ts +227 -0
  87. package/test/libs/DYOFinder.double.ts +152 -0
  88. package/test/libs/DYOFinder.spec.ts +194 -0
  89. package/tsconfig.dev.json +22 -0
  90. package/tsconfig.json +21 -0
  91. package/dist/utils/filters.d.ts +0 -6
  92. package/dist/utils/filters.js +0 -39
  93. package/dist/utils/filters.js.map +0 -1
@@ -0,0 +1,115 @@
1
+ import {DTComponentWithMeta} from '../../src';
2
+ import {DTAcceptedMetaData} from "../../src/types";
3
+
4
+ /******************** STUB PROPERTIES CONSTANTS
5
+ * Fixed properties to use with double classes, avoid auto generated and easy checking on test
6
+ * *****/
7
+ // Test meta data interface
8
+ export interface IMetaDataTest extends DTAcceptedMetaData {
9
+ name: string,
10
+ queen: boolean,
11
+ kd: number[],
12
+ rank?: number,
13
+ tribes?: string[]
14
+ }
15
+
16
+ // Global properties
17
+ export const IDTest = "DTComponentWithMeta-id-1234567";
18
+ export const KeyTest = "DTComponentWithMeta-key-1234567";
19
+ export const ComponentTypeTest = 'DTComponentWithMeta-componentType-test';
20
+ export const ToObjectTest = { type: "DTComponentWithMeta-test-toObject" };
21
+ export const ToStringTest = "DTComponentWithMeta-test-toString";
22
+
23
+ // Specific components tests meta-data
24
+ export const HaileiMetaData: IMetaDataTest = {
25
+ name: 'Hailei Dorcan Kazan',
26
+ queen: true,
27
+ kd: [47, 1],
28
+ rank: 1,
29
+ tribes: ['Peuple de Salta', 'Fils de Salta', 'Peuple Kanti'],
30
+ };
31
+ export const MeldrineMetaData: IMetaDataTest = {
32
+ name: 'Meldrine Goldmane',
33
+ queen: false,
34
+ kd: [53, 0],
35
+ rank: 2,
36
+ tribes: ['Lodaniens'],
37
+ };
38
+ export const MaydenaMetaData: IMetaDataTest = {
39
+ name: "Maydena 'Intan Kazan",
40
+ queen: true,
41
+ kd: [29, 0],
42
+ tribes: ['Exil rouge', 'Désolation'],
43
+ };
44
+ export const IldressMetaData: IMetaDataTest = {
45
+ name: 'Electel Ildress',
46
+ queen: false,
47
+ kd: [19, 1],
48
+ rank: 3,
49
+ };
50
+ export const YssaliaMetaData: IMetaDataTest = {
51
+ name: 'Yssalia du Gillit',
52
+ queen: true,
53
+ kd: [23, 0],
54
+ };
55
+
56
+ // Player default value
57
+ export const PlayerMetaData: IMetaDataTest = {
58
+ name: 'Llhôonn',
59
+ queen: true,
60
+ kd: [0, 0],
61
+ }
62
+
63
+ // Bunch default value
64
+ export const BunchMetaData: IMetaDataTest = {
65
+ name: 'Elementary Pentacle',
66
+ queen: true,
67
+ kd: [117, 3],
68
+ };
69
+
70
+ /******************** STUB ABSTRACT IMPLEMENTATION
71
+ * Implementation of abstract component class for tests
72
+ * *****/
73
+ export class DTComponentWithMetaImpl extends DTComponentWithMeta<IMetaDataTest> {
74
+ protected _componentType: string = ComponentTypeTest;
75
+
76
+ copy(): DTComponentWithMeta<IMetaDataTest> {
77
+ return this;
78
+ }
79
+
80
+ toObject(): any {
81
+ return ToObjectTest;
82
+ }
83
+
84
+ toString(): string {
85
+ return ToStringTest;
86
+ }
87
+ }
88
+
89
+ /******************** HELPER TEST CLASS
90
+ * Helper test class, inherits the main component
91
+ * Providing methods to property access and other facilities, in order to avoid using class methods
92
+ * *****/
93
+ export class DTComponentWithMetaTest extends DTComponentWithMetaImpl {
94
+ th_get_meta(): Partial<IMetaDataTest> {
95
+ return this._meta;
96
+ }
97
+
98
+ th_set_meta(meta: Partial<IMetaDataTest>): void {
99
+ this._meta = meta;
100
+ }
101
+ }
102
+
103
+ /******************** HELPER METHODS
104
+ * Additional helper methods to use with testing
105
+ * *****/
106
+ // Mocked implementations for overridden methods (for children tests)
107
+ export function mockOverriddenMethods(mock: any) {
108
+ // Constructor
109
+ mock.prototype.constructor.mockImplementation(function (key?: string) {
110
+ this._id = IDTest;
111
+ this._key = key || this._id;
112
+ this._errors = [];
113
+ return this;
114
+ })
115
+ }
@@ -0,0 +1,124 @@
1
+ import {afterEach, beforeEach, describe, expect, jest, test,} from '@jest/globals';
2
+ import {
3
+ DTComponentWithMetaTest,
4
+ HaileiMetaData,
5
+ IMetaDataTest,
6
+ MeldrineMetaData,
7
+ YssaliaMetaData
8
+ } from './DTComponentWithMeta.double';
9
+ import {mockOverriddenMethods} from "./DTComponent.double";
10
+ import {DTComponent, DTComponentWithMeta} from "../../src";
11
+
12
+ /******************** MOCK DEPENDENCIES
13
+ * All Dependencies used by the component are mocked with Jest
14
+ * *****/
15
+ jest.mock('../../src/core/DTComponent');
16
+ mockOverriddenMethods(DTComponent);
17
+
18
+ /************************* TESTS SUITES *******************************/
19
+ describe('class DYOToolsComponentWithMeta', () => {
20
+ let componentWithMetaTest: DTComponentWithMetaTest;
21
+
22
+ beforeEach(() => {
23
+ componentWithMetaTest = new DTComponentWithMetaTest();
24
+ });
25
+
26
+ afterEach(() => {
27
+ jest.resetAllMocks();
28
+ });
29
+
30
+ describe('inheritance', () => {
31
+ test('check good inheritance for class', () => {
32
+ expect(DTComponentWithMeta.prototype instanceof DTComponent).toBeTruthy();
33
+ });
34
+ });
35
+
36
+ describe('getMeta()', () => {
37
+ test('return undefined if meta is empty', () => {
38
+ expect(componentWithMetaTest.getMeta('name')).toBeUndefined();
39
+ });
40
+
41
+ test('return one meta by key', () => {
42
+ componentWithMetaTest.th_set_meta(HaileiMetaData);
43
+
44
+ expect(componentWithMetaTest.getMeta('name')).toBe(HaileiMetaData.name);
45
+ });
46
+ });
47
+
48
+ describe('setMeta()', () => {
49
+ test('set a new value for a meta', () => {
50
+ componentWithMetaTest.th_set_meta(HaileiMetaData);
51
+ componentWithMetaTest.setMeta('name', MeldrineMetaData.name);
52
+
53
+ const newMeta = componentWithMetaTest.th_get_meta();
54
+ expect(newMeta.name === MeldrineMetaData.name).toBeTruthy();
55
+ expect(newMeta.rank === HaileiMetaData.rank).toBeTruthy();
56
+ expect(newMeta.queen === HaileiMetaData.queen).toBeTruthy();
57
+ expect(newMeta.kd[0] === HaileiMetaData.kd[0]).toBeTruthy();
58
+ expect(newMeta.tribes[0] === HaileiMetaData.tribes[0]).toBeTruthy();
59
+ });
60
+ });
61
+
62
+ describe('getManyMeta()', () => {
63
+ test('return empty object meta by default', () => {
64
+ const keys: Array<keyof IMetaDataTest> = ['name', 'rank', 'tribes'];
65
+
66
+ expect(componentWithMetaTest.getManyMeta()).toStrictEqual({});
67
+ expect(componentWithMetaTest.getManyMeta(keys)).toStrictEqual({});
68
+ });
69
+
70
+ test('return all meta', () => {
71
+ componentWithMetaTest.th_set_meta(HaileiMetaData);
72
+
73
+ expect(componentWithMetaTest.getManyMeta()).toStrictEqual(HaileiMetaData);
74
+ });
75
+
76
+ test('return meta by keys', () => {
77
+ componentWithMetaTest.th_set_meta(HaileiMetaData);
78
+ const keys: Array<keyof IMetaDataTest> = ['name', 'kd', 'queen'];
79
+
80
+ expect(componentWithMetaTest.getManyMeta(keys)).toStrictEqual({
81
+ name: HaileiMetaData.name,
82
+ kd: HaileiMetaData.kd,
83
+ queen: HaileiMetaData.queen,
84
+ });
85
+ });
86
+
87
+ test('return meta by keys - unexisting keys', () => {
88
+ componentWithMetaTest.th_set_meta(YssaliaMetaData);
89
+ const keys: Array<keyof IMetaDataTest> = ['name', 'rank', 'tribes'];
90
+
91
+ expect(componentWithMetaTest.getManyMeta(keys)).toStrictEqual({
92
+ name: YssaliaMetaData.name,
93
+ });
94
+ });
95
+ });
96
+
97
+ describe('setManyMeta()', () => {
98
+ test('set new values', () => {
99
+ componentWithMetaTest.th_set_meta(HaileiMetaData);
100
+ const setValues: Partial<IMetaDataTest> = {
101
+ name: MeldrineMetaData.name,
102
+ queen: MeldrineMetaData.queen,
103
+ rank: MeldrineMetaData.rank,
104
+ };
105
+
106
+ componentWithMetaTest.setManyMeta(setValues);
107
+
108
+ const newMeta = componentWithMetaTest.th_get_meta();
109
+ expect(newMeta.name === MeldrineMetaData.name).toBeTruthy();
110
+ expect(newMeta.queen === MeldrineMetaData.queen).toBeTruthy();
111
+ expect(newMeta.kd[0] === HaileiMetaData.kd[0]).toBeTruthy();
112
+ expect(newMeta.rank === MeldrineMetaData.rank).toBeTruthy();
113
+ expect(newMeta.tribes[0] === HaileiMetaData.tribes[0]).toBeTruthy();
114
+ });
115
+
116
+ test('set empty new values (keep former meta)', () => {
117
+ componentWithMetaTest.th_set_meta(HaileiMetaData);
118
+
119
+ componentWithMetaTest.setManyMeta({});
120
+
121
+ expect(componentWithMetaTest.th_get_meta()).toStrictEqual(HaileiMetaData);
122
+ });
123
+ });
124
+ });
@@ -0,0 +1,147 @@
1
+ import { DTElement } from '../../src';
2
+ import { IMetaDataTest } from './DTComponentWithMeta.double';
3
+ import { DTPlayerStub } from './DTPlayer.double';
4
+
5
+ /** ****************** STUB PROPERTIES CONSTANTS
6
+ * Fixed properties to use with double classes, avoid auto generated and easy checking on test
7
+ * **** */
8
+ // Global constants
9
+ export const IDTest = 'DTElement-id-1234567';
10
+ export const KeyTest = 'DTElement-key-1234567';
11
+
12
+ // Specific elements constants
13
+ export const HaileiIdTest = 'DTElement-id-Hailei';
14
+ export const HaileiKeyTest = 'DTElement-key-Hailei';
15
+ export const HaileiToObjectTest = { id: 'DTElement-id-Hailei', key: 'DTElement-key-Hailei', type: 'element' };
16
+ export const MeldrineIdTest = 'DTElement-id-Meldrine';
17
+ export const MeldrineKeyTest = 'DTElement-key-Meldrine';
18
+ export const MeldrineToObjectTest = { id: 'DTElement-id-Meldrine', key: 'DTElement-key-Meldrine', type: 'element' };
19
+ export const MaydenaIdTest = 'DTElement-id-Maydena';
20
+ export const MaydenaKeyTest = 'DTElement-key-Maydena';
21
+ export const MaydenaToObjectTest = { id: 'DTElement-id-Maydena', key: 'DTElement-key-Maydena', type: 'element' };
22
+ export const IldressIdTest = 'DTElement-id-Ildress';
23
+ export const IldressKeyTest = 'DTElement-key-Ildress';
24
+ export const IldressToObjectTest = { id: 'DTElement-id-Ildress', key: 'DTElement-key-Ildress', type: 'element' };
25
+ export const YssaliaIdTest = 'DTElement-id-Yssalia';
26
+ export const YssaliaKeyTest = 'DTElement-key-Yssalia';
27
+ export const YssaliaToObjectTest = { id: 'DTElement-id-Yssalia', key: 'DTElement-key-Yssalia', type: 'element' };
28
+
29
+ /** ****************** HELPER TEST CLASS
30
+ * Helper test class, inherits the main component
31
+ * Providing methods to property access and other facilities, in order to avoid using class methods
32
+ * **** */
33
+ export class DTElementTest extends DTElement<IMetaDataTest> {
34
+ th_get_id(): string {
35
+ return this._id;
36
+ }
37
+
38
+ th_set_id(id: string): void {
39
+ this._id = id;
40
+ }
41
+
42
+ th_get_key(): string {
43
+ return this._key;
44
+ }
45
+
46
+ th_set_key(key: string): void {
47
+ this._key = key;
48
+ }
49
+
50
+ th_get_componentType(): string {
51
+ return this._componentType;
52
+ }
53
+
54
+ th_get_owner(): DTPlayerStub {
55
+ return this._owner;
56
+ }
57
+
58
+ th_set_owner(owner: DTPlayerStub): void {
59
+ this._owner = owner;
60
+ }
61
+
62
+ th_set_meta(meta: IMetaDataTest): void {
63
+ this._meta = meta;
64
+ }
65
+ }
66
+ /** ****************** STUB CLASS
67
+ * Stub class, for using in other component
68
+ * **** */
69
+ export class DTElementStub extends DTElement<IMetaDataTest> {
70
+ public parentIndex: number;
71
+
72
+ constructor(index = 0) {
73
+ super();
74
+ this._id = IDTest;
75
+ this._key = KeyTest;
76
+ this.parentIndex = index;
77
+ }
78
+
79
+ getId(): string {
80
+ return IDTest;
81
+ }
82
+
83
+ getKey(): string {
84
+ return KeyTest;
85
+ }
86
+ }
87
+ export class DTElementStubExtended extends DTElementStub {
88
+ private propString: string;
89
+
90
+ private propArray: string[];
91
+
92
+ private propNumber: number;
93
+
94
+ private propBoolean: boolean;
95
+
96
+ private propObject: Record<string, unknown>;
97
+
98
+ private propMeta: Record<string, unknown>;
99
+
100
+ getPropString(): string {
101
+ return this.propString;
102
+ }
103
+
104
+ setPropString(propString: string): void {
105
+ this.propString = propString;
106
+ }
107
+
108
+ getPropArray(): string[] {
109
+ return this.propArray;
110
+ }
111
+
112
+ setPropArray(propArray: string[]): void {
113
+ this.propArray = propArray;
114
+ }
115
+
116
+ getPropNumber(): number {
117
+ return this.propNumber;
118
+ }
119
+
120
+ setPropNumber(propNumber: number): void {
121
+ this.propNumber = propNumber;
122
+ }
123
+
124
+ getPropBoolean(): boolean {
125
+ return this.propBoolean;
126
+ }
127
+
128
+ setPropBoolean(propBoolean: boolean): void {
129
+ this.propBoolean = propBoolean;
130
+ }
131
+
132
+ getPropObject(): Record<string, unknown> {
133
+ return this.propObject;
134
+ }
135
+
136
+ setPropObject(propObject: Record<string, unknown>): void {
137
+ this.propObject = propObject;
138
+ }
139
+
140
+ getPropMeta(): Record<string, unknown> {
141
+ return this.propMeta;
142
+ }
143
+
144
+ setPropMeta(propMeta: Record<string, unknown>): void {
145
+ this.propMeta = propMeta;
146
+ }
147
+ }
@@ -0,0 +1,102 @@
1
+ import {beforeEach, describe, expect, jest, test} from '@jest/globals';
2
+ import {DTPlayerStub, KeyTest as KeyPlayerTest, toStringTest as toStringPlayerTest,} from './DTPlayer.double';
3
+ import {DTElementTest, IDTest, KeyTest} from './DTElement.double';
4
+ import {MeldrineMetaData} from './DTComponentWithMeta.double';
5
+ import {DTComponentPhysical, DTElement} from "../../src";
6
+ import {mockOverriddenMethods} from "./DTComponentPhysical.double";
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
+ // Add specific mock for inherited methods to have a basic implementation
15
+ mockOverriddenMethods(DTComponentPhysical);
16
+
17
+ /************************* TESTS SUITES *******************************/
18
+ describe('class DYOToolsElement', () => {
19
+ let elementTest: DTElementTest;
20
+
21
+ beforeEach(() => {
22
+ elementTest = new DTElementTest();
23
+ });
24
+
25
+ afterEach(() => {
26
+ jest.resetAllMocks();
27
+ });
28
+
29
+ describe('inheritance', () => {
30
+ test('check good inheritance for class', () => {
31
+ expect(DTElement.prototype instanceof DTComponentPhysical).toBeTruthy();
32
+ });
33
+ });
34
+
35
+ describe('_componentType', () => {
36
+ test('componentType must be "element"', () => {
37
+ expect(elementTest.th_get_componentType()).toBe('element');
38
+ });
39
+ });
40
+
41
+ describe('copy()', () => {
42
+ // @see copy.spec.ts for unit tests about copy method
43
+ })
44
+
45
+ describe('toObject()', () => {
46
+ beforeEach(() => {
47
+ elementTest.th_set_id(IDTest);
48
+ elementTest.th_set_key(KeyTest);
49
+ })
50
+
51
+ test('toObject output standard', () => {
52
+ const toObjectElement = elementTest.toObject();
53
+
54
+ expect(Object.keys(toObjectElement)).toStrictEqual(['id', 'key', 'type']);
55
+ expect(toObjectElement.id).toBe(IDTest);
56
+ expect(toObjectElement.key).toBe(KeyTest);
57
+ expect(toObjectElement.type).toBe('element');
58
+ });
59
+
60
+ test('toObject output standard with owner', () => {
61
+ elementTest.th_set_owner(new DTPlayerStub());
62
+
63
+ const toObjectElement = elementTest.toObject();
64
+
65
+ expect(Object.keys(toObjectElement)).toStrictEqual(['id', 'key', 'type', 'owner']);
66
+ expect(toObjectElement.owner.toString()).toBe(toStringPlayerTest);
67
+ });
68
+
69
+ test('toObject output standard with owner and meta', () => {
70
+ jest.spyOn(elementTest, 'getManyMeta').mockImplementation(function () {
71
+ return this._meta;
72
+ });
73
+ elementTest.th_set_owner(new DTPlayerStub());
74
+ elementTest.th_set_meta(MeldrineMetaData);
75
+
76
+ const toObjectElement = elementTest.toObject();
77
+
78
+ expect(Object.keys(toObjectElement)).toStrictEqual(['id', 'key', 'type', 'owner', 'meta']);
79
+ expect(toObjectElement.meta).toStrictEqual(MeldrineMetaData);
80
+ });
81
+ });
82
+
83
+ describe('toString()', () => {
84
+ beforeEach(() => {
85
+ elementTest.th_set_key(KeyTest);
86
+ })
87
+
88
+ test('string output standard', () => {
89
+ const toStringElement = elementTest.toString();
90
+
91
+ expect(toStringElement).toBe(`Component ${KeyTest} - Type: Element`);
92
+ });
93
+
94
+ test('string output standard with owner', () => {
95
+ elementTest.th_set_owner(new DTPlayerStub());
96
+
97
+ const toStringElement = elementTest.toString();
98
+
99
+ expect(toStringElement).toBe(`Component ${KeyTest} - Type: Element - Owner: ${KeyPlayerTest}`);
100
+ });
101
+ });
102
+ });
@@ -0,0 +1,92 @@
1
+ import {DTError} from '../../src';
2
+ import {expect} from "@jest/globals";
3
+ import {MockedFunction} from "ts-jest";
4
+ import DYOToolsComponent from "../../src/core/DTComponent";
5
+
6
+ /******************** STUB PROPERTIES CONSTANTS
7
+ * Fixed properties to use with double classes, avoid auto generated and easy checking on test
8
+ * *****/
9
+ export const CodeTest = 'DTError-code-123456';
10
+ export const MessageTest = 'DTError-message-test';
11
+ export const TimestampTest = 1500000000000;
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 DTErrorTest extends DTError {
18
+ th_get_code(): string {
19
+ return this.code;
20
+ }
21
+
22
+ th_get_message(): string {
23
+ return this.message;
24
+ }
25
+
26
+ th_get_timestamp(): Date {
27
+ return this.timestamp;
28
+ }
29
+
30
+ th_set_timestamp(timestamp: Date): void {
31
+ this.timestamp = timestamp;
32
+ }
33
+
34
+ th_get_initiator(): DYOToolsComponent {
35
+ return this.initiator;
36
+ }
37
+
38
+ th_set_initiator(initiator: DYOToolsComponent): void {
39
+ this.initiator = initiator;
40
+ }
41
+
42
+ th_get_convicted(): DYOToolsComponent {
43
+ return this.convicted;
44
+ }
45
+
46
+ th_set_convicted(convicted: DYOToolsComponent): void {
47
+ this.convicted = convicted;
48
+ }
49
+ }
50
+
51
+ /******************** STUB CLASS
52
+ * Stub class, for using in other component
53
+ * *****/
54
+ export class DTErrorStub extends DTError {
55
+ constructor() {
56
+ super('', '');
57
+ this.code = CodeTest;
58
+ this.message = MessageTest;
59
+ this.timestamp = new Date(Math.random() * 100000000);
60
+ }
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
+ }
74
+
75
+ /******************** HELPER METHODS
76
+ * Additional helper methods to use with testing
77
+ * *****/
78
+ export const checkCallForMockedDTError = (code, message, initiatorId, convictedId?) => {
79
+ const mockedErrorConstructor = DTError.prototype.constructor as MockedFunction<(code: string, message: string, initiator?: DYOToolsComponent, convicted?: DYOToolsComponent) => DTError>;
80
+ if (!mockedErrorConstructor.mock) {
81
+ throw new Error('The DTError Constructor is not a mock');
82
+ } else {
83
+ expect(mockedErrorConstructor.mock.calls.length).toBe(1);
84
+ expect(mockedErrorConstructor.mock.calls[0][0]).toBe(code);
85
+ expect(mockedErrorConstructor.mock.calls[0][1]).toBe(message);
86
+ expect(mockedErrorConstructor.mock.calls[0][2].getId()).toBe(initiatorId);
87
+ if (convictedId) {
88
+ expect(mockedErrorConstructor.mock.calls[0][3].getId()).toBe(convictedId);
89
+ }
90
+ }
91
+ };
92
+
@@ -0,0 +1,89 @@
1
+ import {afterEach, beforeEach, describe, expect, jest, test,} from '@jest/globals';
2
+ import {CodeTest, DTErrorTest, MessageTest, TimestampTest,} from './DTError.double';
3
+ import {DTComponentStub, IDTest as ComponentIdTest} from './DTComponent.double';
4
+
5
+ /************************* TESTS SUITES *******************************/
6
+ describe('class DYOToolsError', () => {
7
+ let errorTest: DTErrorTest;
8
+
9
+ beforeEach(() => {
10
+ errorTest = new DTErrorTest(CodeTest, MessageTest);
11
+ });
12
+
13
+ afterEach(() => {
14
+ jest.resetAllMocks();
15
+ });
16
+
17
+ describe('constructor()', () => {
18
+ test('creation with standard field (code, message and timestamp)', () => {
19
+ const newError = new DTErrorTest(CodeTest, MessageTest);
20
+ const currentDate = new Date();
21
+
22
+ expect(newError.th_get_code()).toBe(CodeTest);
23
+ expect(newError.th_get_message()).toBe(MessageTest);
24
+ expect(newError.th_get_timestamp().toDateString()).toBe(currentDate.toDateString());
25
+ expect(newError.th_get_timestamp().toTimeString()).toBe(currentDate.toTimeString());
26
+ expect(newError.th_get_initiator()).toBeUndefined();
27
+ expect(newError.th_get_convicted()).toBeUndefined();
28
+ });
29
+
30
+ test('creation with initiator component', () => {
31
+ const initiatorMock = new DTComponentStub('initiator');
32
+ const newError = new DTErrorTest(CodeTest, MessageTest, initiatorMock);
33
+
34
+ expect(newError.th_get_initiator().getId()).toBe(`${ComponentIdTest}-initiator`);
35
+ });
36
+
37
+ test('creation with initiator and convicted component', () => {
38
+ const initiatorMock = new DTComponentStub('initiator');
39
+ const convictedMock = new DTComponentStub('convicted');
40
+ const newError = new DTErrorTest(CodeTest, MessageTest, initiatorMock, convictedMock);
41
+
42
+ expect(newError.th_get_convicted().getId()).toBe(`${ComponentIdTest}-convicted`);
43
+ });
44
+ });
45
+
46
+ describe('getCode()', () => {
47
+ test('return code property', () => {
48
+ expect(errorTest.getCode()).toBe(CodeTest);
49
+ });
50
+ });
51
+
52
+ describe('getMessage()', () => {
53
+ test('return message property', () => {
54
+ expect(errorTest.getMessage()).toBe(MessageTest);
55
+ });
56
+ });
57
+
58
+ describe('getTimestamp()', () => {
59
+ test('return timestamp property', () => {
60
+ errorTest.th_set_timestamp(new Date(TimestampTest));
61
+
62
+ expect(errorTest.getTimestamp().getTime()).toBe(TimestampTest);
63
+ });
64
+ });
65
+
66
+ describe('getInitiator()', () => {
67
+ test('return empty initiator component by default', () => {
68
+ expect(errorTest.getInitiator()).toBeUndefined();
69
+ });
70
+
71
+ test('return initiator component when set', () => {
72
+ errorTest.th_set_initiator(new DTComponentStub('initiator'));
73
+
74
+ expect(errorTest.getInitiator().getId()).toBe(`${ComponentIdTest}-initiator`);
75
+ });
76
+ });
77
+
78
+ describe('getConvicted()', () => {
79
+ test('return empty convicted component by default', () => {
80
+ expect(errorTest.getConvicted()).toBeUndefined();
81
+ });
82
+
83
+ test('return convicted component when set', () => {
84
+ errorTest.th_set_convicted(new DTComponentStub('convicted'));
85
+
86
+ expect(errorTest.getConvicted().getId()).toBe(`${ComponentIdTest}-convicted`);
87
+ });
88
+ });
89
+ });