-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
339 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
import { IGetUserAuthInfoRequest } from "./request.model" | ||
import { Response, NextFunction } from "express" | ||
import { projectExistsMiddleware } from "./project-exists-middleware" | ||
import { db } from "../../db/db" | ||
import Boom = require("boom") | ||
|
||
jest.mock("../../db/db") | ||
|
||
describe("projectExistsMiddleware", () => { | ||
const nextFunction: NextFunction = jest.fn() | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks() | ||
}) | ||
it("should return 404 when no project found", async () => { | ||
const request: any = { params: { projectName: "does not exist" } } | ||
db.oneOrNone = jest.fn().mockReturnValueOnce(null) | ||
|
||
await projectExistsMiddleware(request as unknown as IGetUserAuthInfoRequest, | ||
{} as unknown as Response, nextFunction) | ||
expect(nextFunction).toHaveBeenCalledTimes(1) | ||
expect(nextFunction).toHaveBeenCalledWith(Boom.notFound("Project not found")) | ||
}) | ||
|
||
it("should proceed when project found", async () => { | ||
const request: any = { params: { projectName: "my-project" } } | ||
db.oneOrNone = jest.fn().mockReturnValueOnce("projectId") | ||
|
||
await projectExistsMiddleware(request as unknown as IGetUserAuthInfoRequest, | ||
{} as unknown as Response, nextFunction) | ||
expect(nextFunction).toHaveBeenCalledTimes(1) | ||
expect(nextFunction).toHaveBeenCalledWith() | ||
}) | ||
|
||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import { IGetUserAuthInfoRequest } from "./request.model" | ||
import { NextFunction, Response } from "express" | ||
import { db } from "../../db/db" | ||
import * as boom from "boom" | ||
import { findProjectId } from "../queries/projects" | ||
|
||
export const projectExistsMiddleware = async (req: IGetUserAuthInfoRequest, res: Response, next: NextFunction) => { | ||
|
||
const { projectName } = req.params | ||
const project = await db.oneOrNone(findProjectId(projectName)) | ||
if (!project) { | ||
return next(boom.notFound("Project not found")) | ||
} | ||
next() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.