import { readFileSync, existsSync } from 'node:fs'
import { resolve, dirname } from 'node:path'
import { fileURLToPath } from 'node:url'
import { describe, it, expect } from 'vitest'

const __dirname = dirname(fileURLToPath(import.meta.url))
const projectRoot = resolve(__dirname, '../..')

describe('map and geolocation config', () => {
  it('Permissions-Policy allows geolocation so browser can prompt', () => {
    const configPath = resolve(projectRoot, 'nuxt.config.js')
    const source = readFileSync(configPath, 'utf-8')
    expect(source).toContain('geolocation=(self)')
    expect(source).not.toMatch(/Permissions-Policy[^']*geolocation=\s*\(\s*\)/)
  })

  it('Leaflet marker assets exist in public so /marker-icon*.png are served', () => {
    const publicDir = resolve(projectRoot, 'public')
    expect(existsSync(resolve(publicDir, 'marker-icon.png'))).toBe(true)
    expect(existsSync(resolve(publicDir, 'marker-icon-2x.png'))).toBe(true)
    expect(existsSync(resolve(publicDir, 'marker-shadow.png'))).toBe(true)
  })
})
