@@ -55,7 +55,7 @@ export function hasResponseFormatIssues(
55
55
actualResponse : Record < string , unknown > | ErrorResponse | JsonRpcResponse ,
56
56
expectedResponse : Record < string , unknown > | string | ErrorResponse ,
57
57
wildcards : string [ ] = [ ] ,
58
- ) {
58
+ ) : boolean {
59
59
let parsedExpectedResponse : Record < string , unknown > | ErrorResponse = expectedResponse as Record < string , unknown > ;
60
60
if ( typeof expectedResponse === 'string' ) {
61
61
try {
@@ -90,13 +90,17 @@ export function hasResponseFormatIssues(
90
90
return true ;
91
91
}
92
92
93
- return areValuesMatching ( actualResponse , parsedExpectedResponse , wildcards ) ;
93
+ return hasValuesMismatch ( actualResponse , parsedExpectedResponse , wildcards ) ;
94
94
}
95
95
96
96
/**
97
- * Checks if the actual response has the required error properties
97
+ * Checks if the actual response is missing required error properties
98
+ *
99
+ * @param actual - The actual response to check
100
+ * @param expected - The expected error response
101
+ * @returns {boolean } - Returns true if error properties are missing or mismatched, false if all required properties exist
98
102
*/
99
- function checkErrorResponse ( actual : Record < string , unknown > , expected : ErrorResponse ) : boolean {
103
+ function hasErrorResponseMismatch ( actual : Record < string , unknown > , expected : ErrorResponse ) : boolean {
100
104
if ( ! actual || typeof actual !== 'object' || ! actual . error ) {
101
105
return true ;
102
106
}
@@ -115,24 +119,36 @@ function arePrimitivesDifferent(actual: unknown, expected: unknown): boolean {
115
119
116
120
/**
117
121
* Checks if two arrays have different values
122
+ *
123
+ * @param actual - The actual array from the response
124
+ * @param expected - The expected array to compare against
125
+ * @param wildcards - Array of property paths to ignore during comparison
126
+ * @param path - Current property path being evaluated
127
+ * @returns {boolean } - Returns true if arrays have different values, false if they match
118
128
*/
119
- function checkArrayValues ( actual : unknown [ ] , expected : unknown [ ] , wildcards : string [ ] , path : string ) : boolean {
129
+ function hasArrayValuesMismatch ( actual : unknown [ ] , expected : unknown [ ] , wildcards : string [ ] , path : string ) : boolean {
120
130
if ( actual . length !== expected . length ) {
121
131
return true ;
122
132
}
123
133
124
134
for ( let i = 0 ; i < expected . length ; i ++ ) {
125
- if ( areValuesMatching ( actual [ i ] , expected [ i ] , wildcards , `${ path } [${ i } ]` ) ) {
135
+ if ( hasValuesMismatch ( actual [ i ] , expected [ i ] , wildcards , `${ path } [${ i } ]` ) ) {
126
136
return true ;
127
137
}
128
138
}
129
139
return false ;
130
140
}
131
141
132
142
/**
133
- * Checks if an object has all the required properties with matching values
143
+ * Checks if an object is missing required properties or has mismatched values
144
+ *
145
+ * @param actual - The actual object from the response
146
+ * @param expected - The expected object to compare against
147
+ * @param wildcards - Array of property paths to ignore during comparison
148
+ * @param path - Current property path being evaluated
149
+ * @returns {boolean } - Returns true if properties are missing or values are mismatched, false if all match
134
150
*/
135
- function checkObjectProperties (
151
+ function hasObjectPropertiesMismatch (
136
152
actual : Record < string , unknown > ,
137
153
expected : Record < string , unknown > ,
138
154
wildcards : string [ ] ,
@@ -146,14 +162,23 @@ function checkObjectProperties(
146
162
if ( ! ( key in actual ) ) {
147
163
return true ;
148
164
}
149
- if ( areValuesMatching ( actual [ key ] , expected [ key ] , wildcards , newPath ) ) {
165
+ if ( hasValuesMismatch ( actual [ key ] , expected [ key ] , wildcards , newPath ) ) {
150
166
return true ;
151
167
}
152
168
}
153
169
return false ;
154
170
}
155
171
156
- function checkComplexTypes ( actual : object | null , expected : object , wildcards : string [ ] , path : string ) : boolean {
172
+ /**
173
+ * Checks if complex types (objects or arrays) have mismatches in their structure or values
174
+ *
175
+ * @param actual - The actual object/array from the response
176
+ * @param expected - The expected object/array to compare against
177
+ * @param wildcards - Array of property paths to ignore during comparison
178
+ * @param path - Current property path being evaluated
179
+ * @returns {boolean } - Returns true if mismatches are found, false if values match
180
+ */
181
+ function hasComplexTypeMismatch ( actual : object | null , expected : object , wildcards : string [ ] , path : string ) : boolean {
157
182
if ( actual === null ) {
158
183
return true ;
159
184
}
@@ -166,10 +191,15 @@ function checkComplexTypes(actual: object | null, expected: object, wildcards: s
166
191
}
167
192
168
193
if ( isExpectedArray ) {
169
- return checkArrayValues ( actual as unknown [ ] , expected as unknown [ ] , wildcards , path ) ;
194
+ return hasArrayValuesMismatch ( actual as unknown [ ] , expected as unknown [ ] , wildcards , path ) ;
170
195
}
171
196
172
- return checkObjectProperties ( actual as Record < string , unknown > , expected as Record < string , unknown > , wildcards , path ) ;
197
+ return hasObjectPropertiesMismatch (
198
+ actual as Record < string , unknown > ,
199
+ expected as Record < string , unknown > ,
200
+ wildcards ,
201
+ path ,
202
+ ) ;
173
203
}
174
204
175
205
/**
@@ -186,12 +216,12 @@ function checkComplexTypes(actual: object | null, expected: object, wildcards: s
186
216
* - Error responses: Validates error structure when expected response contains an error property
187
217
* - Null/undefined values: Handles null checks appropriately
188
218
* - Type mismatches: Returns true (different) when types don't match
189
- * - Complex objects: Delegates to checkComplexTypes for arrays and objects
219
+ * - Complex objects: Delegates to hasComplexTypeMismatch for arrays and objects
190
220
* - Primitive values: Uses direct comparison for primitive types
191
221
*/
192
- function areValuesMatching ( actual : unknown , expected : unknown , wildcards : string [ ] , path = '' ) : boolean {
222
+ function hasValuesMismatch ( actual : unknown , expected : unknown , wildcards : string [ ] , path = '' ) : boolean {
193
223
if ( path === '' && expected && typeof expected === 'object' && ( expected as ErrorResponse ) . error ) {
194
- return checkErrorResponse ( actual as Record < string , unknown > , expected as ErrorResponse ) ;
224
+ return hasErrorResponseMismatch ( actual as Record < string , unknown > , expected as ErrorResponse ) ;
195
225
}
196
226
197
227
if ( expected == null ) {
@@ -203,7 +233,7 @@ function areValuesMatching(actual: unknown, expected: unknown, wildcards: string
203
233
}
204
234
205
235
if ( typeof expected === 'object' ) {
206
- return checkComplexTypes ( actual as object | null , expected , wildcards , path ) ;
236
+ return hasComplexTypeMismatch ( actual as object | null , expected , wildcards , path ) ;
207
237
}
208
238
209
239
return arePrimitivesDifferent ( actual , expected ) ;
0 commit comments