import { test } from '@japa/runner'
import { AllowAuthenticatedAccessRule } from '../../../../src/modeling/rules/AllowAuthenticated.js'

test.group('AllowAuthenticatedAccessRule', () => {
  test('initializes with correct type', ({ assert }) => {
    const rule = new AllowAuthenticatedAccessRule()
    assert.equal(rule.type, 'allowAuthenticated')
  }).tags(['@modeling', '@rule', '@allow-authenticated'])

  test('toJSON returns valid schema', ({ assert }) => {
    const rule = new AllowAuthenticatedAccessRule()
    const json = rule.toJSON()

    assert.equal(json.type, 'allowAuthenticated')
  }).tags(['@modeling', '@rule', '@allow-authenticated', '@serialization'])

  test('notifies change', async ({ assert }) => {
    const rule = new AllowAuthenticatedAccessRule()
    let notified = false
    rule.addEventListener('change', () => {
      notified = true
    })

    rule.notifyChange()
    await Promise.resolve()
    assert.isTrue(notified)
  }).tags(['@modeling', '@rule', '@allow-authenticated', '@observed'])
})
