db management fix

This commit is contained in:
root
2026-05-22 17:21:52 -04:00
parent bae4942276
commit 48ecde2a51
13 changed files with 294 additions and 7 deletions
@@ -0,0 +1,49 @@
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest'
vi.mock('./admin.repo', () => ({
findAdminByEmail: vi.fn(),
setAdminPasswordReset: vi.fn(),
}))
vi.mock('../../services/notificationService', () => ({
sendTransactionalEmail: vi.fn().mockResolvedValue(undefined),
}))
import * as repo from './admin.repo'
import { sendTransactionalEmail } from '../../services/notificationService'
import { forgotPassword } from './admin.service'
describe('admin.service forgotPassword', () => {
const originalAdminUrl = process.env.ADMIN_URL
beforeEach(() => {
vi.clearAllMocks()
process.env.ADMIN_URL = 'http://localhost:3002'
})
afterAll(() => {
process.env.ADMIN_URL = originalAdminUrl
})
it('sends the reset email to the canonical stored admin address', async () => {
vi.mocked(repo.findAdminByEmail).mockResolvedValue({
id: 'admin_1',
email: 'admin@rentaldrivego.com',
firstName: 'Samir',
isActive: true,
} as any)
await forgotPassword('Admin@RentalDriveGo.com')
expect(repo.setAdminPasswordReset).toHaveBeenCalledWith(
'admin_1',
expect.any(String),
expect.any(Date),
)
expect(sendTransactionalEmail).toHaveBeenCalledWith(
expect.objectContaining({
to: 'admin@rentaldrivego.com',
}),
)
})
})