zation-assured 0.6.3 → 3.0.0-dev.4

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 (151) hide show
  1. package/LICENSE +1 -1
  2. package/README.md +55 -2
  3. package/dist/index.d.ts +2 -2
  4. package/dist/index.js +3 -9
  5. package/dist/lib/api/assert.d.ts +21 -14
  6. package/dist/lib/api/assert.js +17 -13
  7. package/dist/lib/api/testHelper.d.ts +0 -8
  8. package/dist/lib/api/testHelper.js +6 -83
  9. package/dist/lib/api/when.d.ts +41 -45
  10. package/dist/lib/api/when.js +42 -55
  11. package/dist/lib/helper/asserter/abstractActionAsserter.d.ts +68 -0
  12. package/dist/lib/helper/asserter/{rootSendAsserter.js → abstractActionAsserter.js} +23 -67
  13. package/dist/lib/helper/asserter/assertStarter.d.ts +5 -0
  14. package/dist/lib/helper/asserter/assertStarter.js +16 -0
  15. package/dist/lib/helper/asserter/channel/abstractChannelAsserter.d.ts +20 -29
  16. package/dist/lib/helper/asserter/channel/abstractChannelAsserter.js +44 -85
  17. package/dist/lib/helper/asserter/channel/channelAsserter.d.ts +3 -3
  18. package/dist/lib/helper/asserter/channel/channelAsserter.js +2 -2
  19. package/dist/lib/helper/asserter/channel/standaloneChannelAsserter.d.ts +6 -6
  20. package/dist/lib/helper/asserter/channel/standaloneChannelAsserter.js +7 -7
  21. package/dist/lib/helper/asserter/client/abstractClientAsserter.d.ts +20 -38
  22. package/dist/lib/helper/asserter/client/abstractClientAsserter.js +82 -184
  23. package/dist/lib/helper/asserter/client/clientAsserter.d.ts +3 -3
  24. package/dist/lib/helper/asserter/client/clientAsserter.js +2 -2
  25. package/dist/lib/helper/asserter/client/standaloneClientAsserter.d.ts +6 -6
  26. package/dist/lib/helper/asserter/client/standaloneClientAsserter.js +7 -7
  27. package/dist/lib/helper/asserter/controller/integratedResponseAsserter.d.ts +52 -0
  28. package/dist/lib/helper/asserter/controller/integratedResponseAsserter.js +122 -0
  29. package/dist/lib/helper/asserter/controller/standaloneResponseAsserter.d.ts +54 -0
  30. package/dist/lib/helper/asserter/controller/standaloneResponseAsserter.js +118 -0
  31. package/dist/lib/helper/asserter/databox/abstractDataboxAsserter.d.ts +29 -36
  32. package/dist/lib/helper/asserter/databox/abstractDataboxAsserter.js +44 -80
  33. package/dist/lib/helper/asserter/databox/databoxAsserter.d.ts +3 -3
  34. package/dist/lib/helper/asserter/databox/databoxAsserter.js +2 -2
  35. package/dist/lib/helper/asserter/databox/standaloneDataboxAsserter.d.ts +7 -6
  36. package/dist/lib/helper/asserter/databox/standaloneDataboxAsserter.js +7 -7
  37. package/dist/lib/helper/asserter/event/abstractEventAsserter.d.ts +12 -4
  38. package/dist/lib/helper/asserter/event/abstractEventAsserter.js +25 -10
  39. package/dist/lib/helper/asserter/event/codeMetadataEventAsserter.d.ts +21 -0
  40. package/dist/lib/helper/asserter/event/codeMetadataEventAsserter.js +47 -0
  41. package/dist/lib/helper/asserter/event/dataEventAsserter.d.ts +13 -3
  42. package/dist/lib/helper/asserter/event/dataEventAsserter.js +22 -4
  43. package/dist/lib/helper/asserter/receiver/integratedTransmitAsserter.d.ts +9 -0
  44. package/dist/lib/helper/asserter/receiver/{transmitAsserter.js → integratedTransmitAsserter.js} +9 -9
  45. package/dist/lib/helper/asserter/value/abstractValueAsserter.d.ts +13 -15
  46. package/dist/lib/helper/asserter/value/abstractValueAsserter.js +49 -53
  47. package/dist/lib/helper/asserter/value/standaloneValueAsserter.d.ts +3 -3
  48. package/dist/lib/helper/asserter/value/standaloneValueAsserter.js +6 -6
  49. package/dist/lib/helper/asserter/value/valueAsserter.d.ts +4 -4
  50. package/dist/lib/helper/asserter/value/valueAsserter.js +4 -4
  51. package/dist/lib/helper/backError/backErrorsFilterBuilder.d.ts +12 -0
  52. package/dist/lib/helper/backError/backErrorsFilterBuilder.js +29 -0
  53. package/dist/lib/helper/console/logger.js +2 -2
  54. package/dist/lib/helper/definitions/optionTypes.d.ts +8 -0
  55. package/dist/lib/helper/definitions/optionTypes.js +7 -0
  56. package/dist/lib/helper/test/test.d.ts +2 -2
  57. package/dist/lib/helper/test/test.js +8 -6
  58. package/dist/lib/helper/timeout/timeoutAssert.js +2 -2
  59. package/dist/lib/helper/utils/actionUtils.d.ts +5 -18
  60. package/dist/lib/helper/utils/actionUtils.js +14 -43
  61. package/dist/lib/helper/utils/types.d.ts +20 -0
  62. package/dist/lib/helper/utils/types.js +7 -0
  63. package/package.json +9 -12
  64. package/dist/lib/api/before.d.ts +0 -3
  65. package/dist/lib/api/before.js +0 -20
  66. package/dist/lib/api/client.d.ts +0 -3
  67. package/dist/lib/api/client.js +0 -11
  68. package/dist/lib/api/describe.d.ts +0 -1
  69. package/dist/lib/api/describe.js +0 -6
  70. package/dist/lib/api/instanceManager.d.ts +0 -8
  71. package/dist/lib/api/instanceManager.js +0 -48
  72. package/dist/lib/api/testArea.d.ts +0 -3
  73. package/dist/lib/api/testArea.js +0 -41
  74. package/dist/lib/api/testServerManager.d.ts +0 -19
  75. package/dist/lib/api/testServerManager.js +0 -100
  76. package/dist/lib/helper/asserter/abstractClientAsserter.d.ts +0 -102
  77. package/dist/lib/helper/asserter/abstractClientAsserter.js +0 -293
  78. package/dist/lib/helper/asserter/anyAsserter.d.ts +0 -62
  79. package/dist/lib/helper/asserter/anyAsserter.js +0 -130
  80. package/dist/lib/helper/asserter/channelEventAsserter.d.ts +0 -34
  81. package/dist/lib/helper/asserter/channelEventAsserter.js +0 -84
  82. package/dist/lib/helper/asserter/channelPubAsserter.d.ts +0 -53
  83. package/dist/lib/helper/asserter/channelPubAsserter.js +0 -126
  84. package/dist/lib/helper/asserter/clientAsserter.d.ts +0 -13
  85. package/dist/lib/helper/asserter/clientAsserter.js +0 -26
  86. package/dist/lib/helper/asserter/controller/responseAsserter.d.ts +0 -74
  87. package/dist/lib/helper/asserter/controller/responseAsserter.js +0 -138
  88. package/dist/lib/helper/asserter/dataEventAsserter.d.ts +0 -40
  89. package/dist/lib/helper/asserter/dataEventAsserter.js +0 -113
  90. package/dist/lib/helper/asserter/event/abstractDataEventAsserter.d.ts +0 -13
  91. package/dist/lib/helper/asserter/event/abstractDataEventAsserter.js +0 -36
  92. package/dist/lib/helper/asserter/event/codeDataEventAsserter.d.ts +0 -14
  93. package/dist/lib/helper/asserter/event/codeDataEventAsserter.js +0 -40
  94. package/dist/lib/helper/asserter/eventAsserter.d.ts +0 -41
  95. package/dist/lib/helper/asserter/eventAsserter.js +0 -115
  96. package/dist/lib/helper/asserter/objectAsserter.d.ts +0 -55
  97. package/dist/lib/helper/asserter/objectAsserter.js +0 -113
  98. package/dist/lib/helper/asserter/receiver/transmitAsserter.d.ts +0 -9
  99. package/dist/lib/helper/asserter/responseAsserter.d.ts +0 -129
  100. package/dist/lib/helper/asserter/responseAsserter.js +0 -260
  101. package/dist/lib/helper/asserter/rootSendAsserter.d.ts +0 -89
  102. package/dist/lib/helper/asserter/standaloneClientAsserter.d.ts +0 -11
  103. package/dist/lib/helper/asserter/standaloneClientAsserter.js +0 -38
  104. package/dist/lib/helper/assured/clientAssured.d.ts +0 -2
  105. package/dist/lib/helper/assured/clientAssured.js +0 -11
  106. package/dist/lib/helper/assured/responseAssured.d.ts +0 -17
  107. package/dist/lib/helper/assured/responseAssured.js +0 -72
  108. package/dist/lib/helper/backError/backErrorFilterBuilder.d.ts +0 -13
  109. package/dist/lib/helper/backError/backErrorFilterBuilder.js +0 -32
  110. package/dist/lib/helper/builder/controller/abstractRequestBuilder.d.ts +0 -53
  111. package/dist/lib/helper/builder/controller/abstractRequestBuilder.js +0 -69
  112. package/dist/lib/helper/builder/controller/authRequestBuilder.d.ts +0 -15
  113. package/dist/lib/helper/builder/controller/authRequestBuilder.js +0 -30
  114. package/dist/lib/helper/builder/controller/standardRequestBuilder.d.ts +0 -15
  115. package/dist/lib/helper/builder/controller/standardRequestBuilder.js +0 -30
  116. package/dist/lib/helper/builder/controller/validationCheckRequestBuilder.d.ts +0 -21
  117. package/dist/lib/helper/builder/controller/validationCheckRequestBuilder.js +0 -40
  118. package/dist/lib/helper/builder/receiver/packageBuilder.d.ts +0 -45
  119. package/dist/lib/helper/builder/receiver/packageBuilder.js +0 -67
  120. package/dist/lib/helper/controller/request/abstractRequestBuilder.d.ts +0 -53
  121. package/dist/lib/helper/controller/request/abstractRequestBuilder.js +0 -68
  122. package/dist/lib/helper/controller/request/authRequestBuilder.d.ts +0 -15
  123. package/dist/lib/helper/controller/request/authRequestBuilder.js +0 -29
  124. package/dist/lib/helper/controller/request/standardRequestBuilder.d.ts +0 -15
  125. package/dist/lib/helper/controller/request/standardRequestBuilder.js +0 -29
  126. package/dist/lib/helper/controller/request/validationCheckRequestBuilder.d.ts +0 -21
  127. package/dist/lib/helper/controller/request/validationCheckRequestBuilder.js +0 -39
  128. package/dist/lib/helper/data/test.d.ts +0 -13
  129. package/dist/lib/helper/data/test.js +0 -89
  130. package/dist/lib/helper/do/actionUtils.d.ts +0 -24
  131. package/dist/lib/helper/do/actionUtils.js +0 -70
  132. package/dist/lib/helper/do/doUtils.d.ts +0 -24
  133. package/dist/lib/helper/do/doUtils.js +0 -80
  134. package/dist/lib/helper/error/backErrorFilterBuilder.d.ts +0 -13
  135. package/dist/lib/helper/error/backErrorFilterBuilder.js +0 -34
  136. package/dist/lib/helper/error/taskErrorFilterBuilder.d.ts +0 -13
  137. package/dist/lib/helper/error/taskErrorFilterBuilder.js +0 -34
  138. package/dist/lib/helper/request/abstractRequestBuilder.d.ts +0 -53
  139. package/dist/lib/helper/request/abstractRequestBuilder.js +0 -68
  140. package/dist/lib/helper/request/authRequestBuilder.d.ts +0 -15
  141. package/dist/lib/helper/request/authRequestBuilder.js +0 -29
  142. package/dist/lib/helper/request/requestBuilder.d.ts +0 -46
  143. package/dist/lib/helper/request/requestBuilder.js +0 -76
  144. package/dist/lib/helper/request/standardRequestBuilder.d.ts +0 -15
  145. package/dist/lib/helper/request/standardRequestBuilder.js +0 -29
  146. package/dist/lib/helper/request/validationCheckRequestBuilder.d.ts +0 -21
  147. package/dist/lib/helper/request/validationCheckRequestBuilder.js +0 -39
  148. package/dist/lib/helper/request/validationRequestBuilder.d.ts +0 -35
  149. package/dist/lib/helper/request/validationRequestBuilder.js +0 -61
  150. package/dist/lib/helper/utils/clientUtils.d.ts +0 -4
  151. package/dist/lib/helper/utils/clientUtils.js +0 -29
@@ -0,0 +1,122 @@
1
+ "use strict";
2
+ /*
3
+ Author: Ing. Luca Gian Scaringella
4
+ GitHub: LucaCode
5
+ Copyright(c) Ing. Luca Gian Scaringella
6
+ */
7
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14
+ });
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ exports.IntegratedResponseAsserter = void 0;
18
+ const zation_client_1 = require("zation-client");
19
+ const valueAsserter_1 = require("../value/valueAsserter");
20
+ const backErrorsFilterBuilder_1 = require("../../backError/backErrorsFilterBuilder");
21
+ const abstractActionAsserter_1 = require("../abstractActionAsserter");
22
+ const assert = require('assert');
23
+ class IntegratedResponseAsserter extends abstractActionAsserter_1.AbstractActionAsserter {
24
+ constructor(sendRequest, test, client) {
25
+ super(test, client);
26
+ this.sendRequest = sendRequest;
27
+ this.responseAsserters = [];
28
+ }
29
+ _executeAction() {
30
+ return __awaiter(this, void 0, void 0, function* () {
31
+ let resp;
32
+ try {
33
+ resp = yield this.sendRequest();
34
+ }
35
+ catch (err) {
36
+ if (err instanceof zation_client_1.Response)
37
+ resp = err;
38
+ else
39
+ throw err;
40
+ }
41
+ for (let i = 0; i < this.responseAsserters.length; i++)
42
+ yield this.responseAsserters[i](resp);
43
+ });
44
+ }
45
+ // noinspection JSMethodCanBeStatic
46
+ _respInfo(res) {
47
+ return '\n ' + res.toString();
48
+ }
49
+ // noinspection JSUnusedGlobalSymbols
50
+ /**
51
+ * @description
52
+ * Asserts that the response is successful.
53
+ */
54
+ isSuccessful() {
55
+ this.responseAsserters.push(resp => {
56
+ assert(resp.successful, 'Response should be successful.' + this._respInfo(resp));
57
+ });
58
+ return this;
59
+ }
60
+ // noinspection JSUnusedGlobalSymbols
61
+ /**
62
+ * @description
63
+ * Asserts that the response is not successful.
64
+ */
65
+ isNotSuccessful() {
66
+ this.responseAsserters.push(resp => {
67
+ assert(!resp.successful, 'Response should be not successful.' + this._respInfo(resp));
68
+ });
69
+ return this;
70
+ }
71
+ // noinspection JSUnusedGlobalSymbols
72
+ /**
73
+ * @description
74
+ * Asserts that the response has a result.
75
+ */
76
+ hasResult() {
77
+ this.responseAsserters.push(resp => {
78
+ assert(resp.result != null, `Response should have a result.`
79
+ + this._respInfo(resp));
80
+ });
81
+ return this;
82
+ }
83
+ // noinspection JSUnusedGlobalSymbols
84
+ /**
85
+ * @description
86
+ * Asserts the result of the response.
87
+ */
88
+ result() {
89
+ return new valueAsserter_1.ValueAsserter(this, (test) => {
90
+ this.responseAsserters.push(resp => {
91
+ test(resp.result, 'response data');
92
+ });
93
+ });
94
+ }
95
+ hasError(filter) {
96
+ if (filter !== undefined) {
97
+ this.responseAsserters.push((resp) => {
98
+ assert(resp.filter(filter).length > 0, `Response should have at least one back error that matches the filter: ${JSON.stringify(filter)}.`
99
+ + this._respInfo(resp));
100
+ });
101
+ return this;
102
+ }
103
+ else
104
+ return new backErrorsFilterBuilder_1.BackErrorsFilterBuilder(this, (filter) => {
105
+ this.hasError(filter);
106
+ });
107
+ }
108
+ // noinspection JSUnusedGlobalSymbols
109
+ /**
110
+ * @description
111
+ * Creates a custom assertion.
112
+ * @param assert
113
+ */
114
+ assert(assert) {
115
+ this.responseAsserters.push(resp => assert(resp));
116
+ return this;
117
+ }
118
+ self() {
119
+ return this;
120
+ }
121
+ }
122
+ exports.IntegratedResponseAsserter = IntegratedResponseAsserter;
@@ -0,0 +1,54 @@
1
+ import { BackErrorFilter, Response } from "zation-client";
2
+ import { ValueAsserter } from "../value/valueAsserter";
3
+ import { BackErrorsFilterBuilder } from "../../backError/backErrorsFilterBuilder";
4
+ import { ResponseData } from "../../utils/types";
5
+ export default class StandaloneResponseAsserter<R extends Response<any>> {
6
+ private readonly _test;
7
+ private readonly responses;
8
+ constructor(response: R | R[], description?: string);
9
+ protected _forEachResponse(func: (response: R, i: number) => Promise<void> | void): Promise<void>;
10
+ private _respInfo;
11
+ /**
12
+ * @description
13
+ * Asserts that the response is successful.
14
+ */
15
+ isSuccessful(): StandaloneResponseAsserter<R>;
16
+ /**
17
+ * @description
18
+ * Asserts that the response is not successful.
19
+ */
20
+ isNotSuccessful(): StandaloneResponseAsserter<R>;
21
+ /**
22
+ * @description
23
+ * Asserts that the response has a result.
24
+ */
25
+ hasResult(): StandaloneResponseAsserter<R>;
26
+ /**
27
+ * @description
28
+ * Asserts the result of the response.
29
+ */
30
+ result(): ValueAsserter<ResponseData<R>, StandaloneResponseAsserter<R>>;
31
+ /**
32
+ * @description
33
+ * Asserts that the response has specific errors with a BackErrorFilterBuilder.
34
+ */
35
+ hasError(): BackErrorsFilterBuilder<StandaloneResponseAsserter<R>>;
36
+ /**
37
+ * @description
38
+ * Asserts that the response has specific errors with a raw filter.
39
+ * @param filter
40
+ * Queric filter to filter for specific errors.
41
+ */
42
+ hasError(filter: BackErrorFilter): StandaloneResponseAsserter<R>;
43
+ /**
44
+ * @description
45
+ * Creates a custom assertion.
46
+ * @param assert
47
+ */
48
+ assert(assert: (resp: R) => void | Promise<void>): StandaloneResponseAsserter<R>;
49
+ /**
50
+ * @description
51
+ * Runs the test.
52
+ */
53
+ test(): Promise<void>;
54
+ }
@@ -0,0 +1,118 @@
1
+ "use strict";
2
+ /*
3
+ Author: Ing. Luca Gian Scaringella
4
+ GitHub: LucaCode
5
+ Copyright(c) Ing. Luca Gian Scaringella
6
+ */
7
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
9
+ return new (P || (P = Promise))(function (resolve, reject) {
10
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
11
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
12
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
13
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
14
+ });
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ const test_1 = require("../../test/test");
18
+ const valueAsserter_1 = require("../value/valueAsserter");
19
+ const backErrorsFilterBuilder_1 = require("../../backError/backErrorsFilterBuilder");
20
+ const assert = require('assert');
21
+ class StandaloneResponseAsserter {
22
+ constructor(response, description) {
23
+ this._test = new test_1.Test(description);
24
+ this.responses = Array.isArray(response) ? response : [response];
25
+ }
26
+ _forEachResponse(func) {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ yield Promise.all(this.responses
29
+ .map((resp, i) => func(resp, i)));
30
+ });
31
+ }
32
+ // noinspection JSMethodCanBeStatic
33
+ _respInfo(res) {
34
+ return '\n ' + res.toString();
35
+ }
36
+ // noinspection JSUnusedGlobalSymbols
37
+ /**
38
+ * @description
39
+ * Asserts that the response is successful.
40
+ */
41
+ isSuccessful() {
42
+ this._test.test(() => this._forEachResponse((resp, i) => __awaiter(this, void 0, void 0, function* () {
43
+ assert(resp.successful, `Response: ${i} should be successful.` + this._respInfo(resp));
44
+ })));
45
+ return this;
46
+ }
47
+ // noinspection JSUnusedGlobalSymbols
48
+ /**
49
+ * @description
50
+ * Asserts that the response is not successful.
51
+ */
52
+ isNotSuccessful() {
53
+ this._test.test(() => this._forEachResponse((resp, i) => __awaiter(this, void 0, void 0, function* () {
54
+ assert(!resp.successful, `Response: ${i} should be not successful.` + this._respInfo(resp));
55
+ })));
56
+ return this;
57
+ }
58
+ // noinspection JSUnusedGlobalSymbols
59
+ /**
60
+ * @description
61
+ * Asserts that the response has a result.
62
+ */
63
+ hasResult() {
64
+ this._test.test(() => this._forEachResponse((resp, i) => __awaiter(this, void 0, void 0, function* () {
65
+ assert(resp.result != null, `Response: ${i} should have a result.`
66
+ + this._respInfo(resp));
67
+ })));
68
+ return this;
69
+ }
70
+ // noinspection JSUnusedGlobalSymbols
71
+ /**
72
+ * @description
73
+ * Asserts the result of the response.
74
+ */
75
+ result() {
76
+ return new valueAsserter_1.ValueAsserter(this, (test) => {
77
+ this._test.test(() => this._forEachResponse((resp, i) => __awaiter(this, void 0, void 0, function* () {
78
+ test(resp.result, `response: ${i} result`);
79
+ })));
80
+ });
81
+ }
82
+ hasError(filter) {
83
+ if (filter !== undefined) {
84
+ this._test.test(() => this._forEachResponse((resp, i) => __awaiter(this, void 0, void 0, function* () {
85
+ assert(resp.filter(filter).length > 0, `Response: ${i} should have at least one back error that matches the filter: ${JSON.stringify(filter)}.`
86
+ + this._respInfo(resp));
87
+ })));
88
+ return this;
89
+ }
90
+ else
91
+ return new backErrorsFilterBuilder_1.BackErrorsFilterBuilder(this, (filter) => {
92
+ this.hasError(filter);
93
+ });
94
+ }
95
+ // noinspection JSUnusedGlobalSymbols
96
+ /**
97
+ * @description
98
+ * Creates a custom assertion.
99
+ * @param assert
100
+ */
101
+ assert(assert) {
102
+ this._test.test(() => this._forEachResponse((resp) => __awaiter(this, void 0, void 0, function* () {
103
+ yield assert(resp);
104
+ })));
105
+ return this;
106
+ }
107
+ // noinspection JSUnusedGlobalSymbols
108
+ /**
109
+ * @description
110
+ * Runs the test.
111
+ */
112
+ test() {
113
+ return __awaiter(this, void 0, void 0, function* () {
114
+ return this._test.execute();
115
+ });
116
+ }
117
+ }
118
+ exports.default = StandaloneResponseAsserter;
@@ -1,79 +1,72 @@
1
1
  import { Test } from "../../test/test";
2
- import { Databox, DataEventReason } from 'zation-client';
2
+ import { Databox, DataEventReason, DbStorage } from 'zation-client';
3
3
  import { DataEventAsserter } from "../event/dataEventAsserter";
4
4
  import { ValueAsserter } from "../value/valueAsserter";
5
- import { CodeDataEventAsserter } from "../event/codeDataEventAsserter";
6
- export declare abstract class AbstractDataboxAsserter<T> {
5
+ import { CodeMetadataEventAsserter } from "../event/codeMetadataEventAsserter";
6
+ import { Query } from "queric";
7
+ import { DataboxData, DataboxFetchData, DataboxMember } from "../../utils/types";
8
+ import { DeepReadonly } from "../../utils/types";
9
+ export declare abstract class AbstractDataboxAsserter<T, D extends Databox<any, any, any, any>> {
7
10
  protected _test: Test;
8
- protected databoxes: Databox[];
11
+ protected databoxes: D[];
9
12
  protected abstract self(): T;
10
- protected constructor(databoxes: Databox[], test: Test);
11
- protected _forEachDatabox(func: (databox: Databox, i: number) => Promise<void>): Promise<void>;
13
+ protected constructor(databoxes: D[], test: Test);
14
+ protected _forEachDatabox(func: (databox: D, i: number) => Promise<void> | void): Promise<void>;
12
15
  /**
13
16
  * @description
14
17
  * Asserts that the databox is connected.
15
18
  * @param timeout
16
- * With this parameter, you can set a time limit in that the assertion must be successful.
19
+ * Sets a time limit in that the assertion must be successful.
17
20
  */
18
21
  isConnected(timeout?: number): T;
19
22
  /**
20
23
  * @description
21
24
  * Asserts that the databox is disconnected.
22
25
  * @param timeout
23
- * With this parameter, you can set a time limit in that the assertion must be successful.
26
+ * Sets a time limit in that the assertion must be successful.
24
27
  */
25
28
  isDisconnected(timeout?: number): T;
26
29
  /**
27
30
  * Asserts the current data of the databox.
28
31
  */
29
- data(): ValueAsserter<T>;
32
+ data(): ValueAsserter<DeepReadonly<DataboxData<D>>, T>;
30
33
  /**
31
34
  * Asserts the current member of the databox.
32
35
  */
33
- member(): ValueAsserter<T>;
36
+ member(): ValueAsserter<DataboxMember<D>, T>;
34
37
  /**
35
38
  * Fetches data multiple times on each databox.
36
39
  */
37
- fetch(times?: number, fetchData?: any): T;
40
+ fetch(times?: number, fetchData?: DataboxFetchData<D>): T;
38
41
  /**
39
42
  * @description
40
- * This function lets you do extra actions on each databox and asserts that no error is thrown.
41
- * When an error throws, it lets the test fail with the provided message or the concrete error.
43
+ * Runs a extra test action and asserts that no error will be thrown.
44
+ * AssertionErrors will be rethrown, and all other errors will fail
45
+ * the test with the provided message or the concrete error.
42
46
  * @param action
43
- * @param message if not provided it throws the specific error.
47
+ * @param failMsg If not provided, the concrete error is used.
44
48
  */
45
- action(action: (databox: Databox, index: number) => void | Promise<void>, message?: string): T;
49
+ action(action: (databox: D, index: number) => void | Promise<void>, failMsg?: string): T;
46
50
  /**
47
51
  * @description
48
- * This function lets you do extra actions on each databox and
49
- * asserts that an error or an error instance of a specific class is thrown.
50
- * When no error is thrown, or the error does not match with the given classes
51
- * (only if at least one class is given), it lets the test fail with the provided message.
52
- * @param action
53
- * @param message
54
- * @param validErrorClasses
55
- */
56
- actionShouldThrow(action: (databox: Databox, index: number) => void | Promise<void>, message: string, ...validErrorClasses: any[]): T;
57
- /**
58
- * @description
59
- * Asserts that the databox should trigger an DataChange event.
60
- * It is also possible to assert only in case of specific data event reasons.
52
+ * Asserts that the databox should trigger an data change event.
53
+ * It is also possible to filter for specific data event reasons with a queric query.
61
54
  */
62
- dataChangeTriggers(...reasons: DataEventReason[]): DataEventAsserter<T>;
55
+ dataChangeTriggers(reasonFilter?: Query<DataEventReason>): DataEventAsserter<T, [DeepReadonly<DataboxData<D>>, DataEventReason, DbStorage<DataboxData<D>>], 0>;
63
56
  /**
64
57
  * @description
65
- * Asserts that the databox should trigger an DataTouch event.
66
- * It is also possible to assert only in case of specific data event reasons.
58
+ * Asserts that the databox should trigger an data touch event.
59
+ * It is also possible to filter for specific data event reasons with a queric query.
67
60
  */
68
- dataTouchTriggers(...reasons: DataEventReason[]): DataEventAsserter<T>;
61
+ dataTouchTriggers(reasonFilter?: Query<DataEventReason>): DataEventAsserter<T, [DeepReadonly<DataboxData<D>>, DataEventReason, DbStorage<DataboxData<D>>], 0>;
69
62
  /**
70
63
  * @description
71
- * Asserts that the databox should trigger an Close event.
64
+ * Asserts that the databox should trigger an close event.
72
65
  */
73
- closeTriggers(): CodeDataEventAsserter<T>;
66
+ closeTriggers(): CodeMetadataEventAsserter<T, [number | string | undefined, any], 0, 1>;
74
67
  /**
75
68
  * @description
76
- * Asserts that the databox should trigger an KickOut event.
69
+ * Asserts that the databox should trigger an kick out event.
77
70
  */
78
- kickOutTriggers(): CodeDataEventAsserter<T>;
71
+ kickOutTriggers(): CodeMetadataEventAsserter<T, [number | string | undefined, any], 0, 1>;
79
72
  }
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  /*
3
- Author: Luca Scaringella
3
+ Author: Ing. Luca Gian Scaringella
4
4
  GitHub: LucaCode
5
- ©Copyright by Luca Scaringella
5
+ Copyright(c) Ing. Luca Gian Scaringella
6
6
  */
7
7
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
8
8
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
@@ -19,8 +19,9 @@ const timeoutAssert_1 = require("../../timeout/timeoutAssert");
19
19
  const actionUtils_1 = require("../../utils/actionUtils");
20
20
  const dataEventAsserter_1 = require("../event/dataEventAsserter");
21
21
  const valueAsserter_1 = require("../value/valueAsserter");
22
- const codeDataEventAsserter_1 = require("../event/codeDataEventAsserter");
22
+ const codeMetadataEventAsserter_1 = require("../event/codeMetadataEventAsserter");
23
23
  const chai_1 = require("chai");
24
+ const queric_1 = require("queric");
24
25
  class AbstractDataboxAsserter {
25
26
  constructor(databoxes, test) {
26
27
  this._test = test;
@@ -28,11 +29,7 @@ class AbstractDataboxAsserter {
28
29
  }
29
30
  _forEachDatabox(func) {
30
31
  return __awaiter(this, void 0, void 0, function* () {
31
- let promises = [];
32
- this.databoxes.forEach((c, i) => {
33
- promises.push(func(c, i));
34
- });
35
- yield Promise.all(promises);
32
+ yield Promise.all(this.databoxes.map((db, i) => func(db, i)));
36
33
  });
37
34
  }
38
35
  // noinspection JSUnusedGlobalSymbols
@@ -40,11 +37,11 @@ class AbstractDataboxAsserter {
40
37
  * @description
41
38
  * Asserts that the databox is connected.
42
39
  * @param timeout
43
- * With this parameter, you can set a time limit in that the assertion must be successful.
40
+ * Sets a time limit in that the assertion must be successful.
44
41
  */
45
42
  isConnected(timeout = 0) {
46
43
  this._test.test(() => __awaiter(this, void 0, void 0, function* () {
47
- yield this._forEachDatabox((d, i) => __awaiter(this, void 0, void 0, function* () {
44
+ return this._forEachDatabox((d, i) => __awaiter(this, void 0, void 0, function* () {
48
45
  if (d.isConnected())
49
46
  return;
50
47
  const toa = new timeoutAssert_1.TimeoutAssert(`Databox: ${i} should be connected.`, timeout);
@@ -61,11 +58,11 @@ class AbstractDataboxAsserter {
61
58
  * @description
62
59
  * Asserts that the databox is disconnected.
63
60
  * @param timeout
64
- * With this parameter, you can set a time limit in that the assertion must be successful.
61
+ * Sets a time limit in that the assertion must be successful.
65
62
  */
66
63
  isDisconnected(timeout = 0) {
67
64
  this._test.test(() => __awaiter(this, void 0, void 0, function* () {
68
- yield this._forEachDatabox((d, i) => __awaiter(this, void 0, void 0, function* () {
65
+ return this._forEachDatabox((d, i) => __awaiter(this, void 0, void 0, function* () {
69
66
  if (!d.isConnected())
70
67
  return;
71
68
  const toa = new timeoutAssert_1.TimeoutAssert(`Databox: ${i} should be disconnected.`, timeout);
@@ -82,12 +79,8 @@ class AbstractDataboxAsserter {
82
79
  * Asserts the current data of the databox.
83
80
  */
84
81
  data() {
85
- return new valueAsserter_1.ValueAsserter(this.self(), 'Databox', (test) => {
86
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
87
- yield this._forEachDatabox((d, i) => __awaiter(this, void 0, void 0, function* () {
88
- test(d.data, ` ${i} data:`);
89
- }));
90
- }));
82
+ return new valueAsserter_1.ValueAsserter(this.self(), (test) => {
83
+ this._test.test(() => this._forEachDatabox((d, i) => test(d.data, `Databox: ${i} data:`)));
91
84
  });
92
85
  }
93
86
  // noinspection JSUnusedGlobalSymbols
@@ -95,12 +88,8 @@ class AbstractDataboxAsserter {
95
88
  * Asserts the current member of the databox.
96
89
  */
97
90
  member() {
98
- return new valueAsserter_1.ValueAsserter(this.self(), 'Databox', (test) => {
99
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
100
- yield this._forEachDatabox((d, i) => __awaiter(this, void 0, void 0, function* () {
101
- test(d.member, ` ${i} member:`);
102
- }));
103
- }));
91
+ return new valueAsserter_1.ValueAsserter(this.self(), (test) => {
92
+ this._test.test(() => this._forEachDatabox((d, i) => test(d.member, `Databox: ${i} member:`)));
104
93
  });
105
94
  }
106
95
  // noinspection JSUnusedGlobalSymbols
@@ -117,7 +106,7 @@ class AbstractDataboxAsserter {
117
106
  yield databox.fetch(fetchData);
118
107
  }
119
108
  catch (err) {
120
- chai_1.assert.fail(`Databox ${number} fetch ${i} failed. Error -> ` + err.stack);
109
+ chai_1.assert.fail(`Databox: ${number} fetch ${i} failed. Error -> ` + err);
121
110
  }
122
111
  }))());
123
112
  }
@@ -130,101 +119,76 @@ class AbstractDataboxAsserter {
130
119
  // noinspection JSUnusedGlobalSymbols
131
120
  /**
132
121
  * @description
133
- * This function lets you do extra actions on each databox and asserts that no error is thrown.
134
- * When an error throws, it lets the test fail with the provided message or the concrete error.
135
- * @param action
136
- * @param message if not provided it throws the specific error.
137
- */
138
- action(action, message) {
139
- this.databoxes.forEach((databox, index) => {
140
- actionUtils_1.default.action(this._test, () => action(databox, index), message);
141
- });
142
- this._test.pushSyncWait();
143
- return this.self();
144
- }
145
- // noinspection JSUnusedGlobalSymbols
146
- /**
147
- * @description
148
- * This function lets you do extra actions on each databox and
149
- * asserts that an error or an error instance of a specific class is thrown.
150
- * When no error is thrown, or the error does not match with the given classes
151
- * (only if at least one class is given), it lets the test fail with the provided message.
122
+ * Runs a extra test action and asserts that no error will be thrown.
123
+ * AssertionErrors will be rethrown, and all other errors will fail
124
+ * the test with the provided message or the concrete error.
152
125
  * @param action
153
- * @param message
154
- * @param validErrorClasses
126
+ * @param failMsg If not provided, the concrete error is used.
155
127
  */
156
- actionShouldThrow(action, message, ...validErrorClasses) {
157
- this.databoxes.forEach((databox, index) => {
158
- actionUtils_1.default.actionShouldThrow(this._test, () => action(databox, index), message, ...validErrorClasses);
159
- });
128
+ action(action, failMsg) {
129
+ this._test.test(() => this._forEachDatabox((databox, index) => actionUtils_1.default.runAction(() => action(databox, index), failMsg)));
160
130
  this._test.pushSyncWait();
161
131
  return this.self();
162
132
  }
163
133
  // noinspection JSUnusedGlobalSymbols
164
134
  /**
165
135
  * @description
166
- * Asserts that the databox should trigger an DataChange event.
167
- * It is also possible to assert only in case of specific data event reasons.
136
+ * Asserts that the databox should trigger an data change event.
137
+ * It is also possible to filter for specific data event reasons with a queric query.
168
138
  */
169
- dataChangeTriggers(...reasons) {
139
+ dataChangeTriggers(reasonFilter) {
140
+ const filter = reasonFilter ? (0, queric_1.default)(reasonFilter) : () => true;
170
141
  return new dataEventAsserter_1.DataEventAsserter(this.databoxes.map(d => {
171
142
  return (listener) => {
172
143
  let handler;
173
- d.onDataChange(handler = (data, triggerReasons) => {
174
- if (reasons.length === 0 || (triggerReasons.findIndex(r => reasons.indexOf(r) !== -1) !== -1)) {
144
+ d.onDataChange(handler = (data, reason, storage) => {
145
+ if (filter(reason)) {
175
146
  d.offDataChange(handler);
176
- listener(data);
147
+ listener(data, reason, storage);
177
148
  }
178
149
  });
179
150
  };
180
- }), "Databox", "DataChange", this._test, this.self(), ((reasons.length > 0) ? ` with any of these reasons: [${reasons}]` : ''));
151
+ }), "Databox", "data change", this._test, this.self(), 0, ((reasonFilter) ? ` with reasons that match the filter: ${reasonFilter}` : ''));
181
152
  }
182
153
  // noinspection JSUnusedGlobalSymbols
183
154
  /**
184
155
  * @description
185
- * Asserts that the databox should trigger an DataTouch event.
186
- * It is also possible to assert only in case of specific data event reasons.
156
+ * Asserts that the databox should trigger an data touch event.
157
+ * It is also possible to filter for specific data event reasons with a queric query.
187
158
  */
188
- dataTouchTriggers(...reasons) {
159
+ dataTouchTriggers(reasonFilter) {
160
+ const filter = reasonFilter ? (0, queric_1.default)(reasonFilter) : () => true;
189
161
  return new dataEventAsserter_1.DataEventAsserter(this.databoxes.map(d => {
190
162
  return (listener) => {
191
163
  let handler;
192
- d.onDataTouch(handler = (data, triggerReasons) => {
193
- if (reasons.length === 0 || (triggerReasons.findIndex(r => reasons.indexOf(r) !== -1) !== -1)) {
164
+ d.onDataTouch(handler = (data, reason, storage) => {
165
+ if (filter(reason)) {
194
166
  d.offDataTouch(handler);
195
- listener(data);
167
+ listener(data, reason, storage);
196
168
  }
197
169
  });
198
170
  };
199
- }), "Databox", "DataTouch", this._test, this.self(), ((reasons.length > 0) ? ` with any of these reasons: [${reasons}]` : ''));
171
+ }), "Databox", "data touch", this._test, this.self(), 0, ((reasonFilter) ? ` with reasons that match the filter: ${reasonFilter}` : ''));
200
172
  }
201
173
  // noinspection JSUnusedGlobalSymbols
202
174
  /**
203
175
  * @description
204
- * Asserts that the databox should trigger an Close event.
176
+ * Asserts that the databox should trigger an close event.
205
177
  */
206
178
  closeTriggers() {
207
- return new codeDataEventAsserter_1.CodeDataEventAsserter(this.databoxes.map(d => {
208
- return (listener) => {
209
- d.onceClose((code, data) => {
210
- listener(data, code);
211
- });
212
- };
213
- }), "Databox", "Close", this._test, this.self());
179
+ return new codeMetadataEventAsserter_1.CodeMetadataEventAsserter(this.databoxes.map(d => {
180
+ return (listener) => d.onceClose(listener);
181
+ }), "Databox", "close", this._test, this.self(), 0, 1);
214
182
  }
215
183
  // noinspection JSUnusedGlobalSymbols
216
184
  /**
217
185
  * @description
218
- * Asserts that the databox should trigger an KickOut event.
186
+ * Asserts that the databox should trigger an kick out event.
219
187
  */
220
188
  kickOutTriggers() {
221
- return new codeDataEventAsserter_1.CodeDataEventAsserter(this.databoxes.map(d => {
222
- return (listener) => {
223
- d.onceKickOut((code, data) => {
224
- listener(data, code);
225
- });
226
- };
227
- }), "Databox", "KickOut", this._test, this.self());
189
+ return new codeMetadataEventAsserter_1.CodeMetadataEventAsserter(this.databoxes.map(d => {
190
+ return (listener) => d.onceKickOut(listener);
191
+ }), "Databox", "kick out", this._test, this.self(), 0, 1);
228
192
  }
229
193
  }
230
194
  exports.AbstractDataboxAsserter = AbstractDataboxAsserter;
@@ -1,13 +1,13 @@
1
1
  import { Databox } from 'zation-client';
2
2
  import { Test } from "../../test/test";
3
3
  import { AbstractDataboxAsserter } from "./abstractDataboxAsserter";
4
- export declare class DataboxAsserter<T> extends AbstractDataboxAsserter<DataboxAsserter<T>> {
4
+ export declare class DataboxAsserter<T, D extends Databox<any, any, any, any>> extends AbstractDataboxAsserter<DataboxAsserter<T, D>, D> {
5
5
  private readonly _source;
6
- constructor(databoxes: Databox[], test: Test, source: T);
6
+ constructor(databoxes: D[], test: Test, source: T);
7
7
  /**
8
8
  * @description
9
9
  * End the databox asserter.
10
10
  */
11
11
  end(): T;
12
- protected self(): DataboxAsserter<T>;
12
+ protected self(): DataboxAsserter<T, D>;
13
13
  }