import { test } from '@japa/runner'
import { assert } from '@esm-bundle/chai'
import {
  ToBeAssertion,
  ToBeAssertionKind,
  ToBeTypes,
} from '../../../../../src/models/http-flows/steps/assertion/ToBeAssertion.js'
test.group('ToBeAssertion constructor()', () => {
  test('initializes from values', () => {
    const instance = new ToBeAssertion(ToBeTypes.number)
    assert.equal(instance.value, ToBeTypes.number)
    assert.isTrue(instance.enabled)
  })

  test('initializes from the schema', () => {
    const instance = new ToBeAssertion({
      kind: ToBeAssertionKind,
      value: ToBeTypes.number,
      enabled: false,
    })
    assert.equal(instance.value, ToBeTypes.number)
    assert.isFalse(instance.enabled)
  })

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

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

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

test.group('ToBeAssertion toJSON()', () => {
  test('serializes the kind', () => {
    const instance = new ToBeAssertion(ToBeTypes.number)
    assert.equal(instance.kind, ToBeAssertionKind)
  })

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

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

  test('serializes the enabled when set', () => {
    const instance = new ToBeAssertion(ToBeTypes.number)
    instance.enabled = true
    assert.isTrue(instance.enabled)
  })

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