zation-assured 0.6.0 → 3.0.0-dev.2

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 +5 -5
  20. package/dist/lib/helper/asserter/channel/standaloneChannelAsserter.js +6 -6
  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 +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 +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 +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 +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 +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 -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
@@ -1,115 +0,0 @@
1
- "use strict";
2
- /*
3
- Author: Luca Scaringella
4
- GitHub: LucaCode
5
- ©Copyright by Luca 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 timeoutAssert_1 = require("../timeout/timeoutAssert");
18
- const anyAsserter_1 = require("./anyAsserter");
19
- const assert = require('assert');
20
- class EventAsserter {
21
- constructor(clients, event, test, source, responder = () => {
22
- }) {
23
- this._dataChecker = [];
24
- this._timeout = 0;
25
- this._not = false;
26
- this._clients = clients;
27
- this._event = event;
28
- this._test = test;
29
- this._source = source;
30
- this._responder = responder;
31
- }
32
- // noinspection JSUnusedGlobalSymbols
33
- /**
34
- * @description
35
- * With this function, you can set a time limit in that the event should receive.
36
- * @default
37
- * The default value is 0.
38
- */
39
- timeout(timeout) {
40
- this._timeout = timeout;
41
- return this;
42
- }
43
- // noinspection JSUnusedGlobalSymbols
44
- /**
45
- * @description
46
- * With this function, you set that the client should not receive the event.
47
- * @default
48
- * The default value is false.
49
- */
50
- not() {
51
- this._not = true;
52
- return this;
53
- }
54
- // noinspection JSUnusedGlobalSymbols
55
- /**
56
- * @description
57
- * Assert the received data.
58
- * Notice that the data will not checked in (get not) mode.
59
- */
60
- assertData() {
61
- return new anyAsserter_1.AnyAsserter(this, '', (test) => {
62
- this._dataChecker.push(test);
63
- });
64
- }
65
- _checkData(data, clientIndex) {
66
- this._dataChecker.forEach((f) => {
67
- f(data, `Client: ${clientIndex} event: ${this._event} -> Received data `);
68
- });
69
- }
70
- // noinspection JSUnusedGlobalSymbols
71
- /**
72
- * @description
73
- * End the event asserter.
74
- */
75
- end() {
76
- this._clients.forEach((c, i) => {
77
- let receivedEmit = false;
78
- let data;
79
- let resolve;
80
- this._test.beforeTest(() => {
81
- c.once(this._event, (d, res) => {
82
- this._responder(res, d);
83
- data = d;
84
- receivedEmit = true;
85
- if (typeof resolve === 'function') {
86
- resolve();
87
- }
88
- });
89
- });
90
- const failMsg = `Client: ${i} should ${this._not ? 'not ' : ''}receive the event: ${this._event} from the server.`;
91
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
92
- if (!receivedEmit) {
93
- const toa = new timeoutAssert_1.TimeoutAssert(failMsg, this._timeout, this._not);
94
- resolve = () => {
95
- toa.resolve();
96
- };
97
- yield toa.set();
98
- if (!this._not && toa.isSuccess()) {
99
- this._checkData(data, i);
100
- }
101
- }
102
- else {
103
- if (!this._not) {
104
- this._checkData(data, i);
105
- }
106
- else {
107
- assert.fail(failMsg);
108
- }
109
- }
110
- }));
111
- });
112
- return this._source;
113
- }
114
- }
115
- exports.EventAsserter = EventAsserter;
@@ -1,55 +0,0 @@
1
- import { ForintQuery } from "forint";
2
- declare type AddTest = (test: (obj: any, eStr?: string) => void) => void;
3
- export default class ObjectAsserter<T> {
4
- protected readonly self: T;
5
- private readonly addTest;
6
- private readonly name;
7
- constructor(self: T, name: string, addTest: AddTest);
8
- /**
9
- * @description
10
- * Assert that the object has all specific keys or more.
11
- * @param keys
12
- */
13
- containsAllKeys(...keys: string[]): ObjectAsserter<T>;
14
- /**
15
- * @description
16
- * Assert that the object has at least one specific key or more.
17
- * @param keys
18
- */
19
- hasAnyKeys(...keys: string[]): ObjectAsserter<T>;
20
- /**
21
- * @description
22
- * Assert that the object is deepEqual with...
23
- * @param obj
24
- */
25
- deepEqual(obj: any): ObjectAsserter<T>;
26
- /**
27
- * @description
28
- * Assert that the object own includes...
29
- * Can be used to assert the inclusion of a subset of properties
30
- * in an object while ignoring inherited properties.
31
- * @example
32
- * ownInclude({id : 10});
33
- * @param obj
34
- */
35
- ownInclude(obj: any): ObjectAsserter<T>;
36
- /**
37
- * Asserts that object matches with a forint query.
38
- */
39
- matches(query: ForintQuery): ObjectAsserter<T>;
40
- /**
41
- * @description
42
- * With this function you can create custom assertions for object.
43
- * @param assert
44
- * function with params
45
- * -obj the input
46
- * -name the name of this assertion.
47
- */
48
- assert(assert: (obj: any, name: string) => void | Promise<void>): ObjectAsserter<T>;
49
- /**
50
- * @description
51
- * End the object asserter.
52
- */
53
- end(): T;
54
- }
55
- export {};
@@ -1,113 +0,0 @@
1
- "use strict";
2
- /*
3
- Author: Luca Scaringella
4
- GitHub: LucaCode
5
- ©Copyright by Luca 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 forint_1 = require("forint");
18
- const cAssert = require('chai').assert;
19
- class ObjectAsserter {
20
- constructor(self, name, addTest) {
21
- this.self = self;
22
- this.addTest = addTest;
23
- this.name = name;
24
- }
25
- // noinspection JSUnusedGlobalSymbols
26
- /**
27
- * @description
28
- * Assert that the object has all specific keys or more.
29
- * @param keys
30
- */
31
- containsAllKeys(...keys) {
32
- this.addTest((obj, eStr = '') => {
33
- cAssert.containsAllKeys(obj, keys, `${this.name + eStr} should contains ${keys} as keys.`);
34
- });
35
- return this;
36
- }
37
- // noinspection JSUnusedGlobalSymbols
38
- /**
39
- * @description
40
- * Assert that the object has at least one specific key or more.
41
- * @param keys
42
- */
43
- hasAnyKeys(...keys) {
44
- this.addTest((obj, eStr = '') => {
45
- cAssert.hasAnyKeys(obj, keys, `${this.name + eStr} should contains at least one of these keys: ${keys}.`);
46
- });
47
- return this;
48
- }
49
- // noinspection JSUnusedGlobalSymbols
50
- /**
51
- * @description
52
- * Assert that the object is deepEqual with...
53
- * @param obj
54
- */
55
- deepEqual(obj) {
56
- this.addTest((inObj, eStr = '') => {
57
- // noinspection TypeScriptValidateJSTypes
58
- cAssert.deepEqual(inObj, obj, `${this.name + eStr} should deep equal with ${JSON.stringify(obj)}`);
59
- });
60
- return this;
61
- }
62
- // noinspection JSUnusedGlobalSymbols
63
- /**
64
- * @description
65
- * Assert that the object own includes...
66
- * Can be used to assert the inclusion of a subset of properties
67
- * in an object while ignoring inherited properties.
68
- * @example
69
- * ownInclude({id : 10});
70
- * @param obj
71
- */
72
- ownInclude(obj) {
73
- this.addTest((inObj, eStr = '') => {
74
- // noinspection TypeScriptValidateJSTypes
75
- cAssert.ownInclude(inObj, obj, `${this.name + eStr} should own include ${JSON.stringify(obj)}`);
76
- });
77
- return this;
78
- }
79
- // noinspection JSUnusedGlobalSymbols
80
- /**
81
- * Asserts that object matches with a forint query.
82
- */
83
- matches(query) {
84
- this.addTest((inObj, eStr = '') => __awaiter(this, void 0, void 0, function* () {
85
- yield cAssert(forint_1.default(query)(inObj), `${this.name + eStr} should match with the forint query.`);
86
- }));
87
- return this;
88
- }
89
- // noinspection JSUnusedGlobalSymbols
90
- /**
91
- * @description
92
- * With this function you can create custom assertions for object.
93
- * @param assert
94
- * function with params
95
- * -obj the input
96
- * -name the name of this assertion.
97
- */
98
- assert(assert) {
99
- this.addTest((inObj, eStr = '') => __awaiter(this, void 0, void 0, function* () {
100
- yield assert(inObj, (this.name + eStr));
101
- }));
102
- return this;
103
- }
104
- // noinspection JSUnusedGlobalSymbols
105
- /**
106
- * @description
107
- * End the object asserter.
108
- */
109
- end() {
110
- return this.self;
111
- }
112
- }
113
- exports.default = ObjectAsserter;
@@ -1,9 +0,0 @@
1
- import { PackageBuilder as NativePackageBuilder, Client } from "zation-client";
2
- import { Test } from "../../test/test";
3
- import { RootSendAsserter } from "../rootSendAsserter";
4
- export declare class TransmitAsserter extends RootSendAsserter<TransmitAsserter> {
5
- private nativeBuilder;
6
- constructor(nativeBuilder: NativePackageBuilder<any>, test: Test, client: Client);
7
- protected _executeAction(): Promise<void>;
8
- protected self(): TransmitAsserter;
9
- }
@@ -1,129 +0,0 @@
1
- import { AbstractRequestBuilder as NativeAbstractRequestBuilder, ZationClient, Response, BackErrorFilter } from "zation-client";
2
- import { Test } from "../test/test";
3
- import { WhenBuilder } from "../../api/when";
4
- import { AnyAsserter } from "./anyAsserter";
5
- import { BackErrorFilterBuilder } from "../backError/backErrorFilterBuilder";
6
- import { ClientAsserter } from "./clientAsserter";
7
- export declare class ResponseAsserter {
8
- private req;
9
- private readonly _test;
10
- private readonly _client;
11
- private autoConnectedClient;
12
- private _shouldThrowTimeoutError;
13
- private _shouldThrowConnectionRequiredError;
14
- constructor(req: NativeAbstractRequestBuilder<any>, test: Test, client: ZationClient);
15
- private _createTest;
16
- private _respInfo;
17
- /**
18
- * @description
19
- * Assert that send the request should throw a timeout error.
20
- * @param value
21
- */
22
- throwsTimeoutError(value?: boolean): ResponseAsserter;
23
- /**
24
- * @description
25
- * Assert that send the request should throw a connection required error.
26
- * @param value
27
- */
28
- throwsConnectionRequiredError(value?: boolean): ResponseAsserter;
29
- /**
30
- * @description
31
- * Assert that the response is successful.
32
- */
33
- isSuccessful(): ResponseAsserter;
34
- /**
35
- * @description
36
- * Assert that the response is not successful.
37
- */
38
- isNotSuccessful(): ResponseAsserter;
39
- /**
40
- * @description
41
- * Assert that the response has a result.
42
- */
43
- hasResult(): ResponseAsserter;
44
- /**
45
- * @description
46
- * Assert the result of the response.
47
- */
48
- assertResult(): AnyAsserter<ResponseAsserter>;
49
- /**
50
- * @description
51
- * Print the complete response to the console.
52
- */
53
- print(): ResponseAsserter;
54
- /**
55
- * @description
56
- * Assert that the response has a specific count of errors.
57
- * @param count
58
- * count of errors
59
- * @param filter
60
- * Filter to filter for specific errors.
61
- */
62
- hasErrorCount(count: number, ...filter: BackErrorFilter[]): ResponseAsserter;
63
- /**
64
- * @description
65
- * Assert that the response has count of specific errors
66
- * with filter builder.
67
- * @param count
68
- * count of errors
69
- */
70
- buildHasErrorCount(count: number): BackErrorFilterBuilder<ResponseAsserter>;
71
- /**
72
- * @description
73
- * Assert that the response has an specific error
74
- * with filter builder.
75
- */
76
- hasError(): BackErrorFilterBuilder<ResponseAsserter>;
77
- /**
78
- * @description
79
- * Assert that the response has an error.
80
- * @param filter
81
- * Filter to filter for specific errors.
82
- */
83
- hasError(...filter: BackErrorFilter[]): ResponseAsserter;
84
- private static _filterErrors;
85
- /**
86
- * @description
87
- * With this function you can create custom assertions for a response.
88
- * @param assert
89
- * The assert function with params:
90
- * -res The response
91
- */
92
- assert(assert: (resp: Response) => void | Promise<void>): ResponseAsserter;
93
- /**
94
- * @description
95
- * With this function, you can do extra things in the test.
96
- * Subscribe a channel, publish to a channel...
97
- * @param func
98
- * @param failMsg if not provided it throws the specific error.
99
- */
100
- do(func: () => void | Promise<void>, failMsg?: string): ResponseAsserter;
101
- /**
102
- * @description
103
- * With this function, you can do extra things in the test
104
- * and assert that it should throw an error or a specific error.
105
- * Subscribe a channel, publish to a channel...
106
- * @param func
107
- * @param failMsg
108
- * @param errors
109
- */
110
- doShouldThrow(func: () => void | Promise<void>, failMsg: string, ...errors: any[]): ResponseAsserter;
111
- /**
112
- * @description
113
- * Start with a new request and link them to one test.
114
- */
115
- and(): WhenBuilder;
116
- /**
117
- * @description
118
- * Run the test.
119
- * @param autoConnect
120
- * Will auto connect the client
121
- * if the client is not connected to the server.
122
- */
123
- test(autoConnect?: boolean): Promise<void>;
124
- /**
125
- * @description
126
- * Assert zation clients after request.
127
- */
128
- client(...client: ZationClient[]): ClientAsserter<ResponseAsserter>;
129
- }
@@ -1,260 +0,0 @@
1
- "use strict";
2
- /*
3
- Author: Luca Scaringella
4
- GitHub: LucaCode
5
- ©Copyright by Luca 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 zation_client_1 = require("zation-client");
18
- const when_1 = require("../../api/when");
19
- const logger_1 = require("../console/logger");
20
- const anyAsserter_1 = require("./anyAsserter");
21
- const backErrorFilterBuilder_1 = require("../backError/backErrorFilterBuilder");
22
- const clientAsserter_1 = require("./clientAsserter");
23
- const doUtils_1 = require("../do/doUtils");
24
- const assert = require('assert');
25
- class ResponseAsserter {
26
- constructor(req, test, client) {
27
- this.autoConnectedClient = false;
28
- this._shouldThrowTimeoutError = false;
29
- this._shouldThrowConnectionRequiredError = false;
30
- this.req = req;
31
- this._test = test;
32
- this._client = client;
33
- this._createTest();
34
- }
35
- _createTest() {
36
- this._test.test(() => __awaiter(this, void 0, void 0, function* () {
37
- if (!this._client.isConnected() && this.autoConnectedClient) {
38
- yield this._client.connect();
39
- }
40
- try {
41
- yield this.req.send(false);
42
- if (this._shouldThrowTimeoutError) {
43
- assert.fail('Send should throw a timeout error.');
44
- }
45
- if (this._shouldThrowConnectionRequiredError) {
46
- assert.fail('Send should throw a connection required error.');
47
- }
48
- }
49
- catch (e) {
50
- if (e instanceof zation_client_1.TimeoutError) {
51
- if (!this._shouldThrowTimeoutError) {
52
- assert.fail('Send should not throw a timeout error.');
53
- }
54
- }
55
- else if (e instanceof zation_client_1.ConnectionRequiredError) {
56
- if (!this._shouldThrowConnectionRequiredError) {
57
- assert.fail('Send should not throw a connection required error.');
58
- }
59
- }
60
- else {
61
- throw e;
62
- }
63
- }
64
- }), true);
65
- }
66
- // noinspection JSMethodCanBeStatic
67
- _respInfo(res) {
68
- return '\n ' + res.toString();
69
- }
70
- // noinspection JSUnusedGlobalSymbols
71
- /**
72
- * @description
73
- * Assert that send the request should throw a timeout error.
74
- * @param value
75
- */
76
- throwsTimeoutError(value = true) {
77
- this._shouldThrowTimeoutError = value;
78
- return this;
79
- }
80
- // noinspection JSUnusedGlobalSymbols
81
- /**
82
- * @description
83
- * Assert that send the request should throw a connection required error.
84
- * @param value
85
- */
86
- throwsConnectionRequiredError(value = true) {
87
- this._shouldThrowConnectionRequiredError = value;
88
- return this;
89
- }
90
- // noinspection JSUnusedGlobalSymbols
91
- /**
92
- * @description
93
- * Assert that the response is successful.
94
- */
95
- isSuccessful() {
96
- this.req.onResponse((res) => {
97
- assert(res.isSuccessful(), 'Response should be successful.' + this._respInfo(res));
98
- });
99
- return this;
100
- }
101
- // noinspection JSUnusedGlobalSymbols
102
- /**
103
- * @description
104
- * Assert that the response is not successful.
105
- */
106
- isNotSuccessful() {
107
- this.req.onResponse((res) => {
108
- assert(!res.isSuccessful(), 'Response should be not successful.' + this._respInfo(res));
109
- });
110
- return this;
111
- }
112
- // noinspection JSUnusedGlobalSymbols
113
- /**
114
- * @description
115
- * Assert that the response has a result.
116
- */
117
- hasResult() {
118
- this.req.onResponse((res) => {
119
- assert(res.hasResult(), `Response should have a result.`
120
- + this._respInfo(res));
121
- });
122
- return this;
123
- }
124
- // noinspection JSUnusedGlobalSymbols
125
- /**
126
- * @description
127
- * Assert the result of the response.
128
- */
129
- assertResult() {
130
- return new anyAsserter_1.AnyAsserter(this, 'Response Result', (test) => {
131
- this.req.onResponse((res) => {
132
- test(res.getResult());
133
- });
134
- });
135
- }
136
- // noinspection JSUnusedGlobalSymbols
137
- /**
138
- * @description
139
- * Print the complete response to the console.
140
- */
141
- print() {
142
- this.req.onResponse((res) => {
143
- logger_1.Logger.logInfo(res.toString());
144
- });
145
- return this;
146
- }
147
- // noinspection JSUnusedGlobalSymbols
148
- /**
149
- * @description
150
- * Assert that the response has a specific count of errors.
151
- * @param count
152
- * count of errors
153
- * @param filter
154
- * Filter to filter for specific errors.
155
- */
156
- hasErrorCount(count, ...filter) {
157
- this.req.onResponse((res) => {
158
- assert(ResponseAsserter._filterErrors(res, filter).length === count, `Response should have ${count} back errors.${filter.length === 0 ? '' : ` With filter: ${JSON.stringify(filter)}`}`
159
- + this._respInfo(res));
160
- });
161
- return this;
162
- }
163
- // noinspection JSUnusedGlobalSymbols
164
- /**
165
- * @description
166
- * Assert that the response has count of specific errors
167
- * with filter builder.
168
- * @param count
169
- * count of errors
170
- */
171
- buildHasErrorCount(count) {
172
- return new backErrorFilterBuilder_1.BackErrorFilterBuilder(this, count);
173
- }
174
- hasError(...filter) {
175
- if (filter.length > 0) {
176
- this.req.onResponse((res) => {
177
- assert(ResponseAsserter._filterErrors(res, filter).length > 0, `Response should have an error.${filter.length === 0 ? '' : ` With filter: ${JSON.stringify(filter)}`}`
178
- + this._respInfo(res));
179
- });
180
- return this;
181
- }
182
- else
183
- return new backErrorFilterBuilder_1.BackErrorFilterBuilder(this);
184
- }
185
- static _filterErrors(res, filter) {
186
- return zation_client_1.ErrorFilterEngine.filterErrors(res.getErrors(false), filter);
187
- }
188
- // noinspection JSUnusedGlobalSymbols
189
- /**
190
- * @description
191
- * With this function you can create custom assertions for a response.
192
- * @param assert
193
- * The assert function with params:
194
- * -res The response
195
- */
196
- assert(assert) {
197
- this.req.onResponse((res) => __awaiter(this, void 0, void 0, function* () {
198
- yield assert(res);
199
- }));
200
- return this;
201
- }
202
- // noinspection JSUnusedGlobalSymbols
203
- /**
204
- * @description
205
- * With this function, you can do extra things in the test.
206
- * Subscribe a channel, publish to a channel...
207
- * @param func
208
- * @param failMsg if not provided it throws the specific error.
209
- */
210
- do(func, failMsg) {
211
- doUtils_1.default.do(this._test, func, failMsg);
212
- return this;
213
- }
214
- // noinspection JSUnusedGlobalSymbols
215
- /**
216
- * @description
217
- * With this function, you can do extra things in the test
218
- * and assert that it should throw an error or a specific error.
219
- * Subscribe a channel, publish to a channel...
220
- * @param func
221
- * @param failMsg
222
- * @param errors
223
- */
224
- doShouldThrow(func, failMsg, ...errors) {
225
- doUtils_1.default.doShouldThrow(this._test, func, failMsg, ...errors);
226
- return this;
227
- }
228
- // noinspection JSUnusedGlobalSymbols
229
- /**
230
- * @description
231
- * Start with a new request and link them to one test.
232
- */
233
- and() {
234
- this._test.newSubTest();
235
- return new when_1.WhenBuilder(this._client, this._test);
236
- }
237
- // noinspection JSUnusedGlobalSymbols
238
- /**
239
- * @description
240
- * Run the test.
241
- * @param autoConnect
242
- * Will auto connect the client
243
- * if the client is not connected to the server.
244
- */
245
- test(autoConnect = false) {
246
- return __awaiter(this, void 0, void 0, function* () {
247
- this.autoConnectedClient = autoConnect;
248
- return this._test.execute();
249
- });
250
- }
251
- // noinspection JSUnusedGlobalSymbols
252
- /**
253
- * @description
254
- * Assert zation clients after request.
255
- */
256
- client(...client) {
257
- return new clientAsserter_1.ClientAsserter(client, this._test, this);
258
- }
259
- }
260
- exports.ResponseAsserter = ResponseAsserter;