diff --git a/packages/auth-providers/dbAuth/api/src/__tests__/DbAuthHandler.fetch.test.js b/packages/auth-providers/dbAuth/api/src/__tests__/DbAuthHandler.fetch.test.js index 71f48c227f6f..7f78bd11097f 100644 --- a/packages/auth-providers/dbAuth/api/src/__tests__/DbAuthHandler.fetch.test.js +++ b/packages/auth-providers/dbAuth/api/src/__tests__/DbAuthHandler.fetch.test.js @@ -1,6 +1,17 @@ import crypto from 'node:crypto' import path from 'node:path' +import { + vi, + describe, + it, + expect, + beforeAll, + afterAll, + beforeEach, + afterEach, +} from 'vitest' + import { DbAuthHandler } from '../DbAuthHandler' import * as dbAuthError from '../errors' import { hashToken } from '../shared' @@ -136,7 +147,7 @@ let req, context, options describe('dbAuth', () => { beforeEach(() => { // hide deprecation warnings during test - jest.spyOn(console, 'warn').mockImplementation(() => {}) + vi.spyOn(console, 'warn').mockImplementation(() => {}) // encryption key so results are consistent regardless of settings in .env process.env.SESSION_SECRET = SESSION_SECRET delete process.env.DBAUTH_COOKIE_DOMAIN @@ -221,7 +232,7 @@ describe('dbAuth', () => { }) afterEach(async () => { - jest.spyOn(console, 'warn').mockRestore() + vi.spyOn(console, 'warn').mockRestore() await db.user.deleteMany({ where: { email: 'rob@redwoodjs.com' }, }) @@ -665,7 +676,7 @@ describe('dbAuth', () => { const dbAuth = new DbAuthHandler(fetchEvent, context, options) await dbAuth.init() - dbAuth.logout = jest.fn(() => { + dbAuth.logout = vi.fn(() => { throw Error('Logout error') }) const response = await dbAuth.invoke() @@ -687,7 +698,7 @@ describe('dbAuth', () => { credentials: true, }, }) - dbAuth.logout = jest.fn(() => { + dbAuth.logout = vi.fn(() => { throw Error('Logout error') }) const response = await dbAuth.invoke() @@ -711,7 +722,7 @@ describe('dbAuth', () => { const dbAuth = new DbAuthHandler(fetchEvent, context, options) await dbAuth.init() - dbAuth.logout = jest.fn(() => ['body', { foo: 'bar' }]) + dbAuth.logout = vi.fn(() => ['body', { foo: 'bar' }]) const response = await dbAuth.invoke() expect(dbAuth.logout).toHaveBeenCalled() @@ -1245,8 +1256,8 @@ describe('dbAuth', () => { }) it('login db check is called with insensitive string when user has provided one in LoginFlowOptions', async () => { - jest.clearAllMocks() - const spy = jest.spyOn(db.user, 'findFirst') + vi.clearAllMocks() + const spy = vi.spyOn(db.user, 'findFirst') options.signup.usernameMatch = 'insensitive' options.login.usernameMatch = 'insensitive' @@ -1279,8 +1290,8 @@ describe('dbAuth', () => { }) it('login db check is not called with insensitive string when user has not provided one in LoginFlowOptions', async () => { - jest.clearAllMocks() - const spy = jest.spyOn(db.user, 'findFirst') + vi.clearAllMocks() + const spy = vi.spyOn(db.user, 'findFirst') delete options.signup.usernameMatch delete options.login.usernameMatch @@ -2993,7 +3004,7 @@ describe('dbAuth', () => { }) it('createUser db check is called with insensitive string when user has provided one in SignupFlowOptions', async () => { - const spy = jest.spyOn(db.user, 'findFirst') + const spy = vi.spyOn(db.user, 'findFirst') options.signup.usernameMatch = 'insensitive' const dbUser = await createDbUser() @@ -3018,11 +3029,11 @@ describe('dbAuth', () => { }) it('createUser db check is not called with insensitive string when user has not provided one in SignupFlowOptions', async () => { - jest.resetAllMocks() - jest.clearAllMocks() + vi.resetAllMocks() + vi.clearAllMocks() const defaultMessage = options.signup.errors.usernameTaken - const spy = jest.spyOn(db.user, 'findFirst') + const spy = vi.spyOn(db.user, 'findFirst') delete options.signup.usernameMatch const dbUser = await createDbUser()