diff --git a/src/server/controllers/api-tokens/create-token-controller.spec.ts b/src/server/controllers/api-tokens/create-token-controller.spec.ts index 87bfd90b..30b55573 100644 --- a/src/server/controllers/api-tokens/create-token-controller.spec.ts +++ b/src/server/controllers/api-tokens/create-token-controller.spec.ts @@ -4,7 +4,7 @@ import { createTokenController } from "./create-token-controller" jest.mock("../../../db/db") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -22,6 +22,6 @@ describe("createTokenController", () => { request as unknown as IGetUserAuthInfoRequest, response as unknown as Response, nextFunction) expect(querySpy).toHaveBeenCalledTimes(1) - expect(response.send).toHaveBeenCalledTimes(1) + expect(response.json).toHaveBeenCalledTimes(1) }) }) diff --git a/src/server/controllers/api-tokens/create-token-controller.ts b/src/server/controllers/api-tokens/create-token-controller.ts index d3da15a1..667c8187 100644 --- a/src/server/controllers/api-tokens/create-token-controller.ts +++ b/src/server/controllers/api-tokens/create-token-controller.ts @@ -11,7 +11,7 @@ export const createTokenController = async (req: IGetUserAuthInfoRequest, res: R const newToken = `at-${uuidv4()}` try { await db.query(createNewApiToken(newToken, description, userId)) - return res.status(StatusCode.Created).send({ token: newToken }) + return res.status(StatusCode.Created).json({ token: newToken }) } catch(error) { return next(error) } diff --git a/src/server/controllers/api-tokens/get-tokens-controller.spec.ts b/src/server/controllers/api-tokens/get-tokens-controller.spec.ts index 8f738e4e..31d6771a 100644 --- a/src/server/controllers/api-tokens/get-tokens-controller.spec.ts +++ b/src/server/controllers/api-tokens/get-tokens-controller.spec.ts @@ -5,7 +5,7 @@ import { getTokensController } from "./get-tokens-controller" jest.mock("../../../db/db") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -23,7 +23,7 @@ describe("getTokenController", () => { request as unknown as IGetUserAuthInfoRequest, response as unknown as Response) expect(querySpy).toHaveBeenCalledTimes(1) - expect(response.send).toHaveBeenCalledTimes(1) + expect(response.json).toHaveBeenCalledTimes(1) }) it("should call getOnlyMyApiTokens query when operator role", async () => { @@ -38,6 +38,6 @@ describe("getTokenController", () => { request as unknown as IGetUserAuthInfoRequest, response as unknown as Response) expect(querySpy).toHaveBeenCalledTimes(1) - expect(response.send).toHaveBeenCalledTimes(1) + expect(response.json).toHaveBeenCalledTimes(1) }) }) diff --git a/src/server/controllers/api-tokens/get-tokens-controller.ts b/src/server/controllers/api-tokens/get-tokens-controller.ts index 1331ad19..5f458fd0 100644 --- a/src/server/controllers/api-tokens/get-tokens-controller.ts +++ b/src/server/controllers/api-tokens/get-tokens-controller.ts @@ -9,9 +9,9 @@ export const getTokensController = async (req: IGetUserAuthInfoRequest, res: Res const { role, userId } = req.user if (role === AllowedRoles.Operator) { const myApiKeys = await db.manyOrNone(getOnlyMyApiTokens(userId)) - return res.status(StatusCode.Ok).send(myApiKeys) + return res.status(StatusCode.Ok).json(myApiKeys) } const result = await db.manyOrNone(getApiTokens()) - res.status(StatusCode.Ok).send(result) + res.status(StatusCode.Ok).json(result) } diff --git a/src/server/controllers/auth/login-controller.spec.ts b/src/server/controllers/auth/login-controller.spec.ts index d0ae4a9c..cb580c92 100644 --- a/src/server/controllers/auth/login-controller.spec.ts +++ b/src/server/controllers/auth/login-controller.spec.ts @@ -8,7 +8,7 @@ jest.mock("../../../db/db") jest.mock("./helper/passwords") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -72,8 +72,8 @@ describe("loginController", () => { await loginController( request as unknown as IGetUserAuthInfoRequest, response as unknown as Response, nextFunction) - expect(response.send).toHaveBeenCalledTimes(1) - expect(response.send).toBeCalledWith( + expect(response.json).toHaveBeenCalledTimes(1) + expect(response.json).toBeCalledWith( expect.objectContaining({ token: expect.any(String), username: "test", diff --git a/src/server/controllers/auth/login-controller.ts b/src/server/controllers/auth/login-controller.ts index 94ddc43c..9e70460a 100644 --- a/src/server/controllers/auth/login-controller.ts +++ b/src/server/controllers/auth/login-controller.ts @@ -18,7 +18,7 @@ export const loginController = async (req: Request, res: Response, next: NextFun return next(boom.unauthorized("Invalid credentials")) } const token = generateToken(result[0].id) - return res.status(StatusCode.Ok).send({ token, username, role: result[0].role }) + return res.status(StatusCode.Ok).json({ token, username, role: result[0].role }) } catch(error) { return next(error) } diff --git a/src/server/controllers/auth/login-with-token-controller.spec.ts b/src/server/controllers/auth/login-with-token-controller.spec.ts index af2cbca2..cec8b3d0 100644 --- a/src/server/controllers/auth/login-with-token-controller.spec.ts +++ b/src/server/controllers/auth/login-with-token-controller.spec.ts @@ -7,7 +7,7 @@ jest.mock("../../../db/db") jest.mock("./helper/passwords") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -26,7 +26,7 @@ describe("loginWithTokenController", () => { await loginWithTokenController( request as unknown as IGetUserAuthInfoRequest, response as unknown as Response, nextFunction) - expect(response.send).toBeCalledWith( + expect(response.json).toBeCalledWith( expect.objectContaining({ jwtToken: expect.any(String), })) diff --git a/src/server/controllers/auth/login-with-token-controller.ts b/src/server/controllers/auth/login-with-token-controller.ts index 13213d84..25a965a1 100644 --- a/src/server/controllers/auth/login-with-token-controller.ts +++ b/src/server/controllers/auth/login-with-token-controller.ts @@ -12,7 +12,7 @@ export const loginWithTokenController = async (req: Request, res: Response, next const [tokenData] = await db.query(getApiToken(token)) const { created_by } = tokenData const jwtToken = generateTokenFromToken(created_by) - return res.status(StatusCode.Ok).send({ jwtToken }) + return res.status(StatusCode.Ok).json({ jwtToken }) } catch(error) { logger.error(error) return next(boom.unauthorized()) diff --git a/src/server/controllers/init/initialize-controller.spec.ts b/src/server/controllers/init/initialize-controller.spec.ts index 28a22d8f..60e5add1 100644 --- a/src/server/controllers/init/initialize-controller.spec.ts +++ b/src/server/controllers/init/initialize-controller.spec.ts @@ -6,7 +6,7 @@ import { db } from "../../../db/db" jest.mock("../../../db/db") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -21,7 +21,7 @@ describe("getInitController", () => { await getInitController( request as unknown as IGetUserAuthInfoRequest, response as unknown as Response, nextFunction) - expect(response.send).toBeCalledWith({ initialized: true }) + expect(response.json).toBeCalledWith({ initialized: true }) }) it("should return false if no user exists", async function () { (db.manyOrNone as any).mockResolvedValue([]) @@ -31,6 +31,6 @@ describe("getInitController", () => { await getInitController( request as unknown as IGetUserAuthInfoRequest, response as unknown as Response, nextFunction) - expect(response.send).toBeCalledWith({ initialized: false }) + expect(response.json).toBeCalledWith({ initialized: false }) }) }) diff --git a/src/server/controllers/init/initialize-controller.ts b/src/server/controllers/init/initialize-controller.ts index a0b2f1af..fc0afb9a 100644 --- a/src/server/controllers/init/initialize-controller.ts +++ b/src/server/controllers/init/initialize-controller.ts @@ -7,9 +7,9 @@ export const getInitController = async (req: Request, res: Response, next: NextF try { const users = await db.manyOrNone(getUsers()) if (users && users.length > 0) { - return res.status(StatusCode.Ok).send({ initialized: true }) + return res.status(StatusCode.Ok).json({ initialized: true }) } - return res.status(StatusCode.Ok).send({ initialized: false }) + return res.status(StatusCode.Ok).json({ initialized: false }) } catch(error) { return next(error) diff --git a/src/server/controllers/item/create-item-async-controller.ts b/src/server/controllers/item/create-item-async-controller.ts index 698b8b1d..8a443944 100644 --- a/src/server/controllers/item/create-item-async-controller.ts +++ b/src/server/controllers/item/create-item-async-controller.ts @@ -40,9 +40,9 @@ export const createItemAsyncController = async (req: IGetUserAuthInfoRequest, re const itemId = item.id logger.info(`New item for scenario: ${scenarioName} created with id: ${itemId}`) - res.status(StatusCode.Created).send({ itemId, shareToken }) + res.status(StatusCode.Created).json({ itemId, shareToken }) } catch(e) { logger.error(`Creating new async item failed ${e}`) - res.status(StatusCode.InternalError).send() + res.status(StatusCode.InternalError).json() } } diff --git a/src/server/controllers/item/create-item-controller.ts b/src/server/controllers/item/create-item-controller.ts index 5bb4d359..aad1fb79 100644 --- a/src/server/controllers/item/create-item-controller.ts +++ b/src/server/controllers/item/create-item-controller.ts @@ -91,7 +91,7 @@ export const createItemController = (req: IGetUserAuthInfoRequest, res: Response const itemId = item.id - res.status(StatusCode.Ok).send({ itemId, shareToken }) + res.status(StatusCode.Ok).json({ itemId, shareToken }) const columnSet = new pg.helpers.ColumnSet([ "elapsed", "success", "bytes", "label", diff --git a/src/server/controllers/item/get-item-chart-settings-controller.spec.ts b/src/server/controllers/item/get-item-chart-settings-controller.spec.ts index 377b2afe..e04813ec 100644 --- a/src/server/controllers/item/get-item-chart-settings-controller.spec.ts +++ b/src/server/controllers/item/get-item-chart-settings-controller.spec.ts @@ -4,7 +4,7 @@ import { getItemChartSettingsController } from "./get-item-chart-settings-contro jest.mock("../../../db/db") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -20,6 +20,6 @@ describe("getItemChartSettingsController", () => { await getItemChartSettingsController(request as unknown as IGetUserAuthInfoRequest, response as unknown as Response) expect(querySpy).toHaveBeenCalledTimes(1) - expect(response.send).toHaveBeenCalledTimes(1) + expect(response.json).toHaveBeenCalledTimes(1) }) }) diff --git a/src/server/controllers/item/get-item-chart-settings-controller.ts b/src/server/controllers/item/get-item-chart-settings-controller.ts index dffaaacd..e02ffb03 100644 --- a/src/server/controllers/item/get-item-chart-settings-controller.ts +++ b/src/server/controllers/item/get-item-chart-settings-controller.ts @@ -12,5 +12,5 @@ export const getItemChartSettingsController = async ( const { userId } = req.user const chartSettings = await db.oneOrNone(getItemChartSettings(itemId, userId)) - res.status(StatusCode.Ok).send(chartSettings?.settings || []) + res.status(StatusCode.Ok).json(chartSettings?.settings || []) } diff --git a/src/server/controllers/item/get-item-controller.spec.ts b/src/server/controllers/item/get-item-controller.spec.ts index 854e0cc1..e8e47114 100644 --- a/src/server/controllers/item/get-item-controller.spec.ts +++ b/src/server/controllers/item/get-item-controller.spec.ts @@ -6,7 +6,7 @@ import { db } from "../../../db/db" jest.mock("../../../db/db") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -43,8 +43,8 @@ describe("getItemController", () => { expect(findItemQuerySpy).toHaveBeenCalledTimes(1) expect(findItemStatsQuerySpy).toHaveBeenCalledTimes(1) expect(getMonitoringDataQuerySpy).toHaveBeenCalledTimes(1) - expect(response.send).toHaveBeenCalledTimes(1) - expect(response.send).toHaveBeenLastCalledWith({ + expect(response.json).toHaveBeenCalledTimes(1) + expect(response.json).toHaveBeenLastCalledWith({ analysisEnabled: true, baseId: null, environment: "environment", diff --git a/src/server/controllers/item/get-item-controller.ts b/src/server/controllers/item/get-item-controller.ts index d36b33a4..1bc22710 100644 --- a/src/server/controllers/item/get-item-controller.ts +++ b/src/server/controllers/item/get-item-controller.ts @@ -36,7 +36,7 @@ export const getItemController = async (req: IGetUserAuthInfoRequest, res: Respo const maxCpu = findMinMax(monitoring.map(_ => _.avgCpu)).max - res.status(StatusCode.Ok).send({ + res.status(StatusCode.Ok).json({ overview, sutOverview, statistics, status, plot, extraPlotData, note, environment, hostname, reportStatus, thresholds, analysisEnabled, baseId: base_id, isBase: base_id === itemId, zeroErrorToleranceEnabled, topMetricsSettings, diff --git a/src/server/controllers/item/get-items-controller.ts b/src/server/controllers/item/get-items-controller.ts index 68d33156..1b8d549f 100644 --- a/src/server/controllers/item/get-items-controller.ts +++ b/src/server/controllers/item/get-items-controller.ts @@ -15,5 +15,5 @@ export const getItemsController = async (req: Request, res: Response) => { _.base = !_.base ? false : true return _ }) - res.status(StatusCode.Ok).send({ name: scenarioName, data: idsBaseUpdate, total: parseInt(total, 10) }) + res.status(StatusCode.Ok).json({ name: scenarioName, data: idsBaseUpdate, total: parseInt(total, 10) }) } diff --git a/src/server/controllers/item/get-processing-items-controller.ts b/src/server/controllers/item/get-processing-items-controller.ts index 6c900926..63c9ffbc 100644 --- a/src/server/controllers/item/get-processing-items-controller.ts +++ b/src/server/controllers/item/get-processing-items-controller.ts @@ -10,5 +10,5 @@ export const getProcessingItemsController = async (req: Request, res: Response) const processingItems = await db.any(getProcessingItems(projectName, scenarioName)) const inprogress = processingItems.filter((_) => _.reportStatus === ReportStatus.InProgress) const failed = processingItems.filter((_) => _.reportStatus === ReportStatus.Error) - res.status(StatusCode.Ok).send({ failed, inprogress }) + res.status(StatusCode.Ok).json({ failed, inprogress }) } diff --git a/src/server/controllers/item/share-tokens/create-item-share-token-controller.spec.ts b/src/server/controllers/item/share-tokens/create-item-share-token-controller.spec.ts index 965c0c8e..c8e25bce 100644 --- a/src/server/controllers/item/share-tokens/create-item-share-token-controller.spec.ts +++ b/src/server/controllers/item/share-tokens/create-item-share-token-controller.spec.ts @@ -4,7 +4,7 @@ import { createItemLinkController } from "./create-item-share-token-controller" jest.mock("../../../../db/db") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -24,7 +24,7 @@ describe("createItemLinkController", () => { } await createItemLinkController(request as unknown as IGetUserAuthInfoRequest, response as unknown as Response) expect(querySpy).toHaveBeenCalledWith("project", "scenario", "id", "token", "userId", "note") - expect(response.send).toHaveBeenCalledTimes(1) + expect(response.json).toHaveBeenCalledTimes(1) expect(generateTokenSpy).toHaveBeenCalledTimes(1) }) }) diff --git a/src/server/controllers/item/share-tokens/create-item-share-token-controller.ts b/src/server/controllers/item/share-tokens/create-item-share-token-controller.ts index 53a45c91..6bf3de56 100644 --- a/src/server/controllers/item/share-tokens/create-item-share-token-controller.ts +++ b/src/server/controllers/item/share-tokens/create-item-share-token-controller.ts @@ -11,5 +11,5 @@ export const createItemLinkController = async (req: IGetUserAuthInfoRequest, res const { note } = req.body const token = generateShareToken() await db.none(createShareToken(projectName, scenarioName, itemId, token, user.userId, note )) - res.status(StatusCode.Created).send({ token }) + res.status(StatusCode.Created).json({ token }) } diff --git a/src/server/controllers/item/share-tokens/get-item-share-tokens-controller.spec.ts b/src/server/controllers/item/share-tokens/get-item-share-tokens-controller.spec.ts index 4f193414..6ce0a20c 100644 --- a/src/server/controllers/item/share-tokens/get-item-share-tokens-controller.spec.ts +++ b/src/server/controllers/item/share-tokens/get-item-share-tokens-controller.spec.ts @@ -4,7 +4,7 @@ import { IGetUserAuthInfoRequest } from "../../../middleware/request.model" jest.mock("../../../../db/db") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -19,6 +19,6 @@ describe("getItemLinksController", () => { } await getItemLinksController(request as unknown as IGetUserAuthInfoRequest, response as unknown as Response) expect(querySpy).toHaveBeenCalledTimes(1) - expect(response.send).toHaveBeenCalledTimes(1) + expect(response.json).toHaveBeenCalledTimes(1) }) }) diff --git a/src/server/controllers/item/share-tokens/get-item-share-tokens-controller.ts b/src/server/controllers/item/share-tokens/get-item-share-tokens-controller.ts index 4c285684..dae0e31f 100644 --- a/src/server/controllers/item/share-tokens/get-item-share-tokens-controller.ts +++ b/src/server/controllers/item/share-tokens/get-item-share-tokens-controller.ts @@ -10,9 +10,9 @@ export const getItemLinksController = async (req: IGetUserAuthInfoRequest, res: const { projectName, scenarioName, itemId } = req.params if ([AllowedRoles.Readonly, AllowedRoles.Operator].includes(role)) { const myApiKeys = await db.manyOrNone(selectOnlyMyShareTokens(projectName, scenarioName, itemId, userId)) - return res.status(StatusCode.Ok).send(myApiKeys) + return res.send(StatusCode.Ok).json(myApiKeys) } const shareTokens = await db.manyOrNone(selectShareTokens(projectName, scenarioName, itemId)) - res.status(StatusCode.Ok).send(shareTokens) + res.status(StatusCode.Ok).json(shareTokens) } diff --git a/src/server/controllers/label/get-label-errors-controller.ts b/src/server/controllers/label/get-label-errors-controller.ts index 30b0dd34..09a79f68 100644 --- a/src/server/controllers/label/get-label-errors-controller.ts +++ b/src/server/controllers/label/get-label-errors-controller.ts @@ -13,5 +13,5 @@ export const getLabelErrorsController = async (req: Request, res: Response) => { : acc[rc] = 1 return acc }, {}) - res.status(StatusCode.Ok).send({ stat }) + res.status(StatusCode.Ok).json({ stat }) } diff --git a/src/server/controllers/label/get-label-trend-controller.spec.ts b/src/server/controllers/label/get-label-trend-controller.spec.ts index 3312884f..70c56615 100644 --- a/src/server/controllers/label/get-label-trend-controller.spec.ts +++ b/src/server/controllers/label/get-label-trend-controller.spec.ts @@ -8,7 +8,7 @@ jest.mock("../../../db/db") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -26,7 +26,7 @@ describe("getItemChartSettingsController", () => { await getLabelTrendController(request as unknown as IGetUserAuthInfoRequest, response as unknown as Response) expect(querySpy).toHaveBeenCalledTimes(1) - expect(response.send).toHaveBeenCalledTimes(1) + expect(response.json).toHaveBeenCalledTimes(1) }) it("should fetch getLabelHistory from db", async () => { const response = mockResponse() @@ -41,7 +41,7 @@ describe("getItemChartSettingsController", () => { await getLabelTrendController(request as unknown as IGetUserAuthInfoRequest, response as unknown as Response) expect(querySpy).toHaveBeenCalledTimes(1) - expect(response.send).toHaveBeenCalledTimes(1) + expect(response.json).toHaveBeenCalledTimes(1) }) it("should sort query output from oldest to newest", async () => { const response = mockResponse() @@ -108,7 +108,7 @@ describe("getItemChartSettingsController", () => { await getLabelTrendController(request as unknown as IGetUserAuthInfoRequest, response as unknown as Response) - expect(response.send).toHaveBeenCalledWith({ + expect(response.json).toHaveBeenCalledWith({ chartSeries: { errorRate: [100, 10], p90: [1, 10], diff --git a/src/server/controllers/label/get-label-trend-controller.ts b/src/server/controllers/label/get-label-trend-controller.ts index c139fb6e..91756fff 100644 --- a/src/server/controllers/label/get-label-trend-controller.ts +++ b/src/server/controllers/label/get-label-trend-controller.ts @@ -38,7 +38,7 @@ export const getLabelTrendController = async (req: Request, res: Response) => { }, { timePoints: [], p90: [], p95: [], p99: [], errorRate: [], throughput: [], virtualUsers: [], avgResponseTime: [], avgConnectionTime: [], avgLatency: [], name: [] }) - res.status(StatusCode.Ok).send({ + res.status(StatusCode.Ok).json({ chartSeries: { timePoints, p90, p95, p99, diff --git a/src/server/controllers/label/get-label-vu-controllers.ts b/src/server/controllers/label/get-label-vu-controllers.ts index 8ff7d3fe..fc2b9141 100644 --- a/src/server/controllers/label/get-label-vu-controllers.ts +++ b/src/server/controllers/label/get-label-vu-controllers.ts @@ -10,7 +10,7 @@ export const getLabelVirtualUsersController = async (req: Request, res: Response const result = await db.query(getMaxVuForLabel( scenarioName, projectName, label, itemId, environment)) - res.status(StatusCode.Ok).send({ result }) + res.status(StatusCode.Ok).json({ result }) } catch(error) { return next(error) } diff --git a/src/server/controllers/project/get-latest-items-controller.spec.ts b/src/server/controllers/project/get-latest-items-controller.spec.ts index 04526556..62fcca31 100644 --- a/src/server/controllers/project/get-latest-items-controller.spec.ts +++ b/src/server/controllers/project/get-latest-items-controller.spec.ts @@ -6,7 +6,7 @@ import { db } from "../../../db/db" jest.mock("../../../db/db") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -28,6 +28,6 @@ describe("getLatestItemsController", function () { response as unknown as Response) expect(latestItemSpy).toHaveBeenNthCalledWith(1, request.user.userId) - expect(response.send).toHaveBeenCalledWith([]) + expect(response.json).toHaveBeenCalledWith([]) }) }) diff --git a/src/server/controllers/project/get-latest-items-controllers.ts b/src/server/controllers/project/get-latest-items-controllers.ts index ef68e56b..281bc832 100644 --- a/src/server/controllers/project/get-latest-items-controllers.ts +++ b/src/server/controllers/project/get-latest-items-controllers.ts @@ -7,5 +7,5 @@ import { IGetUserAuthInfoRequest } from "../../middleware/request.model" export const getLatestItemsControllers = async (req: IGetUserAuthInfoRequest, res: Response) => { const user = req.user const items = await db.many(latestItems(user.userId)) - res.status(StatusCode.Ok).send(items) + res.status(StatusCode.Ok).json(items) } diff --git a/src/server/controllers/project/get-project-controller.spec.ts b/src/server/controllers/project/get-project-controller.spec.ts index 18995e35..6e141896 100644 --- a/src/server/controllers/project/get-project-controller.spec.ts +++ b/src/server/controllers/project/get-project-controller.spec.ts @@ -6,7 +6,7 @@ import { db } from "../../../db/db" jest.mock("../../../db/db") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -28,8 +28,8 @@ describe("getProjectController", () => { (db.manyOrNone as any).mockResolvedValue([{ user_id: 1 }]) await getProjectController(request as unknown as IGetUserAuthInfoRequest, response as unknown as Response) - expect(response.send).toHaveBeenCalledTimes(1) - expect(response.send).toBeCalledWith({ ...responseStub, projectMembers: [1] }) + expect(response.json).toHaveBeenCalledTimes(1) + expect(response.json).toBeCalledWith({ ...responseStub, projectMembers: [1] }) }) it("should not return project members when user role is not admin", async () => { const responseStub = { name: "project" } @@ -45,7 +45,7 @@ describe("getProjectController", () => { (db.one as any).mockResolvedValue(responseStub) await getProjectController(request as unknown as IGetUserAuthInfoRequest, response as unknown as Response) - expect(response.send).toHaveBeenCalledTimes(1) - expect(response.send).toBeCalledWith({ ...responseStub, projectMembers: [] }) + expect(response.json).toHaveBeenCalledTimes(1) + expect(response.json).toBeCalledWith({ ...responseStub, projectMembers: [] }) }) }) diff --git a/src/server/controllers/project/get-project-controller.ts b/src/server/controllers/project/get-project-controller.ts index e6bb9b4e..ce71a88c 100644 --- a/src/server/controllers/project/get-project-controller.ts +++ b/src/server/controllers/project/get-project-controller.ts @@ -14,5 +14,5 @@ export const getProjectController = async (req: IGetUserAuthInfoRequest, res: Re const pm = await db.manyOrNone(getProjectMembers(projectName)) pm.forEach(user => projectMembers.push(user.user_id)) } - res.status(StatusCode.Ok).send({ ...projectSettings, projectMembers }) + res.status(StatusCode.Ok).json({ ...projectSettings, projectMembers }) } diff --git a/src/server/controllers/project/get-projects-controller.spec.ts b/src/server/controllers/project/get-projects-controller.spec.ts index afcab713..dda9164a 100644 --- a/src/server/controllers/project/get-projects-controller.spec.ts +++ b/src/server/controllers/project/get-projects-controller.spec.ts @@ -6,7 +6,7 @@ import { getProjectsController } from "./get-projects-controller" jest.mock("../../../db/db") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -30,6 +30,6 @@ describe("getProjectsController", function () { response as unknown as Response) expect(findProjectsSpy).toHaveBeenNthCalledWith(1, request.user.userId) - expect(response.send).toHaveBeenCalledWith(projects) + expect(response.json).toHaveBeenCalledWith(projects) }) }) diff --git a/src/server/controllers/project/get-projects-controller.ts b/src/server/controllers/project/get-projects-controller.ts index 547e210d..e69c6f8f 100644 --- a/src/server/controllers/project/get-projects-controller.ts +++ b/src/server/controllers/project/get-projects-controller.ts @@ -7,5 +7,5 @@ import { IGetUserAuthInfoRequest } from "../../middleware/request.model" export const getProjectsController = async (req: IGetUserAuthInfoRequest, res: Response ) => { const user = req.user const projects = await db.any(findProjects(user.userId)) - res.status(StatusCode.Ok).send(projects) + res.status(StatusCode.Ok).json(projects) } diff --git a/src/server/controllers/project/get-projects-stats-controller.ts b/src/server/controllers/project/get-projects-stats-controller.ts index 17100285..cc124ecc 100644 --- a/src/server/controllers/project/get-projects-stats-controller.ts +++ b/src/server/controllers/project/get-projects-stats-controller.ts @@ -5,7 +5,7 @@ import { StatusCode } from "../../utils/status-code" export const getProjectStatsController = async (req: Request, res: Response) => { const { avgVu, avgDuration, totalDuration, totalCount } = await db.one(dashboardStats()) - res.status(StatusCode.Ok).send({ + res.status(StatusCode.Ok).json({ avgVu: avgVu ? parseInt(avgVu, 10) : 0, avgDuration: avgDuration ? parseInt(avgDuration, 10) : 0, totalDuration: totalDuration ? parseInt(totalDuration, 10) : 0, diff --git a/src/server/controllers/scenario/get-scenario-controller.ts b/src/server/controllers/scenario/get-scenario-controller.ts index 89488735..9fd34639 100644 --- a/src/server/controllers/scenario/get-scenario-controller.ts +++ b/src/server/controllers/scenario/get-scenario-controller.ts @@ -22,7 +22,7 @@ export const getScenarioController = async (req: IGetUserAuthInfoRequest, res: R const { userId } = req.user const scenario = await db.oneOrNone(getScenario(projectName, scenarioName)) const userScenarioSettings = await db.oneOrNone(getUserScenarioSettings(projectName, scenarioName, userId)) - res.status(StatusCode.Ok).send({ + res.status(StatusCode.Ok).json({ name: scenario.name, analysisEnabled: scenario.analysis_enabled, zeroErrorToleranceEnabled: scenario.zero_error_tolerance_enabled, diff --git a/src/server/controllers/scenario/get-scenarios-controller.spec.ts b/src/server/controllers/scenario/get-scenarios-controller.spec.ts index 5b078bf9..2a1aef9c 100644 --- a/src/server/controllers/scenario/get-scenarios-controller.spec.ts +++ b/src/server/controllers/scenario/get-scenarios-controller.spec.ts @@ -6,7 +6,7 @@ import { getScenariosController } from "./get-scenarios-controller" jest.mock("../../../db/db") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -26,7 +26,7 @@ describe("getScenariosController", () => { await getScenariosController( request as unknown as IGetUserAuthInfoRequest, response as unknown as Response) - expect(response.send).toBeCalledWith([ + expect(response.json).toBeCalledWith([ { name: "scenario1", id: "id1", data: [{ test: 1 }, { test: 2 }] }, { name: "scenario2", id: "id2", data: [{ test: 2 }] }, ]) @@ -43,7 +43,7 @@ describe("getScenariosController", () => { await getScenariosController( request as unknown as IGetUserAuthInfoRequest, response as unknown as Response) - expect(response.send).toBeCalledWith([ + expect(response.json).toBeCalledWith([ { name: "scenario1", id: "id1", data: [{ test: 1 }] }, { name: "scenario2", id: "id2", data: [] }, ]) diff --git a/src/server/controllers/scenario/get-scenarios-controller.ts b/src/server/controllers/scenario/get-scenarios-controller.ts index 60d2422f..7d6f2a3d 100644 --- a/src/server/controllers/scenario/get-scenarios-controller.ts +++ b/src/server/controllers/scenario/get-scenarios-controller.ts @@ -23,5 +23,5 @@ export const getScenariosController = async (req: Request, res: Response) => { groupedData.push({ name: scenario.name, id: scenario.id, data: [] }) } }) - res.status(StatusCode.Ok).send(groupedData) + res.status(StatusCode.Ok).json(groupedData) } diff --git a/src/server/controllers/scenario/trends/get-scenario-trends-controller.spec.ts b/src/server/controllers/scenario/trends/get-scenario-trends-controller.spec.ts index 5adb816c..cd26470a 100644 --- a/src/server/controllers/scenario/trends/get-scenario-trends-controller.spec.ts +++ b/src/server/controllers/scenario/trends/get-scenario-trends-controller.spec.ts @@ -6,7 +6,7 @@ import { getScenarioTrendsController } from "./get-scenario-trends-controller" jest.mock("../../../../db/db") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -27,7 +27,7 @@ describe("getScenarioTrendsController", function () { request as unknown as IGetUserAuthInfoRequest, response as unknown as Response) - expect(response.send).toBeCalledWith([{ + expect(response.json).toBeCalledWith([{ id: "id1", overview: { bytesPerSecond: 100, diff --git a/src/server/controllers/scenario/trends/get-scenario-trends-controller.ts b/src/server/controllers/scenario/trends/get-scenario-trends-controller.ts index a39a6158..266300f4 100644 --- a/src/server/controllers/scenario/trends/get-scenario-trends-controller.ts +++ b/src/server/controllers/scenario/trends/get-scenario-trends-controller.ts @@ -18,5 +18,5 @@ export const getScenarioTrendsController = async (req: Request, res: Response) = } }).sort((a, b) => new Date(a.overview.startDate).getTime() - new Date(b.overview.startDate).getTime()) - res.status(StatusCode.Ok).send(networkAdjustedData) + res.status(StatusCode.Ok).json(networkAdjustedData) } diff --git a/src/server/controllers/users/create-new-user-controller.ts b/src/server/controllers/users/create-new-user-controller.ts index 3e607311..adb52f70 100644 --- a/src/server/controllers/users/create-new-user-controller.ts +++ b/src/server/controllers/users/create-new-user-controller.ts @@ -12,8 +12,6 @@ export const createNewUserController = async (req: Request, res: Response, next: try { const userId = await createUserInDB(username, password, role) - console.log({ userId }) - console.log({ role }) if (role === "admin") { await db.query(asignAdminAsProjectMember(userId.id)) } diff --git a/src/server/controllers/users/get-users-controller.ts b/src/server/controllers/users/get-users-controller.ts index aeeacf5b..ada63e55 100644 --- a/src/server/controllers/users/get-users-controller.ts +++ b/src/server/controllers/users/get-users-controller.ts @@ -6,5 +6,5 @@ import { StatusCode } from "../../utils/status-code" export const getUsersController = async (req: Request, res: Response) => { const result = await db.query(getUsers) - res.status(StatusCode.Ok).send(result) + res.status(StatusCode.Ok).json(result) } diff --git a/src/server/controllers/users/get-users.controller.spec.ts b/src/server/controllers/users/get-users.controller.spec.ts index 65d7532c..b391505c 100644 --- a/src/server/controllers/users/get-users.controller.spec.ts +++ b/src/server/controllers/users/get-users.controller.spec.ts @@ -6,7 +6,7 @@ import { getUsersController } from "./get-users-controller" jest.mock("../../../db/db") const mockResponse = () => { const res: Partial = {} - res.send = jest.fn().mockReturnValue(res) + res.json = jest.fn().mockReturnValue(res) res.status = jest.fn().mockReturnValue(res) return res } @@ -20,7 +20,7 @@ describe("getUsersController", () => { await getUsersController( request as unknown as IGetUserAuthInfoRequest, response as unknown as Response) - expect(response.send).toBeCalledTimes(1) - expect(response.send).toBeCalledWith(users) + expect(response.json).toBeCalledTimes(1) + expect(response.json).toBeCalledWith(users) }) }) diff --git a/src/server/routes/test-data-setup.ts b/src/server/routes/test-data-setup.ts index c8b237f2..5328d3f2 100644 --- a/src/server/routes/test-data-setup.ts +++ b/src/server/routes/test-data-setup.ts @@ -53,7 +53,7 @@ export class TestDataSetup { item.id, JSON.stringify(testStats), JSON.stringify(testOverview), JSON.stringify([]))) - res.status(StatusCode.Ok).send({ itemId: item.id }) + res.status(StatusCode.Ok).json({ itemId: item.id }) } else if (state === States.EmptyDb) { res.sendStatus(StatusCode.Created) } else if (state === States.NoUsers) { @@ -65,7 +65,7 @@ export class TestDataSetup { // eslint-disable-next-line no-case-declarations const { id } = await db.one(getUser("test-user")) await db.any(createNewApiToken(TOKEN, "test-token", id)) - res.status(StatusCode.Ok).send({ token: TOKEN }) + res.status(StatusCode.Ok).json({ token: TOKEN }) } else { res.sendStatus(StatusCode.BadRequest) } @@ -80,7 +80,7 @@ export class TestDataSetup { await createUserInDB(username, password, AllowedRoles.Admin) const { id } = await db.one(getUser(username)) const token = generateToken(id) - res.status(StatusCode.Ok).send({ token, username, password, id }) + res.status(StatusCode.Ok).json({ token, username, password, id }) }) ) @@ -92,7 +92,7 @@ export class TestDataSetup { await createUserInDB("test-user", "test0000", AllowedRoles.Admin) const { id } = await db.one(getUser("test-user")) await db.any(createNewApiToken(TOKEN, "test-token", id)) - res.status(StatusCode.Ok).send({ token: TOKEN }) + res.status(StatusCode.Ok).json({ token: TOKEN }) }) ) }