Skip to content

Commit

Permalink
tests updated
Browse files Browse the repository at this point in the history
  • Loading branch information
ludeknovy committed Jan 12, 2023
1 parent adf9882 commit 50d8216
Show file tree
Hide file tree
Showing 16 changed files with 43 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createTokenController } from "./create-token-controller"
jest.mock("../../../db/db")
const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand All @@ -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)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { getTokensController } from "./get-tokens-controller"
jest.mock("../../../db/db")
const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand All @@ -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 () => {
Expand All @@ -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)
})
})
6 changes: 3 additions & 3 deletions src/server/controllers/auth/login-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jest.mock("../../../db/db")
jest.mock("./helper/passwords")
const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jest.mock("../../../db/db")
jest.mock("./helper/passwords")
const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand All @@ -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),
}))
Expand Down
6 changes: 3 additions & 3 deletions src/server/controllers/init/initialize-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { db } from "../../../db/db"
jest.mock("../../../db/db")
const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand All @@ -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([])
Expand All @@ -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 })
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getItemChartSettingsController } from "./get-item-chart-settings-contro
jest.mock("../../../db/db")
const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand All @@ -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)
})
})
6 changes: 3 additions & 3 deletions src/server/controllers/item/get-item-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { db } from "../../../db/db"
jest.mock("../../../db/db")
const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand Down Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { createItemLinkController } from "./create-item-share-token-controller"
jest.mock("../../../../db/db")
const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand All @@ -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)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { IGetUserAuthInfoRequest } from "../../../middleware/request.model"
jest.mock("../../../../db/db")
const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand All @@ -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)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ jest.mock("../../../db/db")

const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand All @@ -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()
Expand All @@ -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()
Expand Down Expand Up @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { db } from "../../../db/db"
jest.mock("../../../db/db")
const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand All @@ -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([])
})
})
10 changes: 5 additions & 5 deletions src/server/controllers/project/get-project-controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { db } from "../../../db/db"
jest.mock("../../../db/db")
const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand All @@ -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" }
Expand All @@ -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: [] })
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getProjectsController } from "./get-projects-controller"
jest.mock("../../../db/db")
const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand All @@ -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)
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getScenariosController } from "./get-scenarios-controller"
jest.mock("../../../db/db")
const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand All @@ -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 }] },
])
Expand All @@ -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: [] },
])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getScenarioTrendsController } from "./get-scenario-trends-controller"
jest.mock("../../../../db/db")
const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand All @@ -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,
Expand Down
6 changes: 3 additions & 3 deletions src/server/controllers/users/get-users.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { getUsersController } from "./get-users-controller"
jest.mock("../../../db/db")
const mockResponse = () => {
const res: Partial<Response> = {}
res.send = jest.fn().mockReturnValue(res)
res.json = jest.fn().mockReturnValue(res)
res.status = jest.fn().mockReturnValue(res)
return res
}
Expand All @@ -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)
})
})

0 comments on commit 50d8216

Please sign in to comment.