server: linting
This commit is contained in:
parent
18dff00a93
commit
2a9e7ba6fc
4 changed files with 44 additions and 42 deletions
|
@ -2,47 +2,47 @@ import jwt, { UserJwtRequest } from "@lib/middleware/jwt"
|
||||||
import { NextFunction, Response } from "express"
|
import { NextFunction, Response } from "express"
|
||||||
|
|
||||||
describe("jwt middlware", () => {
|
describe("jwt middlware", () => {
|
||||||
let mockRequest: Partial<UserJwtRequest>
|
let mockRequest: Partial<UserJwtRequest>
|
||||||
let mockResponse: Partial<Response>
|
let mockResponse: Partial<Response>
|
||||||
let nextFunction: NextFunction = jest.fn()
|
let nextFunction: NextFunction = jest.fn()
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
mockRequest = {}
|
mockRequest = {}
|
||||||
mockResponse = {
|
mockResponse = {
|
||||||
sendStatus: jest.fn().mockReturnThis(),
|
sendStatus: jest.fn().mockReturnThis()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return 401 if no authorization header", () => {
|
it("should return 401 if no authorization header", () => {
|
||||||
const res = mockResponse as Response
|
const res = mockResponse as Response
|
||||||
jwt(mockRequest as UserJwtRequest, res, nextFunction)
|
jwt(mockRequest as UserJwtRequest, res, nextFunction)
|
||||||
expect(res.sendStatus).toHaveBeenCalledWith(401)
|
expect(res.sendStatus).toHaveBeenCalledWith(401)
|
||||||
})
|
})
|
||||||
|
|
||||||
it("should return 401 if no token is supplied", () => {
|
it("should return 401 if no token is supplied", () => {
|
||||||
const req = mockRequest as UserJwtRequest
|
const req = mockRequest as UserJwtRequest
|
||||||
req.headers = {
|
req.headers = {
|
||||||
authorization: "Bearer"
|
authorization: "Bearer"
|
||||||
}
|
}
|
||||||
jwt(req, mockResponse as Response, nextFunction)
|
jwt(req, mockResponse as Response, nextFunction)
|
||||||
expect(mockResponse.sendStatus).toBeCalledWith(401)
|
expect(mockResponse.sendStatus).toBeCalledWith(401)
|
||||||
})
|
})
|
||||||
|
|
||||||
// it("should return 401 if token is deleted", async () => {
|
// it("should return 401 if token is deleted", async () => {
|
||||||
// try {
|
// try {
|
||||||
// const tokenString = "123"
|
// const tokenString = "123"
|
||||||
|
|
||||||
// const req = mockRequest as UserJwtRequest
|
// const req = mockRequest as UserJwtRequest
|
||||||
// req.headers = {
|
// req.headers = {
|
||||||
// authorization: `Bearer ${tokenString}`
|
// authorization: `Bearer ${tokenString}`
|
||||||
// }
|
// }
|
||||||
// jwt(req, mockResponse as Response, nextFunction)
|
// jwt(req, mockResponse as Response, nextFunction)
|
||||||
// expect(mockResponse.sendStatus).toBeCalledWith(401)
|
// expect(mockResponse.sendStatus).toBeCalledWith(401)
|
||||||
// expect(mockResponse.json).toBeCalledWith({
|
// expect(mockResponse.json).toBeCalledWith({
|
||||||
// message: "Token is no longer valid"
|
// message: "Token is no longer valid"
|
||||||
// })
|
// })
|
||||||
// } catch (e) {
|
// } catch (e) {
|
||||||
// console.log(e)
|
// console.log(e)
|
||||||
// }
|
// }
|
||||||
// })
|
// })
|
||||||
})
|
})
|
|
@ -29,7 +29,7 @@ export default async function authenticateToken(
|
||||||
|
|
||||||
if (authToken.deletedAt) {
|
if (authToken.deletedAt) {
|
||||||
return res.sendStatus(401).json({
|
return res.sendStatus(401).json({
|
||||||
message: "Token is no longer valid",
|
message: "Token is no longer valid"
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -133,7 +133,6 @@ auth.get("/requires-passcode", async (req, res, next) => {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an access token, stores it in AuthToken table, and returns it
|
* Creates an access token, stores it in AuthToken table, and returns it
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -241,7 +241,10 @@ posts.get(
|
||||||
}),
|
}),
|
||||||
async (req: UserJwtRequest, res, next) => {
|
async (req: UserJwtRequest, res, next) => {
|
||||||
const isUserAuthor = (post: Post) => {
|
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 {
|
try {
|
||||||
|
|
Loading…
Reference in a new issue