From 2a9e7ba6fc7758da949fecfcce5921867f680afb Mon Sep 17 00:00:00 2001 From: Max Leiter Date: Wed, 6 Apr 2022 15:14:05 -0700 Subject: [PATCH] server: linting --- server/src/lib/middleware/__tests__/jwt.ts | 78 +++++++++++----------- server/src/lib/middleware/jwt.ts | 2 +- server/src/routes/auth.ts | 1 - server/src/routes/posts.ts | 5 +- 4 files changed, 44 insertions(+), 42 deletions(-) diff --git a/server/src/lib/middleware/__tests__/jwt.ts b/server/src/lib/middleware/__tests__/jwt.ts index 4e869de4..4673c13e 100644 --- a/server/src/lib/middleware/__tests__/jwt.ts +++ b/server/src/lib/middleware/__tests__/jwt.ts @@ -2,47 +2,47 @@ import jwt, { UserJwtRequest } from "@lib/middleware/jwt" import { NextFunction, Response } from "express" describe("jwt middlware", () => { - let mockRequest: Partial - let mockResponse: Partial - let nextFunction: NextFunction = jest.fn() + let mockRequest: Partial + let mockResponse: Partial + let nextFunction: NextFunction = jest.fn() - beforeEach(() => { - mockRequest = {} - mockResponse = { - sendStatus: jest.fn().mockReturnThis(), - } - }) + beforeEach(() => { + mockRequest = {} + mockResponse = { + sendStatus: jest.fn().mockReturnThis() + } + }) - it("should return 401 if no authorization header", () => { - const res = mockResponse as Response - jwt(mockRequest as UserJwtRequest, res, nextFunction) - expect(res.sendStatus).toHaveBeenCalledWith(401) - }) + it("should return 401 if no authorization header", () => { + const res = mockResponse as Response + jwt(mockRequest as UserJwtRequest, res, nextFunction) + expect(res.sendStatus).toHaveBeenCalledWith(401) + }) - it("should return 401 if no token is supplied", () => { - const req = mockRequest as UserJwtRequest - req.headers = { - authorization: "Bearer" - } - jwt(req, mockResponse as Response, nextFunction) - expect(mockResponse.sendStatus).toBeCalledWith(401) - }) + it("should return 401 if no token is supplied", () => { + const req = mockRequest as UserJwtRequest + req.headers = { + authorization: "Bearer" + } + jwt(req, mockResponse as Response, nextFunction) + expect(mockResponse.sendStatus).toBeCalledWith(401) + }) - // it("should return 401 if token is deleted", async () => { - // try { - // const tokenString = "123" + // it("should return 401 if token is deleted", async () => { + // try { + // const tokenString = "123" - // const req = mockRequest as UserJwtRequest - // req.headers = { - // authorization: `Bearer ${tokenString}` - // } - // jwt(req, mockResponse as Response, nextFunction) - // expect(mockResponse.sendStatus).toBeCalledWith(401) - // expect(mockResponse.json).toBeCalledWith({ - // message: "Token is no longer valid" - // }) - // } catch (e) { - // console.log(e) - // } - // }) -}) \ No newline at end of file + // const req = mockRequest as UserJwtRequest + // req.headers = { + // authorization: `Bearer ${tokenString}` + // } + // jwt(req, mockResponse as Response, nextFunction) + // expect(mockResponse.sendStatus).toBeCalledWith(401) + // expect(mockResponse.json).toBeCalledWith({ + // message: "Token is no longer valid" + // }) + // } catch (e) { + // console.log(e) + // } + // }) +}) diff --git a/server/src/lib/middleware/jwt.ts b/server/src/lib/middleware/jwt.ts index 553c4bba..189aa10b 100644 --- a/server/src/lib/middleware/jwt.ts +++ b/server/src/lib/middleware/jwt.ts @@ -29,7 +29,7 @@ export default async function authenticateToken( if (authToken.deletedAt) { return res.sendStatus(401).json({ - message: "Token is no longer valid", + message: "Token is no longer valid" }) } diff --git a/server/src/routes/auth.ts b/server/src/routes/auth.ts index 83502d2e..f25c3557 100644 --- a/server/src/routes/auth.ts +++ b/server/src/routes/auth.ts @@ -133,7 +133,6 @@ auth.get("/requires-passcode", async (req, res, next) => { } }) - /** * Creates an access token, stores it in AuthToken table, and returns it */ diff --git a/server/src/routes/posts.ts b/server/src/routes/posts.ts index 74b92adb..b70204f2 100644 --- a/server/src/routes/posts.ts +++ b/server/src/routes/posts.ts @@ -241,7 +241,10 @@ posts.get( }), async (req: UserJwtRequest, res, next) => { const isUserAuthor = (post: Post) => { - return req.user?.id && post.users?.map((user) => user.id).includes(req.user?.id) + return ( + req.user?.id && + post.users?.map((user) => user.id).includes(req.user?.id) + ) } try {