import { describe, expect, it } from 'vitest'
import { generateMentorObjectKey } from '../../src/lib/minio'

describe('generateMentorObjectKey', () => {
  it('produces a path under <projectName>/mentorship/<timestamp>-<file>', () => {
    const key = generateMentorObjectKey('Revamp Flips', 'meeting-notes.pdf')
    expect(key).toMatch(/^Revamp_Flips\/mentorship\/\d+-meeting-notes\.pdf$/)
  })

  it('sanitizes special characters in the project title', () => {
    const key = generateMentorObjectKey('Côté & Bro 2026!', 'file.pdf')
    expect(key.startsWith('Ct_Bro_2026/mentorship/')).toBe(true)
  })

  it('sanitizes special characters in the file name', () => {
    const key = generateMentorObjectKey('Project', 'rapport final 2026 — version 2.docx')
    expect(key).toMatch(/^Project\/mentorship\/\d+-rapport_final_2026___version_2\.docx$/)
  })

  it('falls back to "unnamed" for an empty project title', () => {
    const key = generateMentorObjectKey('', 'doc.pdf')
    expect(key.startsWith('unnamed/mentorship/')).toBe(true)
  })

  it('uses a different timestamp for sequential calls in different milliseconds', async () => {
    const a = generateMentorObjectKey('P', 'a.pdf')
    await new Promise((r) => setTimeout(r, 5))
    const b = generateMentorObjectKey('P', 'a.pdf')
    expect(a).not.toEqual(b)
  })
})
