import { describe, it, expect, afterEach } from 'vitest'
import { prisma } from '../../lib/prisma.js'

describe('OAuth — User model fields', () => {
  const createdIds = []

  afterEach(async () => {
    for (const id of createdIds) {
      try {
        await prisma.user.delete({ where: { id } })
      } catch {
        // Already deleted by another test or cleanup — ignore
      }
    }
    createdIds.length = 0
  })

  it('stores displayName and avatar fields on User model', async () => {
    const user = await prisma.user.create({
      data: {
        email: 'test-oauth@example.com',
        displayName: 'Test User',
        avatar: 'https://example.com/avatar.jpg',
      },
    })

    createdIds.push(user.id)

    expect(user.displayName).toBe('Test User')
    expect(user.avatar).toBe('https://example.com/avatar.jpg')
  })

  it('allows nullable fields', async () => {
    const user = await prisma.user.create({
      data: {
        email: 'test-oauth-null@example.com',
      },
    })

    createdIds.push(user.id)

    expect(user.displayName).toBeNull()
    expect(user.avatar).toBeNull()
  })
})
