@api-client/core 0.9.4 → 0.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/browser.d.ts +12 -2
- package/build/browser.js +15 -2
- package/build/browser.js.map +1 -1
- package/build/index.d.ts +13 -3
- package/build/index.js +16 -3
- package/build/index.js.map +1 -1
- package/build/src/data/{JmesparthReader.d.ts → JmespathReader.d.ts} +1 -1
- package/build/src/data/{JmesparthReader.js → JmespathReader.js} +2 -2
- package/build/src/data/JmespathReader.js.map +1 -0
- package/build/src/data/RequestDataExtractor.d.ts +5 -5
- package/build/src/data/RequestDataExtractor.js.map +1 -1
- package/build/src/data/XmlReader.js +14 -1
- package/build/src/data/XmlReader.js.map +1 -1
- package/build/src/models/ClientCertificate.d.ts +9 -0
- package/build/src/models/ClientCertificate.js.map +1 -1
- package/build/src/models/Environment.d.ts +3 -2
- package/build/src/models/Environment.js +11 -6
- package/build/src/models/Environment.js.map +1 -1
- package/build/src/models/ErrorResponse.js.map +1 -1
- package/build/src/models/HttpRequest.d.ts +2 -7
- package/build/src/models/HttpRequest.js +1 -6
- package/build/src/models/HttpRequest.js.map +1 -1
- package/build/src/models/HttpResponse.d.ts +2 -7
- package/build/src/models/HttpResponse.js +1 -3
- package/build/src/models/HttpResponse.js.map +1 -1
- package/build/src/models/ProjectRequest.d.ts +19 -0
- package/build/src/models/ProjectRequest.js +50 -0
- package/build/src/models/ProjectRequest.js.map +1 -1
- package/build/src/models/Request.d.ts +12 -3
- package/build/src/models/Request.js +14 -1
- package/build/src/models/Request.js.map +1 -1
- package/build/src/models/RequestAuthorization.js.map +1 -1
- package/build/src/models/RequestLog.d.ts +11 -0
- package/build/src/models/RequestLog.js +15 -1
- package/build/src/models/RequestLog.js.map +1 -1
- package/build/src/models/SerializablePayload.d.ts +6 -1
- package/build/src/models/SerializablePayload.js +10 -6
- package/build/src/models/SerializablePayload.js.map +1 -1
- package/build/src/models/http-actions/AssertionError.d.ts +36 -0
- package/build/src/models/http-actions/AssertionError.js +35 -0
- package/build/src/models/http-actions/AssertionError.js.map +1 -0
- package/build/src/models/http-actions/HttpAssertion.d.ts +84 -0
- package/build/src/models/http-actions/HttpAssertion.js +52 -0
- package/build/src/models/http-actions/HttpAssertion.js.map +1 -0
- package/build/src/models/http-actions/HttpFlows.d.ts +109 -0
- package/build/src/models/http-actions/HttpFlows.js +31 -0
- package/build/src/models/http-actions/HttpFlows.js.map +1 -0
- package/build/src/models/http-actions/HttpStep.d.ts +29 -0
- package/build/src/models/http-actions/HttpStep.js +30 -0
- package/build/src/models/http-actions/HttpStep.js.map +1 -0
- package/build/src/models/http-actions/LegacyTranslator.d.ts +8 -7
- package/build/src/models/http-actions/LegacyTranslator.js +18 -13
- package/build/src/models/http-actions/LegacyTranslator.js.map +1 -1
- package/build/src/models/http-actions/steps/assertion/EqualAssertion.d.ts +76 -0
- package/build/src/models/http-actions/steps/assertion/EqualAssertion.js +79 -0
- package/build/src/models/http-actions/steps/assertion/EqualAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/GreaterThanAssertion.d.ts +36 -0
- package/build/src/models/http-actions/steps/assertion/GreaterThanAssertion.js +59 -0
- package/build/src/models/http-actions/steps/assertion/GreaterThanAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/IncludesAssertion.d.ts +28 -0
- package/build/src/models/http-actions/steps/assertion/IncludesAssertion.js +45 -0
- package/build/src/models/http-actions/steps/assertion/IncludesAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/IsEmptyAssertion.d.ts +18 -0
- package/build/src/models/http-actions/steps/assertion/IsEmptyAssertion.js +29 -0
- package/build/src/models/http-actions/steps/assertion/IsEmptyAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/IsNotEmptyAssertion.d.ts +18 -0
- package/build/src/models/http-actions/steps/assertion/IsNotEmptyAssertion.js +29 -0
- package/build/src/models/http-actions/steps/assertion/IsNotEmptyAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/LengthOfAssertion.d.ts +28 -0
- package/build/src/models/http-actions/steps/assertion/LengthOfAssertion.js +45 -0
- package/build/src/models/http-actions/steps/assertion/LengthOfAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/LessThanAssertion.d.ts +36 -0
- package/build/src/models/http-actions/steps/assertion/LessThanAssertion.js +59 -0
- package/build/src/models/http-actions/steps/assertion/LessThanAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/MatchesAssertion.d.ts +28 -0
- package/build/src/models/http-actions/steps/assertion/MatchesAssertion.js +45 -0
- package/build/src/models/http-actions/steps/assertion/MatchesAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/MatchesSchemaAssertion.d.ts +36 -0
- package/build/src/models/http-actions/steps/assertion/MatchesSchemaAssertion.js +59 -0
- package/build/src/models/http-actions/steps/assertion/MatchesSchemaAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/NotEqualAssertion.d.ts +76 -0
- package/build/src/models/http-actions/steps/assertion/NotEqualAssertion.js +79 -0
- package/build/src/models/http-actions/steps/assertion/NotEqualAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/NotIncludesAssertion.d.ts +28 -0
- package/build/src/models/http-actions/steps/assertion/NotIncludesAssertion.js +45 -0
- package/build/src/models/http-actions/steps/assertion/NotIncludesAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/NotOkAssertion.d.ts +18 -0
- package/build/src/models/http-actions/steps/assertion/NotOkAssertion.js +29 -0
- package/build/src/models/http-actions/steps/assertion/NotOkAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/NotToBeAssertion.d.ts +29 -0
- package/build/src/models/http-actions/steps/assertion/NotToBeAssertion.js +45 -0
- package/build/src/models/http-actions/steps/assertion/NotToBeAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/OkAssertion.d.ts +18 -0
- package/build/src/models/http-actions/steps/assertion/OkAssertion.js +29 -0
- package/build/src/models/http-actions/steps/assertion/OkAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/ToBeAssertion.d.ts +35 -0
- package/build/src/models/http-actions/steps/assertion/ToBeAssertion.js +53 -0
- package/build/src/models/http-actions/steps/assertion/ToBeAssertion.js.map +1 -0
- package/build/src/models/http-actions/steps/assertion/index.d.ts +15 -0
- package/build/src/models/http-actions/steps/assertion/index.js +16 -0
- package/build/src/models/http-actions/steps/assertion/index.js.map +1 -0
- package/build/src/models/http-actions/steps/data/DeleteCookieStep.d.ts +44 -0
- package/build/src/models/http-actions/steps/data/DeleteCookieStep.js +67 -0
- package/build/src/models/http-actions/steps/data/DeleteCookieStep.js.map +1 -0
- package/build/src/models/http-actions/steps/data/ReadDataSourceStep.d.ts +53 -0
- package/build/src/models/http-actions/steps/data/ReadDataSourceStep.js +60 -0
- package/build/src/models/http-actions/steps/data/ReadDataSourceStep.js.map +1 -0
- package/build/src/models/http-actions/steps/data/ReadDataStep.d.ts +67 -0
- package/build/src/models/http-actions/steps/data/ReadDataStep.js +77 -0
- package/build/src/models/http-actions/steps/data/ReadDataStep.js.map +1 -0
- package/build/src/models/http-actions/steps/data/ReadValueStep.d.ts +45 -0
- package/build/src/models/http-actions/steps/data/ReadValueStep.js +52 -0
- package/build/src/models/http-actions/steps/data/ReadValueStep.js.map +1 -0
- package/build/src/models/http-actions/steps/data/SetCookieStep.d.ts +100 -0
- package/build/src/models/http-actions/steps/data/SetCookieStep.js +138 -0
- package/build/src/models/http-actions/steps/data/SetCookieStep.js.map +1 -0
- package/build/src/models/http-actions/steps/data/SetDataStep.d.ts +77 -0
- package/build/src/models/http-actions/steps/data/SetDataStep.js +69 -0
- package/build/src/models/http-actions/steps/data/SetDataStep.js.map +1 -0
- package/build/src/models/http-actions/steps/data/SetVariableStep.d.ts +40 -0
- package/build/src/models/http-actions/steps/data/SetVariableStep.js +44 -0
- package/build/src/models/http-actions/steps/data/SetVariableStep.js.map +1 -0
- package/build/src/models/http-actions/steps/data/index.d.ts +7 -0
- package/build/src/models/http-actions/steps/data/index.js +8 -0
- package/build/src/models/http-actions/steps/data/index.js.map +1 -0
- package/build/src/models/http-actions/steps/transformation/AsLowerCaseStep.d.ts +18 -0
- package/build/src/models/http-actions/steps/transformation/AsLowerCaseStep.js +29 -0
- package/build/src/models/http-actions/steps/transformation/AsLowerCaseStep.js.map +1 -0
- package/build/src/models/http-actions/steps/transformation/AsNumberStep.d.ts +18 -0
- package/build/src/models/http-actions/steps/transformation/AsNumberStep.js +29 -0
- package/build/src/models/http-actions/steps/transformation/AsNumberStep.js.map +1 -0
- package/build/src/models/http-actions/steps/transformation/AsUpperCaseStep.d.ts +18 -0
- package/build/src/models/http-actions/steps/transformation/AsUpperCaseStep.js +29 -0
- package/build/src/models/http-actions/steps/transformation/AsUpperCaseStep.js.map +1 -0
- package/build/src/models/http-actions/steps/transformation/RoundStep.d.ts +43 -0
- package/build/src/models/http-actions/steps/transformation/RoundStep.js +52 -0
- package/build/src/models/http-actions/steps/transformation/RoundStep.js.map +1 -0
- package/build/src/models/http-actions/steps/transformation/SubstringStep.d.ts +38 -0
- package/build/src/models/http-actions/steps/transformation/SubstringStep.js +65 -0
- package/build/src/models/http-actions/steps/transformation/SubstringStep.js.map +1 -0
- package/build/src/models/http-actions/steps/transformation/TrimStep.d.ts +20 -0
- package/build/src/models/http-actions/steps/transformation/TrimStep.js +30 -0
- package/build/src/models/http-actions/steps/transformation/TrimStep.js.map +1 -0
- package/build/src/models/http-actions/steps/transformation/index.d.ts +6 -0
- package/build/src/models/http-actions/steps/transformation/index.js +7 -0
- package/build/src/models/http-actions/steps/transformation/index.js.map +1 -0
- package/build/src/proxy/RequestProxy.d.ts +7 -2
- package/build/src/proxy/RequestProxy.js +4 -1
- package/build/src/proxy/RequestProxy.js.map +1 -1
- package/build/src/runtime/http-runner/ConditionCheck.d.ts +10 -10
- package/build/src/runtime/http-runner/ConditionCheck.js.map +1 -1
- package/build/src/runtime/http-runner/HttpAssertionRunner.d.ts +75 -0
- package/build/src/runtime/http-runner/HttpAssertionRunner.js +538 -0
- package/build/src/runtime/http-runner/HttpAssertionRunner.js.map +1 -0
- package/build/src/runtime/http-runner/HttpFlowRunner.d.ts +11 -6
- package/build/src/runtime/http-runner/HttpFlowRunner.js +24 -15
- package/build/src/runtime/http-runner/HttpFlowRunner.js.map +1 -1
- package/build/src/runtime/http-runner/HttpRequestRunner.d.ts +14 -3
- package/build/src/runtime/http-runner/HttpRequestRunner.js +44 -0
- package/build/src/runtime/http-runner/HttpRequestRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectParallelRunner.d.ts +1 -1
- package/build/src/runtime/node/ProjectParallelRunner.js +2 -2
- package/build/src/runtime/node/ProjectParallelRunner.js.map +1 -1
- package/build/src/runtime/node/ProjectRequestRunner.js +6 -2
- package/build/src/runtime/node/ProjectRequestRunner.js.map +1 -1
- package/package.json +3 -2
- package/src/data/{JmesparthReader.ts → JmespathReader.ts} +2 -2
- package/src/data/RequestDataExtractor.ts +5 -5
- package/src/data/XmlReader.ts +16 -2
- package/src/models/ClientCertificate.ts +9 -0
- package/src/models/Environment.ts +11 -7
- package/src/models/ErrorResponse.ts +1 -1
- package/src/models/HttpRequest.ts +4 -14
- package/src/models/HttpResponse.ts +5 -11
- package/src/models/ProjectRequest.ts +54 -0
- package/src/models/Request.ts +23 -4
- package/src/models/RequestAuthorization.ts +1 -1
- package/src/models/RequestLog.ts +21 -1
- package/src/models/SerializablePayload.ts +18 -1
- package/src/models/http-actions/AssertionError.ts +57 -0
- package/src/models/http-actions/HttpAssertion.ts +89 -0
- package/src/models/http-actions/HttpFlows.ts +115 -0
- package/src/models/http-actions/HttpStep.ts +50 -0
- package/src/models/http-actions/LegacyTranslator.ts +42 -30
- package/src/models/http-actions/steps/assertion/EqualAssertion.ts +130 -0
- package/src/models/http-actions/steps/assertion/GreaterThanAssertion.ts +87 -0
- package/src/models/http-actions/steps/assertion/IncludesAssertion.ts +68 -0
- package/src/models/http-actions/steps/assertion/IsEmptyAssertion.ts +41 -0
- package/src/models/http-actions/steps/assertion/IsNotEmptyAssertion.ts +41 -0
- package/src/models/http-actions/steps/assertion/LengthOfAssertion.ts +68 -0
- package/src/models/http-actions/steps/assertion/LessThanAssertion.ts +87 -0
- package/src/models/http-actions/steps/assertion/MatchesAssertion.ts +68 -0
- package/src/models/http-actions/steps/assertion/MatchesSchemaAssertion.ts +85 -0
- package/src/models/http-actions/steps/assertion/NotEqualAssertion.ts +130 -0
- package/src/models/http-actions/steps/assertion/NotIncludesAssertion.ts +68 -0
- package/src/models/http-actions/steps/assertion/NotOkAssertion.ts +41 -0
- package/src/models/http-actions/steps/assertion/NotToBeAssertion.ts +69 -0
- package/src/models/http-actions/steps/assertion/OkAssertion.ts +41 -0
- package/src/models/http-actions/steps/assertion/ToBeAssertion.ts +76 -0
- package/src/models/http-actions/steps/data/DeleteCookieStep.ts +102 -0
- package/src/models/http-actions/steps/data/ReadDataSourceStep.ts +103 -0
- package/src/models/http-actions/steps/data/ReadDataStep.ts +128 -0
- package/src/models/http-actions/steps/data/ReadValueStep.ts +88 -0
- package/src/models/http-actions/steps/data/SetCookieStep.ts +206 -0
- package/src/models/http-actions/steps/data/SetDataStep.ts +124 -0
- package/src/models/http-actions/steps/data/SetVariableStep.ts +82 -0
- package/src/models/http-actions/steps/transformation/AsLowerCaseStep.ts +41 -0
- package/src/models/http-actions/steps/transformation/AsNumberStep.ts +41 -0
- package/src/models/http-actions/steps/transformation/AsUpperCaseStep.ts +41 -0
- package/src/models/http-actions/steps/transformation/RoundStep.ts +86 -0
- package/src/models/http-actions/steps/transformation/SubstringStep.ts +93 -0
- package/src/models/http-actions/steps/transformation/TrimStep.ts +43 -0
- package/src/proxy/RequestProxy.ts +11 -3
- package/src/runtime/http-runner/ConditionCheck.ts +13 -14
- package/src/runtime/http-runner/HttpAssertionRunner.ts +540 -0
- package/src/runtime/http-runner/HttpFlowRunner.ts +33 -19
- package/src/runtime/http-runner/HttpRequestRunner.ts +53 -5
- package/src/runtime/node/ProjectParallelRunner.ts +4 -4
- package/src/runtime/node/ProjectRequestRunner.ts +6 -2
- package/build/src/data/JmesparthReader.js.map +0 -1
- package/build/src/models/http-actions/HttpActions.d.ts +0 -256
- package/build/src/models/http-actions/HttpActions.js +0 -46
- package/build/src/models/http-actions/HttpActions.js.map +0 -1
- package/src/models/http-actions/HttpActions.ts +0 -270
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
import { ActionOperatorEnum } from '../../models/http-actions/HttpActions.js';
|
|
1
|
+
import { AssertionEnum } from "../../models/http-actions/HttpAssertion";
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Checks if values equal.
|
|
@@ -7,7 +6,7 @@ import { ActionOperatorEnum } from '../../models/http-actions/HttpActions.js';
|
|
|
7
6
|
* @param condition Comparator value
|
|
8
7
|
* @returns True if objects matches.
|
|
9
8
|
*/
|
|
10
|
-
export function isEqual(value:
|
|
9
|
+
export function isEqual(value: unknown, condition: unknown): boolean {
|
|
11
10
|
if (value === condition || String(value) === String(condition)) {
|
|
12
11
|
return true;
|
|
13
12
|
}
|
|
@@ -34,7 +33,7 @@ export function isEqual(value: any, condition: any): boolean {
|
|
|
34
33
|
* @param condition Comparator value
|
|
35
34
|
* @return False if objects matches.
|
|
36
35
|
*/
|
|
37
|
-
export function isNotEqual(value:
|
|
36
|
+
export function isNotEqual(value: unknown, condition: unknown): boolean {
|
|
38
37
|
return !isEqual(value, condition);
|
|
39
38
|
}
|
|
40
39
|
|
|
@@ -45,7 +44,7 @@ export function isNotEqual(value: any, condition: any): boolean {
|
|
|
45
44
|
* @param condition Comparator value
|
|
46
45
|
* @returns True if value is less than condition.
|
|
47
46
|
*/
|
|
48
|
-
export function isLessThan(value:
|
|
47
|
+
export function isLessThan(value: unknown, condition: unknown): boolean {
|
|
49
48
|
const valueNumber = Number(value);
|
|
50
49
|
if (Number.isNaN(valueNumber)) {
|
|
51
50
|
return false;
|
|
@@ -64,7 +63,7 @@ export function isLessThan(value: any, condition: any): boolean {
|
|
|
64
63
|
* @param condition Comparator value
|
|
65
64
|
* @returns True if value is less than or equal to `condition`.
|
|
66
65
|
*/
|
|
67
|
-
export function isLessThanEqual(value:
|
|
66
|
+
export function isLessThanEqual(value: unknown, condition: unknown): boolean {
|
|
68
67
|
const valueNumber = Number(value);
|
|
69
68
|
if (Number.isNaN(valueNumber)) {
|
|
70
69
|
return false;
|
|
@@ -83,7 +82,7 @@ export function isLessThanEqual(value: any, condition: any): boolean {
|
|
|
83
82
|
* @param condition Comparator value
|
|
84
83
|
* @returns True if value is greater than `condition`.
|
|
85
84
|
*/
|
|
86
|
-
export function isGreaterThan(value:
|
|
85
|
+
export function isGreaterThan(value: unknown, condition: unknown): boolean {
|
|
87
86
|
const valueNumber = Number(value);
|
|
88
87
|
if (Number.isNaN(valueNumber)) {
|
|
89
88
|
return false;
|
|
@@ -102,7 +101,7 @@ export function isGreaterThan(value: any, condition: any): boolean {
|
|
|
102
101
|
* @param condition Comparator value
|
|
103
102
|
* @returns True if value is greater than or equal to `condition`.
|
|
104
103
|
*/
|
|
105
|
-
export function isGreaterThanEqual(value:
|
|
104
|
+
export function isGreaterThanEqual(value: unknown, condition: unknown): boolean {
|
|
106
105
|
const valueNumber = Number(value);
|
|
107
106
|
if (Number.isNaN(valueNumber)) {
|
|
108
107
|
return false;
|
|
@@ -122,12 +121,12 @@ export function isGreaterThanEqual(value: any, condition: any): boolean {
|
|
|
122
121
|
* @param condition Comparator value
|
|
123
122
|
* @returns True if value contains the `condition`.
|
|
124
123
|
*/
|
|
125
|
-
export function contains(value:
|
|
124
|
+
export function contains(value: unknown, condition: unknown): boolean {
|
|
126
125
|
if (!value) {
|
|
127
126
|
return false;
|
|
128
127
|
}
|
|
129
128
|
if (typeof value === 'string') {
|
|
130
|
-
return value.indexOf(condition) !== -1;
|
|
129
|
+
return value.indexOf(condition as string) !== -1;
|
|
131
130
|
}
|
|
132
131
|
if (Array.isArray(value)) {
|
|
133
132
|
if (!Number.isNaN(condition) && typeof condition !== 'number') {
|
|
@@ -141,7 +140,7 @@ export function contains(value: any, condition: any): boolean {
|
|
|
141
140
|
if (typeof value !== 'object') {
|
|
142
141
|
return false;
|
|
143
142
|
}
|
|
144
|
-
return condition in value;
|
|
143
|
+
return (condition as string) in value;
|
|
145
144
|
}
|
|
146
145
|
|
|
147
146
|
/**
|
|
@@ -151,10 +150,10 @@ export function contains(value: any, condition: any): boolean {
|
|
|
151
150
|
* @param condition Comparator value - regex string.
|
|
152
151
|
* @returns Value of calling `test()` function on string.
|
|
153
152
|
*/
|
|
154
|
-
export function isRegex(value:
|
|
153
|
+
export function isRegex(value: unknown, condition: unknown): boolean {
|
|
155
154
|
let re;
|
|
156
155
|
try {
|
|
157
|
-
re = new RegExp(condition, 'm');
|
|
156
|
+
re = new RegExp(condition as string, 'm');
|
|
158
157
|
} catch (e) {
|
|
159
158
|
return false;
|
|
160
159
|
}
|
|
@@ -170,7 +169,7 @@ export function isRegex(value: any, condition: any): boolean {
|
|
|
170
169
|
* @param condition Value to compare.
|
|
171
170
|
* @returns True if the condition is satisfied and false otherwise.
|
|
172
171
|
*/
|
|
173
|
-
export function checkCondition(value:
|
|
172
|
+
export function checkCondition(value: unknown, operator: AssertionEnum, condition: string | undefined): boolean {
|
|
174
173
|
switch (operator) {
|
|
175
174
|
case 'equal':
|
|
176
175
|
return isEqual(value, condition);
|
|
@@ -0,0 +1,540 @@
|
|
|
1
|
+
import { assert } from '@esm-bundle/chai';
|
|
2
|
+
import { HttpRequest } from "../../models/HttpRequest.js";
|
|
3
|
+
import { ISentRequest } from "../../models/SentRequest.js";
|
|
4
|
+
import { IResponse } from "../../models/Response.js";
|
|
5
|
+
import { ErrorResponse, IErrorResponse } from "../../models/ErrorResponse.js";
|
|
6
|
+
import { AssertionResult, IHttpAssertion } from "../../models/http-actions/HttpAssertion.js";
|
|
7
|
+
import { IHttpStep } from "../../models/http-actions/HttpStep.js";
|
|
8
|
+
import { FlowValue } from "./HttpFlowRunner.js";
|
|
9
|
+
import { FlowRequestDataEnum, FlowResponseDataEnum, FlowSourceEnum } from "../../models/http-actions/HttpFlows.js";
|
|
10
|
+
import { IReadDataSourceStep, ReadDataSourceStep, ReadDataSourceStepKind } from "../../models/http-actions/steps/data/ReadDataSourceStep.js";
|
|
11
|
+
import { IReadValueStep, ReadValueStep, ReadValueStepKind } from "../../models/http-actions/steps/data/ReadValueStep.js";
|
|
12
|
+
import * as DataUtils from '../../data/DataUtils.js';
|
|
13
|
+
import { HttpResponse } from "../../models/HttpResponse.js";
|
|
14
|
+
import { Headers } from '../../lib/headers/Headers.js';
|
|
15
|
+
import { DataReader } from "../../data/DataReader.js";
|
|
16
|
+
import { JmespathReader } from "../../data/JmespathReader.js";
|
|
17
|
+
import { XmlReader } from "../../data/XmlReader.js";
|
|
18
|
+
import { UrlEncodedReader } from "../../data/UrlEncodedReader.js";
|
|
19
|
+
import { AsLowerCaseStepKind } from "../../models/http-actions/steps/transformation/AsLowerCaseStep.js";
|
|
20
|
+
import { AsUpperCaseStepKind } from "../../models/http-actions/steps/transformation/AsUpperCaseStep.js";
|
|
21
|
+
import { AsNumberStepKind } from "../../models/http-actions/steps/transformation/AsNumberStep.js";
|
|
22
|
+
import { IRoundStep, RoundStepKind } from "../../models/http-actions/steps/transformation/RoundStep.js";
|
|
23
|
+
import { ISubstringStep, SubstringStepKind } from "../../models/http-actions/steps/transformation/SubstringStep.js";
|
|
24
|
+
import { TrimStepKind } from "../../models/http-actions/steps/transformation/TrimStep.js";
|
|
25
|
+
import { EqualAssertionKind, IEqualAssertion } from "../../models/http-actions/steps/assertion/EqualAssertion.js";
|
|
26
|
+
import { INotEqualAssertion, NotEqualAssertionKind } from "../../models/http-actions/steps/assertion/NotEqualAssertion.js";
|
|
27
|
+
import { ApiSchemaValues } from "../../amf/ApiSchemaValues.js";
|
|
28
|
+
import { AssertionError } from "../../models/http-actions/AssertionError.js";
|
|
29
|
+
import { GreaterThanAssertionKind, IGreaterThanAssertion } from "../../models/http-actions/steps/assertion/GreaterThanAssertion.js";
|
|
30
|
+
import { ILessThanAssertion, LessThanAssertionKind } from "../../models/http-actions/steps/assertion/LessThanAssertion.js";
|
|
31
|
+
import { IIncludesAssertion, IncludesAssertionKind } from "../../models/http-actions/steps/assertion/IncludesAssertion.js";
|
|
32
|
+
import { INotIncludesAssertion, NotIncludesAssertionKind } from "../../models/http-actions/steps/assertion/NotIncludesAssertion.js";
|
|
33
|
+
import { OkAssertionKind } from "../../models/http-actions/steps/assertion/OkAssertion.js";
|
|
34
|
+
import { NotOkAssertionKind } from "../../models/http-actions/steps/assertion/NotOkAssertion.js";
|
|
35
|
+
import { IToBeAssertion, ToBeAssertionKind, ToBeTypes } from '../../models/http-actions/steps/assertion/ToBeAssertion.js';
|
|
36
|
+
import { INotToBeAssertion, NotToBeAssertionKind } from '../../models/http-actions/steps/assertion/NotToBeAssertion.js';
|
|
37
|
+
import { IsEmptyAssertionKind } from '../../models/http-actions/steps/assertion/IsEmptyAssertion.js';
|
|
38
|
+
import { IsNotEmptyAssertionKind } from '../../models/http-actions/steps/assertion/IsNotEmptyAssertion.js';
|
|
39
|
+
import { ILengthOfAssertion, LengthOfAssertionKind } from '../../models/http-actions/steps/assertion/LengthOfAssertion.js';
|
|
40
|
+
|
|
41
|
+
interface IStepValue {
|
|
42
|
+
value: FlowValue;
|
|
43
|
+
type?: FlowRequestDataEnum | FlowResponseDataEnum;
|
|
44
|
+
bodyMime?: string;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* A class that perform assertions that have been defined on an HTTP request.
|
|
49
|
+
*/
|
|
50
|
+
export class HttpAssertionRunner {
|
|
51
|
+
report: AssertionResult[] = [];
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
*
|
|
55
|
+
* @param request The request object sent to the server
|
|
56
|
+
* @param response The generated response
|
|
57
|
+
* @param assertions The list of assertions to perform.
|
|
58
|
+
*/
|
|
59
|
+
async run(request: ISentRequest, response: IResponse | IErrorResponse, assertions: IHttpAssertion[]): Promise<AssertionResult[]> {
|
|
60
|
+
this.report = [];
|
|
61
|
+
if (!assertions || !assertions.length) {
|
|
62
|
+
return [...this.report];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
for (const assertion of assertions) {
|
|
66
|
+
await this.runAssertion(request, response, assertion);
|
|
67
|
+
}
|
|
68
|
+
return [...this.report];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
protected async runAssertion(request: ISentRequest, response: IResponse | IErrorResponse, assertion: IHttpAssertion): Promise<void> {
|
|
72
|
+
const { steps } = assertion;
|
|
73
|
+
|
|
74
|
+
// this keeps a value from the last step to be passed to the next step.
|
|
75
|
+
let lastResult: IStepValue = {
|
|
76
|
+
value: undefined,
|
|
77
|
+
};
|
|
78
|
+
let error: AssertionError | undefined;
|
|
79
|
+
for (const step of steps) {
|
|
80
|
+
try {
|
|
81
|
+
lastResult = await this.runStep(request, response, step, lastResult);
|
|
82
|
+
} catch (e) {
|
|
83
|
+
const typed = e as AssertionError;
|
|
84
|
+
if (typed.name === 'AssertionError') {
|
|
85
|
+
error = typed;
|
|
86
|
+
} else {
|
|
87
|
+
const err = e as Error;
|
|
88
|
+
error = new AssertionError({
|
|
89
|
+
message: err.message,
|
|
90
|
+
});
|
|
91
|
+
}
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
const description = assertion.description || this.createDescription(steps);
|
|
96
|
+
if (error) {
|
|
97
|
+
this.report.push({
|
|
98
|
+
ok: false,
|
|
99
|
+
description,
|
|
100
|
+
error: error.toJSON(),
|
|
101
|
+
});
|
|
102
|
+
} else {
|
|
103
|
+
this.report.push({
|
|
104
|
+
ok: true,
|
|
105
|
+
description,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
protected createDescription(steps: IHttpStep[]): string {
|
|
111
|
+
const parts: string[] = [];
|
|
112
|
+
for (const step of steps) {
|
|
113
|
+
switch (step.kind) {
|
|
114
|
+
case ReadDataSourceStepKind: parts.push(this.getDataSourceStepLabel(step as IReadDataSourceStep)); break;
|
|
115
|
+
case ReadValueStepKind: parts.push(this.getValueStepLabel(step as IReadValueStep)); break;
|
|
116
|
+
case AsLowerCaseStepKind: parts.push('To lower case'); break;
|
|
117
|
+
case AsUpperCaseStepKind: parts.push('To upper case'); break;
|
|
118
|
+
case AsNumberStepKind: parts.push('As number'); break;
|
|
119
|
+
case RoundStepKind: parts.push('Round'); break;
|
|
120
|
+
case TrimStepKind: parts.push('Trim'); break;
|
|
121
|
+
case SubstringStepKind: parts.push('Substring'); break;
|
|
122
|
+
case EqualAssertionKind: parts.push(`Equals to ${(step as IEqualAssertion).value}`); break;
|
|
123
|
+
case NotEqualAssertionKind: parts.push(`Not equals to ${(step as INotEqualAssertion).value}`); break;
|
|
124
|
+
case GreaterThanAssertionKind: parts.push(`Is greater than ${(step as IGreaterThanAssertion).value}`); break;
|
|
125
|
+
case LessThanAssertionKind: parts.push(`Is less than ${(step as ILessThanAssertion).value}`); break;
|
|
126
|
+
case IncludesAssertionKind: parts.push(`Includes ${(step as IIncludesAssertion).value}`); break;
|
|
127
|
+
case NotIncludesAssertionKind: parts.push(`Not includes ${(step as INotIncludesAssertion).value}`); break;
|
|
128
|
+
case OkAssertionKind: parts.push(`Is OK`); break;
|
|
129
|
+
case NotOkAssertionKind: parts.push(`Is not OK`); break;
|
|
130
|
+
default:
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
return parts.filter(i => !!i).join(' > ');
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
protected getDataSourceStepLabel(step: IReadDataSourceStep): string {
|
|
137
|
+
if (step.source === FlowSourceEnum.request) {
|
|
138
|
+
if (step.data === FlowRequestDataEnum.url) {
|
|
139
|
+
return 'Request URL';
|
|
140
|
+
}
|
|
141
|
+
if (step.data === FlowRequestDataEnum.headers) {
|
|
142
|
+
return 'Request headers';
|
|
143
|
+
}
|
|
144
|
+
if (step.data === FlowRequestDataEnum.method) {
|
|
145
|
+
return 'HTTP method';
|
|
146
|
+
}
|
|
147
|
+
if (step.data === FlowRequestDataEnum.body) {
|
|
148
|
+
return 'Request body';
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
if (step.source === FlowSourceEnum.response) {
|
|
152
|
+
if (step.data === FlowResponseDataEnum.url) {
|
|
153
|
+
return 'Response URL';
|
|
154
|
+
}
|
|
155
|
+
if (step.data === FlowResponseDataEnum.headers) {
|
|
156
|
+
return 'Response headers';
|
|
157
|
+
}
|
|
158
|
+
if (step.data === FlowResponseDataEnum.body) {
|
|
159
|
+
return 'Response body';
|
|
160
|
+
}
|
|
161
|
+
if (step.data === FlowResponseDataEnum.status) {
|
|
162
|
+
return 'Status code';
|
|
163
|
+
}
|
|
164
|
+
if (step.data === FlowResponseDataEnum.statusText) {
|
|
165
|
+
return 'Status message';
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
return 'Invalid step';
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
protected getValueStepLabel(step: IReadValueStep): string {
|
|
172
|
+
const { path } = step;
|
|
173
|
+
return path || '';
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
protected async runStep(request: ISentRequest, response: IResponse | IErrorResponse, step: IHttpStep, input: IStepValue): Promise<IStepValue> {
|
|
177
|
+
switch (step.kind) {
|
|
178
|
+
// data reading
|
|
179
|
+
case ReadDataSourceStepKind: return this.readDataSource(request, response, step);
|
|
180
|
+
case ReadValueStepKind: return this.readValue(input, step as IReadValueStep);
|
|
181
|
+
// transformations
|
|
182
|
+
case AsLowerCaseStepKind: return this.toLowerCase(input);
|
|
183
|
+
case AsUpperCaseStepKind: return this.toUpperCase(input);
|
|
184
|
+
case AsNumberStepKind: return this.asNumber(input);
|
|
185
|
+
case RoundStepKind: return this.round(input, step as IRoundStep);
|
|
186
|
+
case TrimStepKind: return this.trim(input);
|
|
187
|
+
case SubstringStepKind: return this.substring(input, step as ISubstringStep);
|
|
188
|
+
// assertions
|
|
189
|
+
case EqualAssertionKind: return this.assertEqual(input, step as IEqualAssertion);
|
|
190
|
+
case NotEqualAssertionKind: return this.assertNotEqual(input, step as INotEqualAssertion);
|
|
191
|
+
case GreaterThanAssertionKind: return this.assertGreaterThan(input, step as IGreaterThanAssertion);
|
|
192
|
+
case LessThanAssertionKind: return this.assertLessThan(input, step as ILessThanAssertion);
|
|
193
|
+
case IncludesAssertionKind: return this.assertIncludes(input, step as IIncludesAssertion);
|
|
194
|
+
case NotIncludesAssertionKind: return this.assertNotIncludes(input, step as INotIncludesAssertion);
|
|
195
|
+
case OkAssertionKind: return this.assertOk(input);
|
|
196
|
+
case NotOkAssertionKind: return this.assertNotOk(input);
|
|
197
|
+
case ToBeAssertionKind: return this.toBe(input, step as IToBeAssertion);
|
|
198
|
+
case NotToBeAssertionKind: return this.notToBe(input, step as INotToBeAssertion);
|
|
199
|
+
case IsEmptyAssertionKind: return this.isEmpty(input);
|
|
200
|
+
case IsNotEmptyAssertionKind: return this.isNotEmpty(input);
|
|
201
|
+
case LengthOfAssertionKind: return this.lengthOf(input, step as ILengthOfAssertion);
|
|
202
|
+
default: return { value: undefined };
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/**
|
|
207
|
+
* Produces the data source.
|
|
208
|
+
*/
|
|
209
|
+
protected async readDataSource(request: ISentRequest, response: IResponse | IErrorResponse, step: IReadDataSourceStep): Promise<IStepValue> {
|
|
210
|
+
const instance = new ReadDataSourceStep(step);
|
|
211
|
+
if (instance.enabled === false || !instance.checkValidity()) {
|
|
212
|
+
return { value: undefined };
|
|
213
|
+
}
|
|
214
|
+
const { source, data } = step;
|
|
215
|
+
if (source === FlowSourceEnum.request) {
|
|
216
|
+
if (data === FlowRequestDataEnum.url) {
|
|
217
|
+
return {
|
|
218
|
+
value: request.url,
|
|
219
|
+
type: data,
|
|
220
|
+
};
|
|
221
|
+
}
|
|
222
|
+
if (data === FlowRequestDataEnum.headers) {
|
|
223
|
+
return {
|
|
224
|
+
value: request.headers,
|
|
225
|
+
type: data,
|
|
226
|
+
};
|
|
227
|
+
}
|
|
228
|
+
if (data === FlowRequestDataEnum.method) {
|
|
229
|
+
return {
|
|
230
|
+
value: request.method,
|
|
231
|
+
type: data,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
if (data === FlowRequestDataEnum.body) {
|
|
235
|
+
const instance = new HttpRequest(request);
|
|
236
|
+
const value = await this.processBody(instance);
|
|
237
|
+
return {
|
|
238
|
+
...value,
|
|
239
|
+
type: data,
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
if (source === FlowSourceEnum.response) {
|
|
244
|
+
if (data === FlowResponseDataEnum.url) {
|
|
245
|
+
return {
|
|
246
|
+
value: request.url,
|
|
247
|
+
type: data,
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
if (data === FlowResponseDataEnum.headers) {
|
|
251
|
+
return {
|
|
252
|
+
value: response.headers,
|
|
253
|
+
type: data,
|
|
254
|
+
};
|
|
255
|
+
}
|
|
256
|
+
if (data === FlowResponseDataEnum.status) {
|
|
257
|
+
return {
|
|
258
|
+
value: response.status,
|
|
259
|
+
type: data,
|
|
260
|
+
};
|
|
261
|
+
}
|
|
262
|
+
if (data === FlowResponseDataEnum.statusText) {
|
|
263
|
+
return {
|
|
264
|
+
value: response.statusText,
|
|
265
|
+
type: data,
|
|
266
|
+
};
|
|
267
|
+
}
|
|
268
|
+
if (data === FlowResponseDataEnum.body) {
|
|
269
|
+
let instance: ErrorResponse | HttpResponse;
|
|
270
|
+
if (ErrorResponse.isErrorResponse(response)) {
|
|
271
|
+
instance = new ErrorResponse(response as IErrorResponse);
|
|
272
|
+
} else {
|
|
273
|
+
instance = new HttpResponse(response);
|
|
274
|
+
}
|
|
275
|
+
const value = await this.processBody(instance);
|
|
276
|
+
return {
|
|
277
|
+
...value,
|
|
278
|
+
type: data,
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
return { value: undefined };
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
protected async processBody(input: HttpRequest | HttpResponse | ErrorResponse): Promise<IStepValue> {
|
|
286
|
+
const { headers } = input;
|
|
287
|
+
if (!headers) {
|
|
288
|
+
return { value: undefined };
|
|
289
|
+
}
|
|
290
|
+
const body = await input.readPayloadAsString();
|
|
291
|
+
if (!body) {
|
|
292
|
+
return { value: undefined };
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
const parser = new Headers(headers);
|
|
296
|
+
const mime = parser.get('content-type');
|
|
297
|
+
if (!mime) {
|
|
298
|
+
return { value: undefined };
|
|
299
|
+
}
|
|
300
|
+
return {
|
|
301
|
+
value: body,
|
|
302
|
+
bodyMime: mime,
|
|
303
|
+
}
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* Produces the value from the current input.
|
|
308
|
+
*/
|
|
309
|
+
protected async readValue(input: IStepValue, step: IReadValueStep): Promise<IStepValue> {
|
|
310
|
+
const instance = new ReadValueStep(step);
|
|
311
|
+
if (instance.enabled === false || !instance.checkValidity() || input.value === undefined || input.value === null) {
|
|
312
|
+
return { value: undefined };
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
const { path } = step;
|
|
316
|
+
const { type, value } = input;
|
|
317
|
+
const args = path ? path.split('.') : [];
|
|
318
|
+
if (type === FlowRequestDataEnum.url || type === FlowResponseDataEnum.url) {
|
|
319
|
+
if (!value) {
|
|
320
|
+
return { value: undefined };
|
|
321
|
+
}
|
|
322
|
+
const v = String(input.value);
|
|
323
|
+
return {
|
|
324
|
+
value: DataUtils.getDataUrl(v, args),
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
if (type === FlowRequestDataEnum.headers || type === FlowResponseDataEnum.headers) {
|
|
328
|
+
if (!value) {
|
|
329
|
+
return { value: undefined };
|
|
330
|
+
}
|
|
331
|
+
const v = String(input.value);
|
|
332
|
+
return {
|
|
333
|
+
value: DataUtils.getDataHeaders(v, args),
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
if (type === FlowRequestDataEnum.body || type === FlowResponseDataEnum.body) {
|
|
337
|
+
if (!input.bodyMime || !path) {
|
|
338
|
+
return { value: undefined };
|
|
339
|
+
}
|
|
340
|
+
let reader: DataReader | undefined;
|
|
341
|
+
if (input.bodyMime.includes('json')) {
|
|
342
|
+
reader = new JmespathReader();
|
|
343
|
+
} else if (input.bodyMime.includes('xml')) {
|
|
344
|
+
reader = new XmlReader();
|
|
345
|
+
} else if (input.bodyMime.includes('x-www-form-urlencoded')) {
|
|
346
|
+
reader = new UrlEncodedReader();
|
|
347
|
+
}
|
|
348
|
+
if (!reader) {
|
|
349
|
+
return { value: undefined };
|
|
350
|
+
}
|
|
351
|
+
await reader.writePayload(String(value));
|
|
352
|
+
const readValue = await reader.getValue(path);
|
|
353
|
+
return {
|
|
354
|
+
value: readValue,
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
if (type === FlowResponseDataEnum.status) {
|
|
358
|
+
const v = Number(input.value);
|
|
359
|
+
if (Number.isNaN(v)) {
|
|
360
|
+
return { value: undefined };
|
|
361
|
+
}
|
|
362
|
+
return {
|
|
363
|
+
value: v,
|
|
364
|
+
}
|
|
365
|
+
}
|
|
366
|
+
|
|
367
|
+
if (type === FlowResponseDataEnum.statusText) {
|
|
368
|
+
if (!value) {
|
|
369
|
+
return { value: undefined };
|
|
370
|
+
}
|
|
371
|
+
return {
|
|
372
|
+
value,
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
return { value: undefined };
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
protected async toLowerCase(input: IStepValue): Promise<IStepValue> {
|
|
379
|
+
if (input.value === null || input.value === undefined) {
|
|
380
|
+
return { value: undefined };
|
|
381
|
+
}
|
|
382
|
+
const value = String(input.value);
|
|
383
|
+
return { value: value.toLowerCase() };
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
protected async toUpperCase(input: IStepValue): Promise<IStepValue> {
|
|
387
|
+
if (input.value === null || input.value === undefined) {
|
|
388
|
+
return { value: undefined };
|
|
389
|
+
}
|
|
390
|
+
const value = String(input.value);
|
|
391
|
+
return { value: value.toUpperCase() };
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
protected async asNumber(input: IStepValue): Promise<IStepValue> {
|
|
395
|
+
if (input.value === null || input.value === undefined) {
|
|
396
|
+
return { value: undefined };
|
|
397
|
+
}
|
|
398
|
+
const value = String(input.value);
|
|
399
|
+
const parsed = Number(value);
|
|
400
|
+
if (Number.isNaN(parsed)) {
|
|
401
|
+
return { value: undefined };
|
|
402
|
+
}
|
|
403
|
+
return { value: parsed };
|
|
404
|
+
}
|
|
405
|
+
|
|
406
|
+
protected async round(input: IStepValue, step: IRoundStep): Promise<IStepValue> {
|
|
407
|
+
if (input.value === null || input.value === undefined) {
|
|
408
|
+
return { value: undefined };
|
|
409
|
+
}
|
|
410
|
+
const value = String(input.value);
|
|
411
|
+
const parsed = typeof input.value === 'number' ? input.value : Number(value);
|
|
412
|
+
if (Number.isNaN(parsed)) {
|
|
413
|
+
return { value: undefined };
|
|
414
|
+
}
|
|
415
|
+
return { value: parsed.toFixed(step.precision) };
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
protected async trim(input: IStepValue): Promise<IStepValue> {
|
|
419
|
+
if (input.value === null || input.value === undefined) {
|
|
420
|
+
return { value: undefined };
|
|
421
|
+
}
|
|
422
|
+
const value = String(input.value);
|
|
423
|
+
return { ...input, value: value.trim() };
|
|
424
|
+
}
|
|
425
|
+
|
|
426
|
+
protected async substring(input: IStepValue, step: ISubstringStep): Promise<IStepValue> {
|
|
427
|
+
if (input.value === null || input.value === undefined) {
|
|
428
|
+
return { value: undefined };
|
|
429
|
+
}
|
|
430
|
+
if (typeof step.start !== 'number') {
|
|
431
|
+
return input;
|
|
432
|
+
}
|
|
433
|
+
const value = String(input.value);
|
|
434
|
+
return { ...input, value: value.substring(step.start, step.end) };
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
protected async assertEqual(input: IStepValue, step: IEqualAssertion): Promise<IStepValue> {
|
|
438
|
+
const { value } = input;
|
|
439
|
+
if (step.strict) {
|
|
440
|
+
const comparator = ApiSchemaValues.readTypedValue(step.value, step.dataType);
|
|
441
|
+
assert.strictEqual(value, comparator);
|
|
442
|
+
} else {
|
|
443
|
+
assert.equal(String(value), step.value);
|
|
444
|
+
}
|
|
445
|
+
return input;
|
|
446
|
+
}
|
|
447
|
+
|
|
448
|
+
protected async assertNotEqual(input: IStepValue, step: INotEqualAssertion): Promise<IStepValue> {
|
|
449
|
+
const { value } = input;
|
|
450
|
+
if (step.strict) {
|
|
451
|
+
const comparator = ApiSchemaValues.readTypedValue(step.value, step.dataType);
|
|
452
|
+
assert.notStrictEqual(value, comparator);
|
|
453
|
+
} else {
|
|
454
|
+
assert.notEqual(value, step.value);
|
|
455
|
+
}
|
|
456
|
+
return input;
|
|
457
|
+
}
|
|
458
|
+
|
|
459
|
+
protected async assertGreaterThan(input: IStepValue, step: IGreaterThanAssertion): Promise<IStepValue> {
|
|
460
|
+
assert.typeOf(input.value, 'number');
|
|
461
|
+
const value = input.value as number;
|
|
462
|
+
if (step.equal) {
|
|
463
|
+
assert.isAtLeast(value as number, step.value as number);
|
|
464
|
+
} else {
|
|
465
|
+
assert.isAbove(value as number, step.value as number);
|
|
466
|
+
}
|
|
467
|
+
return input;
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
protected async assertLessThan(input: IStepValue, step: ILessThanAssertion): Promise<IStepValue> {
|
|
471
|
+
assert.typeOf(input.value, 'number');
|
|
472
|
+
const value = input.value as number;
|
|
473
|
+
if (step.equal) {
|
|
474
|
+
assert.isAtMost(value, step.value as number);
|
|
475
|
+
} else {
|
|
476
|
+
assert.isBelow(value, step.value as number);
|
|
477
|
+
}
|
|
478
|
+
return input;
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
protected async assertIncludes(input: IStepValue, step: IIncludesAssertion): Promise<IStepValue> {
|
|
482
|
+
if (this.isPrimitive(input.value)) {
|
|
483
|
+
assert.include(String(input.value), String(step.value));
|
|
484
|
+
} else {
|
|
485
|
+
assert.include(JSON.stringify(input.value), String(step.value));
|
|
486
|
+
}
|
|
487
|
+
return input;
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
protected async assertNotIncludes(input: IStepValue, step: INotIncludesAssertion): Promise<IStepValue> {
|
|
491
|
+
if (this.isPrimitive(input.value)) {
|
|
492
|
+
assert.notInclude(String(input.value), String(step.value));
|
|
493
|
+
} else {
|
|
494
|
+
assert.notInclude(JSON.stringify(input.value), String(step.value));
|
|
495
|
+
}
|
|
496
|
+
return input;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
protected async assertOk(input: IStepValue): Promise<IStepValue> {
|
|
500
|
+
assert.ok(input.value);
|
|
501
|
+
return input;
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
protected async assertNotOk(input: IStepValue): Promise<IStepValue> {
|
|
505
|
+
assert.notOk(input.value);
|
|
506
|
+
return input;
|
|
507
|
+
}
|
|
508
|
+
|
|
509
|
+
protected async toBe(input: IStepValue, step: IToBeAssertion): Promise<IStepValue> {
|
|
510
|
+
assert.typeOf(input.value, step.value as string);
|
|
511
|
+
return input;
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
protected async notToBe(input: IStepValue, step: INotToBeAssertion): Promise<IStepValue> {
|
|
515
|
+
if (Array.isArray(input.value) && step.value === ToBeTypes.object) {
|
|
516
|
+
assert(false, 'expected [Array] to be an object');
|
|
517
|
+
}
|
|
518
|
+
assert.notTypeOf(input.value, step.value as string);
|
|
519
|
+
return input;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
protected async isEmpty(input: IStepValue): Promise<IStepValue> {
|
|
523
|
+
assert.isEmpty(input.value);
|
|
524
|
+
return input;
|
|
525
|
+
}
|
|
526
|
+
|
|
527
|
+
protected async isNotEmpty(input: IStepValue): Promise<IStepValue> {
|
|
528
|
+
assert.isNotEmpty(input.value);
|
|
529
|
+
return input;
|
|
530
|
+
}
|
|
531
|
+
|
|
532
|
+
protected async lengthOf(input: IStepValue, step: ILengthOfAssertion): Promise<IStepValue> {
|
|
533
|
+
assert.lengthOf(input.value as unknown[], step.value as number);
|
|
534
|
+
return input;
|
|
535
|
+
}
|
|
536
|
+
|
|
537
|
+
protected isPrimitive(value: unknown): boolean {
|
|
538
|
+
return (typeof value !== 'object' && typeof value !== 'function') || value === null;
|
|
539
|
+
}
|
|
540
|
+
}
|