import { test } from '@japa/runner'
import sinon from 'sinon'
import { Authorization } from '../../../../src/mocking/legacy/Authorization.js'
import type { ARCAuthData } from '../../../../src/legacy.js'

test.group('basic()', (group) => {
  let auth: Authorization

  group.each.setup(() => {
    auth = new Authorization()
  })

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

  test('has the {property} property of a type {type}')
    .with([
      { property: '_id', type: 'string' },
      { property: 'username', type: 'string' },
      { property: 'password', type: 'string' },
    ])
    .run(({ assert }, { property, type }) => {
      const result = auth.basic()
      assert.typeOf(result[property as keyof ARCAuthData], type)
    })
})

test.group('basicList()', (group) => {
  let auth: Authorization

  group.each.setup(() => {
    auth = new Authorization()
  })

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

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

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

  test('calls basic() method', ({ assert }) => {
    const spy = sinon.spy(auth, 'basic')
    auth.basicList(5)
    assert.equal(spy.callCount, 5)
  })
})
