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

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

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

  test('initializes from the schema', () => {
    const instance = new GreaterThanAssertion({
      kind: GreaterThanAssertionKind,
      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 GreaterThanAssertion()
    assert.equal(instance.kind, GreaterThanAssertionKind)
    assert.isUndefined(instance.enabled)
    assert.isUndefined(instance.value)
    assert.isUndefined(instance.equal)
  })
})

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

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

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

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

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

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

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

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

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