From ad968a6d176ea67d775bb4a27635965185fb605d Mon Sep 17 00:00:00 2001 From: Maksym Moshniaha Date: Fri, 3 Oct 2025 16:46:51 +0300 Subject: [PATCH] WAT-4939: Enable 302 status code verification in test framework --- core/types/package.json | 33 ++++++------- core/types/src/http-api/structs.ts | 12 ++--- package-lock.json | 15 +++++- packages/http-api/package.json | 57 ++++++++++++----------- packages/http-api/src/request-function.ts | 12 ++--- 5 files changed, 66 insertions(+), 63 deletions(-) diff --git a/core/types/package.json b/core/types/package.json index 661e52c22..bfa781b23 100644 --- a/core/types/package.json +++ b/core/types/package.json @@ -1,18 +1,19 @@ { - "name": "@testring/types", - "version": "0.8.2", - "main": "./dist/index.js", - "types": "./src/index.ts", - "repository": { - "type": "git", - "url": "https://github.com/ringcentral/testring.git" - }, - "scripts": { - "build": "tsc -p tsconfig.build.json" - }, - "author": "RingCentral", - "license": "MIT", - "dependencies": { - "@types/node": "22.8.5" - } + "name": "@testring/types", + "version": "0.8.2", + "main": "./dist/index.js", + "types": "./src/index.ts", + "repository": { + "type": "git", + "url": "https://github.com/ringcentral/testring.git" + }, + "scripts": { + "build": "tsc -p tsconfig.build.json" + }, + "author": "RingCentral", + "license": "MIT", + "dependencies": { + "@types/node": "22.8.5", + "@types/request-promise-native": "1.0.21" + } } diff --git a/core/types/src/http-api/structs.ts b/core/types/src/http-api/structs.ts index f69d73d31..efc83df43 100644 --- a/core/types/src/http-api/structs.ts +++ b/core/types/src/http-api/structs.ts @@ -1,3 +1,5 @@ +import {RequestPromiseOptions} from 'request-promise-native'; + interface IHttpHeaders { [key: string]: any; } @@ -14,18 +16,10 @@ export interface IHttpResponse { cookies: Array; } -export interface IHttpRequest { +export interface IHttpRequest extends RequestPromiseOptions { url: string; - method?: 'POST' | 'GET' | 'PUT' | 'DELETE'; - body?: any; - timeout?: number; - json?: any; - headers?: IHttpHeaders; query?: IHttpQueryParameters; cookies?: Array; - simple?: boolean; - resolveWithFullResponse?: boolean; - gzip?: boolean; } export interface IHttpRequestMessage { diff --git a/package-lock.json b/package-lock.json index 15770436c..fc5ce1ceb 100644 --- a/package-lock.json +++ b/package-lock.json @@ -286,7 +286,8 @@ "version": "0.8.2", "license": "MIT", "dependencies": { - "@types/node": "22.8.5" + "@types/node": "22.8.5", + "@types/request-promise-native": "1.0.21" } }, "core/utils": { @@ -5484,6 +5485,13 @@ "dev": true, "license": "MIT" }, + "node_modules/@types/lodash": { + "version": "4.17.20", + "resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.20.tgz", + "integrity": "sha512-H3MHACvFUEiujabxhaI/ImO6gUrd8oOurg7LQtS7mbwIXA/cUqWrvBsaeJ23aZEPk1TAYkurjfMbSELfoCXlGA==", + "dev": true, + "license": "MIT" + }, "node_modules/@types/mime": { "version": "1.3.5", "resolved": "https://registry.npmjs.org/@types/mime/-/mime-1.3.5.tgz", @@ -25446,11 +25454,14 @@ "@testring/types": "0.8.2", "@testring/utils": "0.8.2", "@types/node": "22.8.5", - "@types/request-promise-native": "1.0.21", "@types/tough-cookie": "4.0.5", + "lodash": "4.17.21", "request": "2.88.2", "request-promise-native": "1.0.9", "tough-cookie": "4.1.4" + }, + "devDependencies": { + "@types/lodash": "4.17.20" } }, "packages/plugin-babel": { diff --git a/packages/http-api/package.json b/packages/http-api/package.json index 9f360f395..1cae86c99 100644 --- a/packages/http-api/package.json +++ b/packages/http-api/package.json @@ -1,29 +1,32 @@ { - "name": "@testring/http-api", - "version": "0.8.2", - "main": "./dist/index.js", - "types": "./src/index.ts", - "repository": { - "type": "git", - "url": "https://github.com/ringcentral/testring.git" - }, - "scripts": { - "build": "tsc -p tsconfig.build.json" - }, - "author": "RingCentral", - "license": "MIT", - "dependencies": { - "@testring/logger": "0.8.2", - "@testring/pluggable-module": "0.8.2", - "@testring/test-utils": "0.8.2", - "@testring/transport": "0.8.2", - "@testring/types": "0.8.2", - "@testring/utils": "0.8.2", - "@types/node": "22.8.5", - "@types/request-promise-native": "1.0.21", - "@types/tough-cookie": "4.0.5", - "request": "2.88.2", - "request-promise-native": "1.0.9", - "tough-cookie": "4.1.4" - } + "name": "@testring/http-api", + "version": "0.8.2", + "main": "./dist/index.js", + "types": "./src/index.ts", + "repository": { + "type": "git", + "url": "https://github.com/ringcentral/testring.git" + }, + "scripts": { + "build": "tsc -p tsconfig.build.json" + }, + "author": "RingCentral", + "license": "MIT", + "dependencies": { + "@testring/logger": "0.8.2", + "@testring/pluggable-module": "0.8.2", + "@testring/test-utils": "0.8.2", + "@testring/transport": "0.8.2", + "@testring/types": "0.8.2", + "@testring/utils": "0.8.2", + "@types/node": "22.8.5", + "@types/tough-cookie": "4.0.5", + "lodash": "4.17.21", + "request": "2.88.2", + "request-promise-native": "1.0.9", + "tough-cookie": "4.1.4" + }, + "devDependencies": { + "@types/lodash": "4.17.20" + } } diff --git a/packages/http-api/src/request-function.ts b/packages/http-api/src/request-function.ts index f85a99296..122bbd228 100644 --- a/packages/http-api/src/request-function.ts +++ b/packages/http-api/src/request-function.ts @@ -1,6 +1,7 @@ import {IHttpRequest, IHttpResponse} from '@testring/types'; import requestLib from 'request'; import requestPromise from 'request-promise-native'; +import _ from 'lodash'; const toString = (c: requestLib.Cookie) => c.toString(); @@ -29,18 +30,11 @@ export async function requestFunction( ): Promise { const cookieJar = createCookieStore(request.cookies, request.url); - const rawRequest: requestPromise.RequestPromiseOptions & { url: string } = { - url: request.url, + const rawRequest = _.merge({}, request, { qs: request.query, - body: request.body, - method: request.method, - timeout: request.timeout, - headers: request.headers, - json: request.json, - gzip: request.gzip, jar: cookieJar, resolveWithFullResponse: true, - }; + }); const response = await requestPromise(rawRequest); const cookies = cookieJar.getCookies(request.url).map(toString);