@@ -6,13 +6,13 @@ import { updateRequestParams } from './overwrites';
6
6
import { sendRequestToRelay } from './utils' ;
7
7
import { checkResponseFormat , findSchema , isResponseValid } from './validations' ;
8
8
9
+ /**
10
+ * Splits a given input string into distinct segments representing the request, the response, and optional wildcard fields.
11
+ *
12
+ * @param {string } content - The input string to be segmented.
13
+ * @returns {{ request: string, response: string, wildcards: string[] } } - An object containing the separated request, response strings, and wildcard fields.
14
+ */
9
15
export function splitReqAndRes ( content : string ) {
10
- /**
11
- * Splits a given input string into distinct segments representing the request, the response, and optional wildcard fields.
12
- *
13
- * @param {string } content - The input string to be segmented.
14
- * @returns {{ request: string, response: string, wildcards: string[] } } - An object containing the separated request, response strings, and wildcard fields.
15
- */
16
16
const lines = content
17
17
. split ( '\n' )
18
18
. map ( ( line : string ) => line . trim ( ) )
@@ -44,15 +44,26 @@ export function splitReqAndRes(content: string) {
44
44
} ;
45
45
}
46
46
47
+ /**
48
+ * Processes file content for API testing by executing requests against a relay server
49
+ * and validating the responses according to various validation strategies.
50
+ *
51
+ * @param {string } relayUrl - The URL of the relay server to send requests to
52
+ * @param {string } directory - The directory path used for schema lookup
53
+ * @param {string } file - The name of the file being processed (used for logging)
54
+ * @param {FileContent } content - The file content object containing request, response, and wildcards
55
+ * @returns {Promise<void> } A promise that resolves when processing is complete
56
+ *
57
+ * @description
58
+ * This function performs the following operations:
59
+ * 1. Updates request parameters based on the file context
60
+ * 2. Sends the modified request to the relay server
61
+ * 3. Validates the response using one of three strategies:
62
+ * - Error response validation (expects validation to fail)
63
+ * - Schema validation (when schema exists and no wildcards)
64
+ * - Response format validation (key-by-key comparison with wildcards support)
65
+ */
47
66
export async function processFileContent ( relayUrl : string , directory : string , file : string , content : FileContent ) {
48
- /**
49
- * Processes a file from the execution apis repo
50
- * containing test request and response data.
51
- *
52
- * @param {string } file - The name of the file being processed.
53
- * @param {Object } content - The content of the file, consisting of request and response data.
54
- * @returns {Array<string> } - An array of missing keys in the response data.
55
- */
56
67
console . log ( 'Executing for ' , file ) ;
57
68
console . log ( 'Original request:' , content . request ) ;
58
69
const modifiedRequest = await updateRequestParams ( file , JSON . parse ( content . request ) ) ;
0 commit comments