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

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

  test('ignores not set values', () => {
    const instance = new LessThanAssertion(5)
    assert.equal(instance.value, 5)
    assert.isUndefined(instance.equal)
  })

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

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

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

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

test.group('LessThanAssertion toJSON()', () => {
  test('serializes the kind', () => {
    const instance = new LessThanAssertion(10, true)
    assert.equal(instance.kind, LessThanAssertionKind)
  })

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

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

  test('serializes the equal when set', () => {
    const instance = new LessThanAssertion(10, true)
    assert.isTrue(instance.equal)
  })

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

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

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