Initial commit

This commit is contained in:
2026-06-24 23:47:55 -07:00
commit d134b480a0
297 changed files with 30726 additions and 0 deletions
+38
View File
@@ -0,0 +1,38 @@
import { Request, Response, NextFunction } from "express"
import {
authorizationMiddleware,
type AuthorizationRequest,
} from "@/middlewares/authorization-middleware"
import { User } from "@/models"
/**
* Usage:
* At the top level of a test file import:
* import { mockCurrentUser } from "@/support"
*
* Then where you want to set the current user:
* mockCurrentUser(currentUser)
*
* @param newCurrentUser - The user to set as the current user
*/
export function mockCurrentUser(newCurrentUser: User) {
vi.mock("@/middlewares/jwt-middleware", () => ({
default: async (_req: Request, _res: Response, next: NextFunction) => next(),
jwtMiddleware: async (_req: Request, _res: Response, next: NextFunction) => next(),
}))
vi.mock("@/middlewares/authorization-middleware")
const authorizationMiddlewareMock = vi.mocked(authorizationMiddleware)
authorizationMiddlewareMock.mockImplementation(
async (req: AuthorizationRequest, _res: Response, next: NextFunction) => {
const currentUser = await User.withScope(["asCurrentUser"]).findByPk(newCurrentUser.id, {
rejectOnEmpty: true,
})
req.currentUser = currentUser
next()
}
)
}