import { test } from '@japa/runner'
import { Invitation } from '../../../../src/mocking/lib/Invitation.js'
import { InvitationKind } from '../../../../src/models/kinds.js'
import type { InvitationSchema } from '../../../../src/models/store/Invitation.js'

test.group('Invitation', (group) => {
  let invitation: Invitation

  group.each.setup(() => {
    invitation = new Invitation()
  })

  test('invitation() returns a valid object', ({ assert }) => {
    const result = invitation.invitation()
    assert.typeOf(result, 'object')
    assert.equal(result.kind, InvitationKind)
    assert.property(result, 'key')
    assert.property(result, 'email')
    assert.property(result, 'token')
    assert.property(result, 'status')
  })

  test('invitation(init) allows overriding properties', ({ assert }) => {
    const init: Partial<InvitationSchema> = {
      email: 'test@example.com',
      status: 'accepted',
    }
    const result = invitation.invitation(init)
    assert.equal(result.email, 'test@example.com')
    assert.equal(result.status, 'accepted')
  })

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

  test('invitations(size, init) allows overriding properties', ({ assert }) => {
    const init: Partial<InvitationSchema> = {
      status: 'declined',
    }
    const result = invitation.invitations(3, init)
    assert.lengthOf(result, 3)
    result.forEach((item) => {
      assert.equal(item.status, 'declined')
    })
  })
})
