import { describe, it, expect, vi, beforeEach, afterEach } from 'vitest'
import { computeRetryNextRunAt } from '../utils'

describe('computeRetryNextRunAt', () => {
  beforeEach(() => {
    vi.useFakeTimers()
    vi.setSystemTime(new Date('2026-01-15T10:00:00Z'))
  })

  afterEach(() => {
    vi.useRealTimers()
  })

  it('returns 1 minute delay for retryCount 0', () => {
    // Formula: (0 + 1)^2 = 1 minute
    const result = computeRetryNextRunAt(0)
    expect(result.toISOString()).toBe('2026-01-15T10:01:00.000Z')
  })

  it('returns 4 minute delay for retryCount 1', () => {
    // Formula: (1 + 1)^2 = 4 minutes
    const result = computeRetryNextRunAt(1)
    expect(result.toISOString()).toBe('2026-01-15T10:04:00.000Z')
  })

  it('returns 9 minute delay for retryCount 2', () => {
    // Formula: (2 + 1)^2 = 9 minutes
    const result = computeRetryNextRunAt(2)
    expect(result.toISOString()).toBe('2026-01-15T10:09:00.000Z')
  })

  it('returns 16 minute delay for retryCount 3', () => {
    // Formula: (3 + 1)^2 = 16 minutes
    const result = computeRetryNextRunAt(3)
    expect(result.toISOString()).toBe('2026-01-15T10:16:00.000Z')
  })
})
