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

const logger = createLogger()

test.group('Status codes', () => {
  test('results with 200', async ({ assert, httpConfig }) => {
    const engine = new CoreEngine(
      {
        url: `http://localhost:${httpConfig.httpPort}/v1/code/200`,
        method: 'GET',
      },
      { logger }
    )
    const info = await engine.send()
    assert.ok(info.response, 'has the response')
    assert.equal(info.response!.status, 200)
  })

  test('results with 201', async ({ assert, httpConfig }) => {
    const engine = new CoreEngine(
      {
        url: `http://localhost:${httpConfig.httpPort}/v1/code/201`,
        method: 'GET',
      },
      { logger }
    )
    const info = await engine.send()
    assert.ok(info.response, 'has the response')
    assert.equal(info.response!.status, 201)
  })

  test('results with 202', async ({ assert, httpConfig }) => {
    const engine = new CoreEngine(
      {
        url: `http://localhost:${httpConfig.httpPort}/v1/code/202`,
        method: 'GET',
      },
      { logger }
    )
    const info = await engine.send()
    assert.ok(info.response, 'has the response')
    assert.equal(info.response!.status, 202)
  })

  test('results with 204', async ({ assert, httpConfig }) => {
    const engine = new CoreEngine(
      {
        url: `http://localhost:${httpConfig.httpPort}/v1/code/204`,
        method: 'GET',
      },
      { logger }
    )
    const info = await engine.send()
    assert.ok(info.response, 'has the response')
    assert.equal(info.response!.status, 204)
  })
})
