/**
 * Smoke tests for the CSRF token holder.
 * These run in isolation (no DOM, no React) and validate the module contract.
 */

import { describe, it, expect, beforeEach } from 'vitest'
import { setCsrfToken, getCsrfToken } from './csrf'

describe('csrf holder', () => {
  beforeEach(() => {
    // Reset to empty between tests by setting empty string
    setCsrfToken('')
  })

  it('returns empty string before any token is set', () => {
    expect(getCsrfToken()).toBe('')
  })

  it('stores and returns the token that was set', () => {
    setCsrfToken('test-token-abc123')
    expect(getCsrfToken()).toBe('test-token-abc123')
  })

  it('overwrites a previously set token', () => {
    setCsrfToken('first')
    setCsrfToken('second')
    expect(getCsrfToken()).toBe('second')
  })

  it('can be reset to empty', () => {
    setCsrfToken('some-token')
    setCsrfToken('')
    expect(getCsrfToken()).toBe('')
  })
})
