fix: test scripts response respects the old api and the new structure
This commit is contained in:
@@ -4,7 +4,9 @@ import getEnvironmentVariablesFromScript from "./preRequest"
|
||||
import { getEffectiveRESTRequest } from "./utils/EffectiveURL"
|
||||
import { HoppRESTResponse } from "./types/HoppRESTResponse"
|
||||
import { createRESTNetworkRequestStream } from "./network"
|
||||
import runTestScriptWithVariables from "./postwomanTesting"
|
||||
import runTestScriptWithVariables, {
|
||||
transformResponseForTesting,
|
||||
} from "./postwomanTesting"
|
||||
import { HoppTestData, HoppTestResult } from "./types/HoppTestResult"
|
||||
import { getRESTRequest, setRESTTestResults } from "~/newstore/RESTSession"
|
||||
|
||||
@@ -50,7 +52,7 @@ export function runRESTRequest$(): Observable<HoppRESTResponse> {
|
||||
>
|
||||
errors: [] // ¯\_(ツ)_/¯
|
||||
} = runTestScriptWithVariables(effectiveRequest.testScript, {
|
||||
response: res,
|
||||
response: transformResponseForTesting(res),
|
||||
}) as any
|
||||
|
||||
setRESTTestResults(translateToNewTestResults(testReport))
|
||||
|
||||
@@ -6,8 +6,16 @@ const styles = {
|
||||
ERROR: { icon: "close", class: "cl-error-response" },
|
||||
}
|
||||
|
||||
type TestScriptResponse = {
|
||||
body: any
|
||||
headers: any[]
|
||||
status: number
|
||||
|
||||
__newRes: HoppRESTResponse
|
||||
}
|
||||
|
||||
type TestScriptVariables = {
|
||||
response: HoppRESTResponse
|
||||
response: TestScriptResponse
|
||||
}
|
||||
|
||||
type TestReportStartBlock = {
|
||||
@@ -284,3 +292,30 @@ class Expectation {
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export function transformResponseForTesting(
|
||||
response: HoppRESTResponse
|
||||
): TestScriptResponse {
|
||||
if (response.type === "loading") {
|
||||
throw new Error("Cannot transform loading responses")
|
||||
}
|
||||
|
||||
if (response.type === "network_fail") {
|
||||
throw new Error("Cannot transform failed responses")
|
||||
}
|
||||
|
||||
let body: any = new TextDecoder("utf-8").decode(response.body)
|
||||
|
||||
// Try parsing to JSON
|
||||
try {
|
||||
body = JSON.parse(body)
|
||||
} catch (_) {}
|
||||
|
||||
return {
|
||||
body,
|
||||
headers: response.headers,
|
||||
status: response.statusCode,
|
||||
|
||||
__newRes: response,
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user