zation-assured 0.5.1 → 3.0.0-dev.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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 +16 -9
  6. package/dist/lib/api/assert.js +16 -12
  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 +24 -33
  16. package/dist/lib/helper/asserter/channel/abstractChannelAsserter.js +48 -89
  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 +5 -5
  20. package/dist/lib/helper/asserter/channel/standaloneChannelAsserter.js +6 -6
  21. package/dist/lib/helper/asserter/client/abstractClientAsserter.d.ts +29 -47
  22. package/dist/lib/helper/asserter/client/abstractClientAsserter.js +91 -193
  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 +5 -5
  26. package/dist/lib/helper/asserter/client/standaloneClientAsserter.js +6 -6
  27. package/dist/lib/helper/asserter/controller/integratedResponseAsserter.d.ts +52 -0
  28. package/dist/lib/helper/asserter/controller/integratedResponseAsserter.js +112 -0
  29. package/dist/lib/helper/asserter/controller/standaloneResponseAsserter.d.ts +49 -0
  30. package/dist/lib/helper/asserter/controller/standaloneResponseAsserter.js +108 -0
  31. package/dist/lib/helper/asserter/databox/abstractDataboxAsserter.d.ts +33 -40
  32. package/dist/lib/helper/asserter/databox/abstractDataboxAsserter.js +48 -84
  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 +6 -5
  36. package/dist/lib/helper/asserter/databox/standaloneDataboxAsserter.js +6 -6
  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 +10 -12
  46. package/dist/lib/helper/asserter/value/abstractValueAsserter.js +46 -50
  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 +8 -10
  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 -76
  87. package/dist/lib/helper/asserter/controller/responseAsserter.js +0 -154
  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 -35
  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
@@ -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,13 +19,13 @@ const test_1 = require("../../test/test");
19
19
  const abstractChannelAsserter_1 = require("./abstractChannelAsserter");
20
20
  const chai_1 = require("chai");
21
21
  class StandaloneChannelAsserter extends abstractChannelAsserter_1.AbstractChannelAsserter {
22
- constructor(channel, itTestDescription) {
23
- super(Array.isArray(channel) ? channel : [channel], new test_1.Test(itTestDescription));
22
+ constructor(channel, description) {
23
+ super(Array.isArray(channel) ? channel : [channel], new test_1.Test(description));
24
24
  }
25
25
  // noinspection JSUnusedGlobalSymbols
26
26
  /**
27
27
  * @description
28
- * Will subscribe all channels (before the test).
28
+ * Subscribes all channels (before the test).
29
29
  */
30
30
  subscribe(member) {
31
31
  this._test.beforeTest(() => __awaiter(this, void 0, void 0, function* () {
@@ -34,7 +34,7 @@ class StandaloneChannelAsserter extends abstractChannelAsserter_1.AbstractChanne
34
34
  yield channel.subscribe(member);
35
35
  }
36
36
  catch (err) {
37
- chai_1.assert.fail(`Cannot subscribe to the channel ${index}. Error -> ` + err.stack);
37
+ chai_1.assert.fail(`Cannot subscribe to the channel ${index}. Error -> ` + err);
38
38
  }
39
39
  })));
40
40
  }));
@@ -1,109 +1,91 @@
1
1
  import { Test } from "../../test/test";
2
- import { DataboxOptions, Client } from 'zation-client';
3
- import { DataEventAsserter } from "../event/dataEventAsserter";
2
+ import { DataboxOptions, Client, Databox, Channel } from 'zation-client';
4
3
  import { DataboxAsserter } from "../databox/databoxAsserter";
5
4
  import { ChannelAsserter } from "../channel/channelAsserter";
6
5
  import { ValueAsserter } from "../value/valueAsserter";
7
- export declare type Responder = (resp: (err?: (any | number), responseData?: any) => void, data: any) => void;
8
- export declare abstract class AbstractClientAsserter<T> {
6
+ import { ClientAPI, ClientTokenPayload, Default } from "../../utils/types";
7
+ export declare abstract class AbstractClientAsserter<T, C extends Client<any, any>> {
9
8
  protected _test: Test;
10
- protected clients: Client[];
9
+ protected clients: C[];
11
10
  protected abstract self(): T;
12
- protected constructor(clients: Client[], test: Test);
13
- protected _forEachClient(func: (client: Client, i: number) => Promise<void>): Promise<void>;
11
+ protected constructor(clients: C[], test: Test);
12
+ protected _forEachClient(func: (client: C, i: number) => Promise<void>): Promise<void>;
14
13
  /**
15
14
  * @description
16
- * Assert that the client is connected.
15
+ * Asserts that the client is connected.
17
16
  * @param timeout
18
- * With this parameter, you can set a time limit in that the assertion must be successful.
17
+ * Sets a time limit in that the assertion must be successful.
19
18
  */
20
19
  isConnected(timeout?: number): T;
21
20
  /**
22
21
  * @description
23
- * Assert that the client is disconnected.
22
+ * Asserts that the client is disconnected.
24
23
  * @param timeout
25
- * With this parameter, you can set a time limit in that the assertion must be successful.
24
+ * Sets a time limit in that the assertion must be successful.
26
25
  */
27
26
  isDisconnected(timeout?: number): T;
28
27
  /**
29
28
  * @description
30
- * Assert that the client is authenticated.
29
+ * Asserts that the client is authenticated.
31
30
  * @param timeout
32
- * With this parameter, you can set a time limit in that the assertion must be successful.
31
+ * Sets a time limit in that the assertion must be successful.
33
32
  */
34
33
  isAuthenticated(timeout?: number): T;
35
34
  /**
36
35
  * @description
37
- * Assert that the client is deauthenticated.
36
+ * Asserts that the client is deauthenticated.
38
37
  * @param timeout
39
- * With this parameter, you can set a time limit in that the assertion must be successful.
38
+ * Sets a time limit in that the assertion must be successful.
40
39
  */
41
40
  isDeauthenticated(timeout?: number): T;
42
41
  /**
43
42
  * @description
44
- * Assert that the client has a user id.
43
+ * Asserts that the client has a user id.
45
44
  * @param userId
46
45
  * If it is not given it will assert that the client has any user id.
47
46
  */
48
47
  hasUserId(userId?: number | string): T;
49
48
  /**
50
49
  * @description
51
- * Assert that the client has a authUserGroup.
50
+ * Asserts that the client has a authUserGroup.
52
51
  * @param authUserGroup
53
52
  * If it is not given it will assert that the client has any authUserGroup.
54
53
  */
55
54
  hasAuthUserGroup(authUserGroup?: string): T;
56
55
  /**
57
56
  * @description
58
- * Assert that the client has a specific token id.
57
+ * Asserts that the client has a specific token id.
59
58
  */
60
59
  hasTokenId(tokenId: string): T;
61
60
  /**
62
61
  * @description
63
- * Assert that the client has panel access.
62
+ * Asserts that the client has panel access.
64
63
  */
65
64
  hasPanelAccess(access?: boolean): T;
66
65
  /**
67
66
  * @description
68
- * Assert the token payload of the client.
67
+ * Asserts the token payload of the client.
69
68
  */
70
- tokenPayload(): ValueAsserter<T>;
69
+ tokenPayload(): ValueAsserter<ClientTokenPayload<C>, T>;
71
70
  /**
72
71
  * @description
73
- * Assert databox.
72
+ * Create assertions on a databox of the client.
74
73
  * Will automatically connect (before the test) and disconnect (after the test) the databox.
75
74
  */
76
- databox(identifier: string, member?: any, options?: DataboxOptions): DataboxAsserter<T>;
75
+ databox<DN extends keyof ClientAPI<C>['databoxes']>(identifier: DN, member?: Default<ClientAPI<C>['databoxes'][DN]['member'], string>, options?: DataboxOptions<ClientAPI<C>['databoxes'][DN]['options'], ClientAPI<C>['databoxes'][DN]['fetchInput']>): DataboxAsserter<T, Databox<ClientAPI<C>['databoxes'][DN]['content'], Default<ClientAPI<C>['databoxes'][DN]['member'], string>, ClientAPI<C>['databoxes'][DN]['options'], ClientAPI<C>['databoxes'][DN]['fetchInput']>>;
77
76
  /**
78
77
  * @description
79
- * Assert channel.
78
+ * Create assertions on a channel of the client.
80
79
  * Will automatically subscribe (before the test) and unsubscribe (after the test) the channel.
81
80
  */
82
- channel(identifier: string, member?: any): ChannelAsserter<T>;
81
+ channel<CN extends keyof ClientAPI<C>['channels']>(identifier: CN, member?: Default<ClientAPI<C>['channels'][CN]['member'], string>): ChannelAsserter<T, Channel<Default<ClientAPI<C>['channels'][CN]['member'], string>, Default<ClientAPI<C>['channels'][CN]['publishes'], Record<string, any>>>>;
83
82
  /**
84
83
  * @description
85
- * This function lets you do extra actions on each client and asserts that no error is thrown.
86
- * When an error throws, it lets the test fail with the provided message or the concrete error.
84
+ * Runs a extra test action and asserts that no error will be thrown.
85
+ * AssertionErrors will be rethrown, and all other errors will fail
86
+ * the test with the provided message or the concrete error.
87
87
  * @param action
88
- * @param message if not provided it throws the specific error.
88
+ * @param failMsg If not provided, the concrete error is used.
89
89
  */
90
- action(action: (client: Client, index: number) => void | Promise<void>, message?: string): T;
91
- /**
92
- * @description
93
- * This function lets you do extra actions on each client and
94
- * asserts that an error or an error instance of a specific class is thrown.
95
- * When no error is thrown, or the error does not match with the given classes
96
- * (only if at least one class is given), it lets the test fail with the provided message.
97
- * @param action
98
- * @param message
99
- * @param validErrorClasses
100
- */
101
- actionShouldThrow(action: (client: Client, index: number) => void | Promise<void>, message: string, ...validErrorClasses: any[]): T;
102
- /**
103
- * @description
104
- * Assert that the client should receive an emit-event from the server.
105
- * It uses the custom zation event namespace
106
- * (so you cannot have name conflicts with internal event names).
107
- */
108
- receiveEvent(event: string, responder?: Responder): DataEventAsserter<T>;
90
+ action(action: (client: C, index: number) => void | Promise<void>, failMsg?: string): T;
109
91
  }
@@ -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); }); }
@@ -16,10 +16,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  exports.AbstractClientAsserter = void 0;
18
18
  const assert = require('assert');
19
- const zation_client_1 = require("zation-client");
20
19
  const timeoutAssert_1 = require("../../timeout/timeoutAssert");
21
20
  const actionUtils_1 = require("../../utils/actionUtils");
22
- const dataEventAsserter_1 = require("../event/dataEventAsserter");
23
21
  const databoxAsserter_1 = require("../databox/databoxAsserter");
24
22
  const channelAsserter_1 = require("../channel/channelAsserter");
25
23
  const valueAsserter_1 = require("../value/valueAsserter");
@@ -30,218 +28,160 @@ class AbstractClientAsserter {
30
28
  }
31
29
  _forEachClient(func) {
32
30
  return __awaiter(this, void 0, void 0, function* () {
33
- let promises = [];
34
- this.clients.forEach((c, i) => {
35
- promises.push(func(c, i));
36
- });
37
- yield Promise.all(promises);
31
+ yield Promise.all(this.clients.map((client, index) => func(client, index)));
38
32
  });
39
33
  }
40
34
  // noinspection JSUnusedGlobalSymbols
41
35
  /**
42
36
  * @description
43
- * Assert that the client is connected.
37
+ * Asserts that the client is connected.
44
38
  * @param timeout
45
- * With this parameter, you can set a time limit in that the assertion must be successful.
39
+ * Sets a time limit in that the assertion must be successful.
46
40
  */
47
41
  isConnected(timeout = 0) {
48
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
49
- yield this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
50
- if (c.isConnected()) {
51
- return;
52
- }
53
- const toa = new timeoutAssert_1.TimeoutAssert(`Client: ${i} should be connected.`, timeout);
54
- c.eventReact().onceConnect(() => {
55
- toa.resolve();
56
- });
57
- yield toa.set();
58
- }));
59
- }));
42
+ this._test.test(() => this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
43
+ if (c.connected)
44
+ return;
45
+ const toa = new timeoutAssert_1.TimeoutAssert(`Client: ${i} should be connected.`, timeout);
46
+ c.onceConnect(() => {
47
+ toa.resolve();
48
+ });
49
+ yield toa.set();
50
+ })));
60
51
  return this.self();
61
52
  }
62
53
  // noinspection JSUnusedGlobalSymbols
63
54
  /**
64
55
  * @description
65
- * Assert that the client is disconnected.
56
+ * Asserts that the client is disconnected.
66
57
  * @param timeout
67
- * With this parameter, you can set a time limit in that the assertion must be successful.
58
+ * Sets a time limit in that the assertion must be successful.
68
59
  */
69
60
  isDisconnected(timeout = 0) {
70
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
71
- yield this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
72
- if (!c.isConnected()) {
73
- return;
74
- }
75
- const toa = new timeoutAssert_1.TimeoutAssert(`Client: ${i} should be disconnected.`, timeout);
76
- c.eventReact().onceDisconnect(() => {
77
- toa.resolve();
78
- });
79
- yield toa.set();
80
- }));
81
- }));
61
+ this._test.test(() => this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
62
+ if (!c.connected)
63
+ return;
64
+ const toa = new timeoutAssert_1.TimeoutAssert(`Client: ${i} should be disconnected.`, timeout);
65
+ c.onceDisconnect(() => {
66
+ toa.resolve();
67
+ });
68
+ yield toa.set();
69
+ })));
82
70
  return this.self();
83
71
  }
84
72
  // noinspection JSUnusedGlobalSymbols
85
73
  /**
86
74
  * @description
87
- * Assert that the client is authenticated.
75
+ * Asserts that the client is authenticated.
88
76
  * @param timeout
89
- * With this parameter, you can set a time limit in that the assertion must be successful.
77
+ * Sets a time limit in that the assertion must be successful.
90
78
  */
91
79
  isAuthenticated(timeout = 0) {
92
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
93
- yield this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
94
- if (c.isAuthenticated()) {
95
- return;
96
- }
97
- const toa = new timeoutAssert_1.TimeoutAssert(`Client: ${i} should be authenticated.`, timeout);
98
- c.eventReact().onceAuthenticate(() => {
99
- toa.resolve();
100
- });
101
- yield toa.set();
102
- }));
103
- }));
80
+ this._test.test(() => this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
81
+ if (c.authenticated)
82
+ return;
83
+ const toa = new timeoutAssert_1.TimeoutAssert(`Client: ${i} should be authenticated.`, timeout);
84
+ c.onceAuthenticate(() => {
85
+ toa.resolve();
86
+ });
87
+ yield toa.set();
88
+ })));
104
89
  return this.self();
105
90
  }
106
91
  // noinspection JSUnusedGlobalSymbols
107
92
  /**
108
93
  * @description
109
- * Assert that the client is deauthenticated.
94
+ * Asserts that the client is deauthenticated.
110
95
  * @param timeout
111
- * With this parameter, you can set a time limit in that the assertion must be successful.
96
+ * Sets a time limit in that the assertion must be successful.
112
97
  */
113
98
  isDeauthenticated(timeout = 0) {
114
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
115
- yield this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
116
- if (!c.isAuthenticated()) {
117
- return;
118
- }
119
- const toa = new timeoutAssert_1.TimeoutAssert(`Client: ${i} should be deauthenticated.`, timeout);
120
- c.eventReact().onceDeauthenticate(() => {
121
- toa.resolve();
122
- });
123
- yield toa.set();
124
- }));
125
- }));
99
+ this._test.test(() => this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
100
+ if (!c.authenticated)
101
+ return;
102
+ const toa = new timeoutAssert_1.TimeoutAssert(`Client: ${i} should be deauthenticated.`, timeout);
103
+ c.onceDeauthenticate(() => {
104
+ toa.resolve();
105
+ });
106
+ yield toa.set();
107
+ })));
126
108
  return this.self();
127
109
  }
128
110
  // noinspection JSUnusedGlobalSymbols
129
111
  /**
130
112
  * @description
131
- * Assert that the client has a user id.
113
+ * Asserts that the client has a user id.
132
114
  * @param userId
133
115
  * If it is not given it will assert that the client has any user id.
134
116
  */
135
117
  hasUserId(userId) {
136
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
137
- yield this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
138
- const currentId = c.userId;
139
- if (userId !== undefined) {
140
- assert.equal(currentId, userId, `Client: ${i} should have the userId: ${userId}`);
141
- }
142
- else if (currentId === undefined) {
143
- assert.fail(`Client: ${i} should have any user id.`);
144
- }
145
- }));
146
- }));
118
+ this._test.test(() => this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
119
+ const currentId = c.userId;
120
+ if (userId != null)
121
+ assert.equal(currentId, userId, `Client: ${i} should have the userId: ${userId}`);
122
+ else if (currentId == null)
123
+ assert.fail(`Client: ${i} should have any user id.`);
124
+ })));
147
125
  return this.self();
148
126
  }
149
127
  // noinspection JSUnusedGlobalSymbols
150
128
  /**
151
129
  * @description
152
- * Assert that the client has a authUserGroup.
130
+ * Asserts that the client has a authUserGroup.
153
131
  * @param authUserGroup
154
132
  * If it is not given it will assert that the client has any authUserGroup.
155
133
  */
156
134
  hasAuthUserGroup(authUserGroup) {
157
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
158
- yield this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
159
- const currentGroup = c.authUserGroup;
160
- if (authUserGroup !== undefined) {
161
- assert.equal(currentGroup, authUserGroup, `Client: ${i} should have the authUserGroup: ${authUserGroup}`);
162
- }
163
- else if (currentGroup === undefined) {
164
- assert.fail(`Client: ${i} should have any authUserGroup.`);
165
- }
166
- }));
167
- }));
135
+ this._test.test(() => this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
136
+ const currentGroup = c.authUserGroup;
137
+ if (authUserGroup != null) {
138
+ assert.equal(currentGroup, authUserGroup, `Client: ${i} should have the authUserGroup: ${authUserGroup}`);
139
+ }
140
+ else if (currentGroup == null)
141
+ assert.fail(`Client: ${i} should have any authUserGroup.`);
142
+ })));
168
143
  return this.self();
169
144
  }
170
145
  // noinspection JSUnusedGlobalSymbols
171
146
  /**
172
147
  * @description
173
- * Assert that the client has a specific token id.
148
+ * Asserts that the client has a specific token id.
174
149
  */
175
150
  hasTokenId(tokenId) {
176
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
177
- yield this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
178
- try {
179
- const currentTokenId = c.tokenId;
180
- assert.equal(currentTokenId, tokenId, `Client: ${i} should have the tokenId: ${tokenId}`);
181
- }
182
- catch (e) {
183
- if (e instanceof zation_client_1.AuthenticationRequiredError) {
184
- assert.fail(`Client: ${i} can not access the token for assert token id.`);
185
- }
186
- else {
187
- throw e;
188
- }
189
- }
190
- }));
191
- }));
151
+ this._test.test(() => this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
152
+ var _a;
153
+ assert.equal((_a = c.authToken) === null || _a === void 0 ? void 0 : _a.tid, tokenId, `Client: ${i} should have the tokenId: ${tokenId}`);
154
+ })));
192
155
  return this.self();
193
156
  }
194
157
  // noinspection JSUnusedGlobalSymbols
195
158
  /**
196
159
  * @description
197
- * Assert that the client has panel access.
160
+ * Asserts that the client has panel access.
198
161
  */
199
162
  hasPanelAccess(access = true) {
200
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
201
- yield this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
202
- try {
203
- const currentAccess = c.hasPanelAccess();
204
- assert.equal(currentAccess, access, `Client: ${i} should ${access ? '' : 'not'} have panel access`);
205
- }
206
- catch (e) {
207
- if (e instanceof zation_client_1.AuthenticationRequiredError) {
208
- assert.fail(`Client: ${i} can not access the token for assert panel access.`);
209
- }
210
- else {
211
- throw e;
212
- }
213
- }
214
- }));
215
- }));
163
+ this._test.test(() => this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
164
+ var _a;
165
+ assert.equal((_a = c.authToken) === null || _a === void 0 ? void 0 : _a.panelAccess, access, `Client: ${i} should ${access ? '' : 'not'} have panel access`);
166
+ })));
216
167
  return this.self();
217
168
  }
218
169
  // noinspection JSUnusedGlobalSymbols
219
170
  /**
220
171
  * @description
221
- * Assert the token payload of the client.
172
+ * Asserts the token payload of the client.
222
173
  */
223
174
  tokenPayload() {
224
- return new valueAsserter_1.ValueAsserter(this.self(), 'Client:', (test) => {
225
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
226
- yield this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
227
- try {
228
- test(c.getTokenPayload(), ` ${i} Token:`);
229
- }
230
- catch (e) {
231
- if (e instanceof zation_client_1.AuthenticationRequiredError) {
232
- assert.fail(`Client: ${i} token payload can not be asserted because the client is not authenticated.`);
233
- }
234
- else
235
- throw e;
236
- }
237
- }));
238
- }));
175
+ return new valueAsserter_1.ValueAsserter(this.self(), (test) => {
176
+ this._test.test(() => this._forEachClient((c, i) => __awaiter(this, void 0, void 0, function* () {
177
+ test(c.authTokenPayload, `Client: ${i} token payload:`);
178
+ })));
239
179
  });
240
180
  }
241
181
  // noinspection JSUnusedGlobalSymbols
242
182
  /**
243
183
  * @description
244
- * Assert databox.
184
+ * Create assertions on a databox of the client.
245
185
  * Will automatically connect (before the test) and disconnect (after the test) the databox.
246
186
  */
247
187
  databox(identifier, member, options = {}) {
@@ -252,12 +192,10 @@ class AbstractClientAsserter {
252
192
  yield db.connect(member);
253
193
  }
254
194
  catch (err) {
255
- assert.fail("Cannot connect the databox. Error -> " + err.stack);
195
+ assert.fail("Cannot connect the databox. Error -> " + err);
256
196
  }
257
197
  }));
258
- this._test.afterTest(() => __awaiter(this, void 0, void 0, function* () {
259
- yield db.disconnect();
260
- }));
198
+ this._test.afterTest(() => db.disconnect());
261
199
  return db;
262
200
  });
263
201
  return new databoxAsserter_1.DataboxAsserter(databoxes, this._test, this.self());
@@ -265,7 +203,7 @@ class AbstractClientAsserter {
265
203
  // noinspection JSUnusedGlobalSymbols
266
204
  /**
267
205
  * @description
268
- * Assert channel.
206
+ * Create assertions on a channel of the client.
269
207
  * Will automatically subscribe (before the test) and unsubscribe (after the test) the channel.
270
208
  */
271
209
  channel(identifier, member) {
@@ -276,12 +214,10 @@ class AbstractClientAsserter {
276
214
  yield channel.subscribe(member);
277
215
  }
278
216
  catch (err) {
279
- assert.fail("Cannot subscribe to the channel. Error -> " + err.stack);
217
+ assert.fail("Cannot subscribe to the channel. Error -> " + err);
280
218
  }
281
219
  }));
282
- this._test.afterTest(() => {
283
- channel.unsubscribe();
284
- });
220
+ this._test.afterTest(() => channel.unsubscribe());
285
221
  return channel;
286
222
  });
287
223
  return new channelAsserter_1.ChannelAsserter(channels, this._test, this.self());
@@ -289,54 +225,16 @@ class AbstractClientAsserter {
289
225
  // noinspection JSUnusedGlobalSymbols
290
226
  /**
291
227
  * @description
292
- * This function lets you do extra actions on each client and asserts that no error is thrown.
293
- * When an error throws, it lets the test fail with the provided message or the concrete error.
294
- * @param action
295
- * @param message if not provided it throws the specific error.
296
- */
297
- action(action, message) {
298
- this.clients.forEach((client, index) => {
299
- actionUtils_1.default.action(this._test, () => action(client, index), message);
300
- });
301
- this._test.pushSyncWait();
302
- return this.self();
303
- }
304
- // noinspection JSUnusedGlobalSymbols
305
- /**
306
- * @description
307
- * This function lets you do extra actions on each client and
308
- * asserts that an error or an error instance of a specific class is thrown.
309
- * When no error is thrown, or the error does not match with the given classes
310
- * (only if at least one class is given), it lets the test fail with the provided message.
228
+ * Runs a extra test action and asserts that no error will be thrown.
229
+ * AssertionErrors will be rethrown, and all other errors will fail
230
+ * the test with the provided message or the concrete error.
311
231
  * @param action
312
- * @param message
313
- * @param validErrorClasses
232
+ * @param failMsg If not provided, the concrete error is used.
314
233
  */
315
- actionShouldThrow(action, message, ...validErrorClasses) {
316
- this.clients.forEach((client, index) => {
317
- actionUtils_1.default.actionShouldThrow(this._test, () => action(client, index), message, ...validErrorClasses);
318
- });
234
+ action(action, failMsg) {
235
+ this._test.test(() => this._forEachClient((client, index) => actionUtils_1.default.runAction(() => action(client, index), failMsg)));
319
236
  this._test.pushSyncWait();
320
237
  return this.self();
321
238
  }
322
- // noinspection JSUnusedGlobalSymbols
323
- /**
324
- * @description
325
- * Assert that the client should receive an emit-event from the server.
326
- * It uses the custom zation event namespace
327
- * (so you cannot have name conflicts with internal event names).
328
- */
329
- receiveEvent(event, responder = (resp) => {
330
- resp(null);
331
- }) {
332
- return new dataEventAsserter_1.DataEventAsserter(this.clients.map(c => {
333
- return (listener) => {
334
- c.once(event, (data, response) => {
335
- listener(data);
336
- responder(response, data);
337
- });
338
- };
339
- }), "Client", event, this._test, this.self());
340
- }
341
239
  }
342
240
  exports.AbstractClientAsserter = AbstractClientAsserter;
@@ -1,13 +1,13 @@
1
1
  import { Client } from 'zation-client';
2
2
  import { AbstractClientAsserter } from "./abstractClientAsserter";
3
3
  import { Test } from "../../test/test";
4
- export declare class ClientAsserter<T> extends AbstractClientAsserter<ClientAsserter<T>> {
4
+ export declare class ClientAsserter<T, C extends Client<any, any>> extends AbstractClientAsserter<ClientAsserter<T, C>, C> {
5
5
  private readonly _source;
6
- constructor(clients: Client[], test: Test, source: T);
6
+ constructor(clients: C[], test: Test, source: T);
7
7
  /**
8
8
  * @description
9
9
  * End the client asserter.
10
10
  */
11
11
  end(): T;
12
- protected self(): ClientAsserter<T>;
12
+ protected self(): ClientAsserter<T, C>;
13
13
  }
@@ -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
  Object.defineProperty(exports, "__esModule", { value: true });
8
8
  exports.ClientAsserter = void 0;
@@ -1,16 +1,16 @@
1
1
  import { Client } from 'zation-client';
2
2
  import { AbstractClientAsserter } from "./abstractClientAsserter";
3
- export declare class StandaloneClientAsserter extends AbstractClientAsserter<StandaloneClientAsserter> {
4
- constructor(client: Client | Client[], itTestDescription?: string);
3
+ export declare class StandaloneClientAsserter<C extends Client<any, any>> extends AbstractClientAsserter<StandaloneClientAsserter<C>, C> {
4
+ constructor(client: C | C[], description?: string);
5
5
  /**
6
6
  * @description
7
- * Will connect all clients (before the test).
7
+ * Connects all clients (before the test).
8
8
  */
9
- connect(): StandaloneClientAsserter;
9
+ connect(): StandaloneClientAsserter<C>;
10
10
  /**
11
11
  * @description
12
12
  * Run the test.
13
13
  */
14
14
  test(): Promise<void>;
15
- protected self(): StandaloneClientAsserter;
15
+ protected self(): StandaloneClientAsserter<C>;
16
16
  }