import { describe, expect, it, vi } from 'vitest'
import { sendVerificationEmail } from '../src/adapters/email'

describe('auth email producer', () => {
  it('fails the auth flow when the durable queue rejects the message', async () => {
    const queue = { send: vi.fn().mockRejectedValue(new Error('queue unavailable')) }

    await expect(
      sendVerificationEmail({ QUEUE: queue } as never, 'user@example.test', 'token', 'user-1'),
    ).rejects.toThrow('queue unavailable')
    expect(queue.send).toHaveBeenCalledWith({
      type: 'auth.email',
      kind: 'verify_email',
      to: 'user@example.test',
      token: 'token',
      userId: 'user-1',
    })
  })
})
