import { test } from '@japa/runner'
import { Organization } from '../../../../src/mocking/lib/Organization.js'
import { OrganizationKind } from '../../../../src/models/kinds.js'
import type { IOrganization } from '../../../../src/models/store/Organization.js'

test.group('Organization', (group) => {
  let organization: Organization

  group.each.setup(() => {
    organization = new Organization()
  })

  test('organization() returns a valid object', ({ assert }) => {
    const result = organization.organization()
    assert.typeOf(result, 'object')
    assert.equal(result.kind, OrganizationKind)
    assert.property(result, 'key')
    assert.property(result, 'name')
    assert.property(result, 'createdBy')
    assert.property(result, 'createdDate')
    assert.property(result, 'grantType')
  })

  test('organization(init) allows overriding properties', ({ assert }) => {
    const init: Partial<IOrganization> = {
      key: 'custom-org-key',
      name: 'Custom Org',
    }
    const result = organization.organization(init)
    assert.equal(result.key, 'custom-org-key')
    assert.equal(result.name, 'Custom Org')
  })

  test('organizations() returns a list', ({ assert }) => {
    const result = organization.organizations(5)
    assert.isArray(result)
    assert.lengthOf(result, 5)
  })

  test('organizations(size, init) allows overriding properties', ({ assert }) => {
    const init: Partial<IOrganization> = {
      name: 'Batch Org',
    }
    const result = organization.organizations(3, init)
    assert.lengthOf(result, 3)
    result.forEach((item) => {
      assert.equal(item.name, 'Batch Org')
    })
  })
})
