// @vitest-environment happy-dom
import { describe, it, expect } from 'vitest'

import CredentialCard from '../../src/components/subscriptions/CredentialCard.vue'
import { freshPinia, mountComponent } from '../support/mountComponent.js'

const platform = { key: 'patreon', name: 'Patreon', auth_type: 'cookies' }

describe('CredentialCard', () => {
  it('renders the last-verified row when last_verified is set', () => {
    // Regression guard: the field was once read as last_verified_at, so the
    // row silently never rendered.
    const pinia = freshPinia()
    const recent = new Date(Date.now() - 2 * 86400_000).toISOString()
    const credential = {
      platform: 'patreon', credential_type: 'cookies',
      captured_at: recent, expires_at: null, last_verified: recent,
    }
    const w = mountComponent(CredentialCard, { props: { platform, credential }, pinia })
    expect(w.text()).toContain('Last verified')
  })

  it('renders the empty state with no credential', () => {
    const pinia = freshPinia()
    const w = mountComponent(CredentialCard, { props: { platform, credential: null }, pinia })
    expect(w.text()).toContain('No credential stored')
  })
})
