Skip to content

Commit

Permalink
feat(middleware): use enums for modes
Browse files Browse the repository at this point in the history
Signed-off-by: Tanmay Bajaj <[email protected]>
  • Loading branch information
frey0-0 committed Mar 24, 2023
1 parent 4bc8bc6 commit 072ce3b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions integrations/express/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Keploy, { HTTP } from "../../src/keploy";
import { Request, Response, NextFunction } from "express";
import { createExecutionContext, getExecutionContext } from "../../src/context";
import { StrArr } from "../../proto/services/StrArr";
import { MODE_TEST, MODE_RECORD, MODE_OFF } from "../../src/mode";

class ResponseBody {
static responseMap = new WeakMap<Request, ResponseBody>();
Expand Down Expand Up @@ -72,10 +73,10 @@ export default function middleware(
});
if (
(process.env.KEPLOY_MODE != undefined &&
process.env.KEPLOY_MODE == "off") ||
process.env.KEPLOY_MODE == MODE_OFF) ||
keploy == undefined
) {
createExecutionContext({ mode: "off" });
createExecutionContext({ mode: MODE_OFF });
next();
return;
}
Expand All @@ -84,7 +85,7 @@ export default function middleware(
// test mode
if (id != undefined && id != "") {
createExecutionContext({
mode: "test",
mode: MODE_TEST,
testId: id,
deps: keploy.getDependencies(id),
mocks: keploy.getMocks(id),
Expand All @@ -94,7 +95,7 @@ export default function middleware(
}

// record mode
createExecutionContext({ mode: "record", deps: [], mocks: [] });
createExecutionContext({ mode: MODE_RECORD, deps: [], mocks: [] });
captureResp(req, res, next);
};
}
Expand All @@ -118,7 +119,7 @@ function captureResp(
export function afterMiddleware(keploy: Keploy, req: Request, res: Response) {
if (
(process.env.KEPLOY_MODE != undefined &&
process.env.KEPLOY_MODE == "off") ||
process.env.KEPLOY_MODE == MODE_OFF) ||
keploy == undefined
) {
return;
Expand All @@ -140,7 +141,7 @@ export function afterMiddleware(keploy: Keploy, req: Request, res: Response) {
}

//to avoid recording tests in the test mode and only recording in the record mode
if (process.env.KEPLOY_MODE == "test" && id === undefined) {
if (process.env.KEPLOY_MODE == MODE_TEST && id === undefined) {
return;
}

Expand Down

0 comments on commit 072ce3b

Please sign in to comment.