const test = require('node:test')
const assert = require('node:assert')
const { normalizeIdTokenForBearerHeader } = require('../src/lib/auth')

const jwt = 'a.b.c'

test('normalizeIdTokenForBearerHeader strips one Bearer prefix', () => {
  assert.strictEqual(normalizeIdTokenForBearerHeader(`Bearer ${jwt}`), jwt)
})

test('normalizeIdTokenForBearerHeader strips repeated Bearer prefixes', () => {
  assert.strictEqual(normalizeIdTokenForBearerHeader(`Bearer Bearer ${jwt}`), jwt)
})

test('normalizeIdTokenForBearerHeader handles Authorization header line', () => {
  assert.strictEqual(
    normalizeIdTokenForBearerHeader(`Authorization: Bearer ${jwt}`),
    jwt,
  )
})

test('normalizeIdTokenForBearerHeader strips quotes then Bearer', () => {
  assert.strictEqual(normalizeIdTokenForBearerHeader(`"Bearer ${jwt}"`), jwt)
})
