import { test } from '@japa/runner'
import { createLogger, CoreEngine, IHttpRequest, HttpEngineOptions, HostRuleKind } from '../../../../src/index.js'

const logger = createLogger()

test.group('Hosts evaluation', () => {
  test('alters the uri', ({ assert }) => {
    const opts: HttpEngineOptions = {
      timeout: 50000,
      followRedirects: false,
      hosts: [
        {
          kind: HostRuleKind,
          from: 'domain.com',
          to: 'test.com',
          key: '1',
        },
      ],
      logger,
    }
    const request: IHttpRequest = {
      url: `https://domain.com/api/endpoint?query=param`,
      method: 'GET',
    }
    const engine = new CoreEngine(request, opts)
    assert.equal(engine.uri.hostname, 'test.com')
  })
})
