import { test } from '@japa/runner'
import sinon from 'sinon'
import { Url } from '../../../../src/mocking/lib/Url.js'
import type { IUrl } from '../../../../src/index.js'

test.group('url()', (group) => {
  let urls: Url

  group.each.setup(() => {
    urls = new Url()
  })

  test('returns an object', ({ assert }) => {
    const result = urls.url()
    assert.typeOf(result, 'object')
  })

  test('has the {property} property of a type {type}')
    .with([
      { property: 'key', type: 'string' },
      { property: 'time', type: 'number' },
      { property: 'cnt', type: 'number' },
      { property: 'midnight', type: 'number' },
    ])
    .run(({ assert }, { property, type }) => {
      const result = urls.url()
      assert.typeOf(result[property as keyof IUrl], type)
    })
})

test.group('urls()', (group) => {
  let urls: Url

  group.each.setup(() => {
    urls = new Url()
  })

  test('returns an array', ({ assert }) => {
    const result = urls.urls()
    assert.typeOf(result, 'array')
  })

  test('returns the default number of items', ({ assert }) => {
    const result = urls.urls()
    assert.lengthOf(result, 25)
  })

  test('returns requested number of items', ({ assert }) => {
    const result = urls.urls(5)
    assert.lengthOf(result, 5)
  })

  test('calls url()', ({ assert }) => {
    const spy = sinon.spy(urls, 'url')
    urls.urls(5)
    assert.equal(spy.callCount, 5)
  })
})
