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

const logger = createLogger()

test.group('GET requests', (group) => {
  let request: IHttpRequest
  let opts: HttpEngineOptions

  group.each.setup((ctx) => {
    request = {
      url: `http://localhost:${ctx.context.httpConfig.httpPort}/v1/tests/`,
      method: 'GET',
      headers: 'Host: test.com',
    }
    opts = {
      timeout: 50000,
      followRedirects: false,
      logger,
    }
  })

  test('makes a GET request', async ({ assert }) => {
    const engine = new CoreEngine(request, opts)
    const info = await engine.send()
    assert.ok(info)
  })

  test('makes a delayed GET request', async ({ assert }) => {
    request.url += '?delay=300'
    const engine = new CoreEngine(request, opts)
    const info = await engine.send()
    assert.ok(info)
  })
})
