Files
carmanagement/apps/api/src/modules/auth/auth.employee.service.test.ts
T
2026-05-22 17:21:52 -04:00

50 lines
1.3 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
vi.mock('./auth.employee.repo', () => ({
findActiveEmployeeByEmail: vi.fn(),
setPasswordResetToken: vi.fn(),
}))
vi.mock('../../services/notificationService', () => ({
sendTransactionalEmail: vi.fn().mockResolvedValue(undefined),
}))
import * as repo from './auth.employee.repo'
import { sendTransactionalEmail } from '../../services/notificationService'
import { forgotPassword } from './auth.employee.service'
describe('auth.employee.service forgotPassword', () => {
const originalDashboardUrl = process.env.DASHBOARD_URL
beforeEach(() => {
vi.clearAllMocks()
process.env.DASHBOARD_URL = 'http://localhost:3001'
})
afterAll(() => {
process.env.DASHBOARD_URL = originalDashboardUrl
})
it('sends the reset email to the canonical stored address', async () => {
vi.mocked(repo.findActiveEmployeeByEmail).mockResolvedValue({
id: 'emp_1',
email: 'owner@company.com',
firstName: 'Aya',
preferredLanguage: 'en',
} as any)
await forgotPassword('Owner@Company.com')
expect(repo.setPasswordResetToken).toHaveBeenCalledWith(
'emp_1',
expect.any(String),
expect.any(Date),
)
expect(sendTransactionalEmail).toHaveBeenCalledWith(
expect.objectContaining({
to: 'owner@company.com',
}),
)
})
})