import { test } from '@japa/runner'
import { assert } from '@esm-bundle/chai'
import {
  IncludesAssertion,
  IncludesAssertionKind,
} from '../../../../../src/models/http-flows/steps/assertion/IncludesAssertion.js'

test.group('IncludesAssertion constructor()', () => {
  test('initializes from values', () => {
    const instance = new IncludesAssertion('test-value')
    assert.equal(instance.value, 'test-value')
    assert.isTrue(instance.enabled)
  })

  test('initializes from the schema', () => {
    const instance = new IncludesAssertion({
      kind: IncludesAssertionKind,
      value: 'test-value',
      enabled: false,
    })
    assert.equal(instance.value, 'test-value')
    assert.isFalse(instance.enabled)
  })

  test('initializes empty class', () => {
    const instance = new IncludesAssertion()
    assert.equal(instance.kind, IncludesAssertionKind)
    assert.isUndefined(instance.enabled)
    assert.isUndefined(instance.value)
  })
})

test.group('IncludesAssertion checkValidity()', () => {
  test('returns true when has the value', () => {
    const instance = new IncludesAssertion('test-value')
    assert.isTrue(instance.checkValidity())
  })

  test('returns false when has no value', () => {
    const instance = new IncludesAssertion()
    assert.isFalse(instance.checkValidity())
  })
})

test.group('IncludesAssertion toJSON()', () => {
  test('serializes the kind', () => {
    const instance = new IncludesAssertion('test-value')
    assert.equal(instance.kind, IncludesAssertionKind)
  })

  test('serializes the value when set', () => {
    const instance = new IncludesAssertion('test-value')
    assert.equal(instance.value, 'test-value')
  })

  test('ignores the value when not set', () => {
    const instance = new IncludesAssertion()
    assert.isUndefined(instance.value)
  })

  test('serializes the enabled when set', () => {
    const instance = new IncludesAssertion('test-value')
    instance.enabled = true
    assert.isTrue(instance.enabled)
  })

  test('ignores the enabled when not set', () => {
    const instance = new IncludesAssertion()
    assert.isUndefined(instance.enabled)
  })
})
