Skip to content

Commit

Permalink
fixing: ts-sdk records keploy-testcase even on test mode (#86)
Browse files Browse the repository at this point in the history
* fix: fixing the middleware.ts file

Signed-off-by: sekhar kumar dash <sekharkumardash229@gmail.com>

* fix: fixing the middleware.ts file

Signed-off-by: sekhar kumar dash <sekharkumardash229@gmail.com>

* fix: fixing the middleware.ts file

Signed-off-by: sekhar kumar dash <sekharkumardash229@gmail.com>

* fix: fixing the middleware.ts file

Signed-off-by: sekhar kumar dash <sekharkumardash229@gmail.com>

* fix: fixing the middleware.ts

Signed-off-by: sekhar kumar dash <sekharkumardash229@gmail.com>

---------

Signed-off-by: sekhar kumar dash <sekharkumardash229@gmail.com>
  • Loading branch information
Sekhar-Kumar-Dash authored Sep 5, 2023
1 parent 18d6254 commit 7f87911
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions integrations/express/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,28 @@ export default function middleware(

const id = req.get("KEPLOY_TEST_ID");
// test mode
//user-initiated request,not the appclient
//treat as disable for this specific request
function handleTestMode(
keploy: Keploy,
req: Request,
res: Response,
next: NextFunction
) {
const id = req.get("KEPLOY_TEST_ID");
if (keploy.mode.GetMode() === MODE_TEST && (!id || id === "")) {
createExecutionContext({ mode: MODE_OFF });
next();
} else {
return false;
}
return true;
}
// Calling the handleTestMode function here
if (handleTestMode(keploy, req, res, next)) {
return;
}

if (id != undefined && id != "") {
createExecutionContext({
mode: MODE_TEST,
Expand Down Expand Up @@ -129,13 +151,13 @@ function captureResp(
next();
return;
}

export function afterMiddleware(keploy: Keploy, req: Request, res: Response) {
if (keploy.mode.GetMode() == MODE_OFF) {
return;
}

const id = req.get("KEPLOY_TEST_ID");

if (id !== undefined && id !== "") {
const respHeader: { [key: string]: StrArr } = getResponseHeader(
res.getHeaders()
Expand All @@ -150,7 +172,9 @@ export function afterMiddleware(keploy: Keploy, req: Request, res: Response) {
deleteExecutionContext();
return;
}

if (keploy.mode.GetMode() == MODE_TEST && (id === undefined || id === "")) {
return;
}
// req.headers
// Since, JSON.stingify trims spaces. Therefore, content-length of request header should be updated
req.headers["content-length"] = JSON.stringify(
Expand Down

0 comments on commit 7f87911

Please sign in to comment.