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', }), ) }) })