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

test.group('NotEqualAssertion constructor()', () => {
  test('initializes from values', () => {
    const instance = new NotEqualAssertion('a', true, 'http://www.w3.org/2001/XMLSchema#string')
    assert.equal(instance.value, 'a')
    assert.equal(instance.dataType, 'http://www.w3.org/2001/XMLSchema#string')
    assert.isTrue(instance.strict)
    assert.isTrue(instance.enabled)
  })

  test('ignores not set values', () => {
    const instance = new NotEqualAssertion('a')
    assert.equal(instance.value, 'a')
    assert.isUndefined(instance.dataType)
    assert.isUndefined(instance.strict)
  })

  test('initializes from the schema', () => {
    const instance = new NotEqualAssertion({
      kind: NotEqualAssertionKind,
      value: 'a',
      strict: false,
      dataType: 'http://www.w3.org/2001/XMLSchema#boolean',
      enabled: false,
    })
    assert.equal(instance.value, 'a')
    assert.equal(instance.dataType, 'http://www.w3.org/2001/XMLSchema#boolean')
    assert.isFalse(instance.strict)
    assert.isFalse(instance.enabled)
  })

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

test.group('NotEqualAssertion checkValidity()', () => {
  test('returns true when has the value', () => {
    const instance = new NotEqualAssertion('a', true, 'http://www.w3.org/2001/XMLSchema#string')
    assert.isTrue(instance.checkValidity())
  })

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

test.group('NotEqualAssertion toJSON()', () => {
  test('serializes the kind', () => {
    const instance = new NotEqualAssertion('a', true, 'http://www.w3.org/2001/XMLSchema#string')
    assert.equal(instance.kind, NotEqualAssertionKind)
  })

  test('serializes the value when set', () => {
    const instance = new NotEqualAssertion('a', true, 'http://www.w3.org/2001/XMLSchema#string')
    assert.equal(instance.value, 'a')
  })

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

  test('serializes the dataType when set', () => {
    const instance = new NotEqualAssertion('a', true, 'http://www.w3.org/2001/XMLSchema#string')
    assert.equal(instance.dataType, 'http://www.w3.org/2001/XMLSchema#string')
  })

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

  test('serializes the strict when set', () => {
    const instance = new NotEqualAssertion('a', true, 'http://www.w3.org/2001/XMLSchema#string')
    assert.isTrue(instance.strict)
  })

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

  test('serializes the enabled when set', () => {
    const instance = new NotEqualAssertion('a', true, 'http://www.w3.org/2001/XMLSchema#string')
    instance.enabled = true
    assert.isTrue(instance.enabled)
  })

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