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

test.group('EqualAssertion constructor()', () => {
  test('initializes from values', () => {
    const instance = new EqualAssertion('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 EqualAssertion('a')
    assert.equal(instance.value, 'a')
    assert.isUndefined(instance.dataType)
    assert.isUndefined(instance.strict)
  })

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

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

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

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

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

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

  test('serializes the dataType when set', () => {
    const instance = new EqualAssertion('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 EqualAssertion()
    assert.isUndefined(instance.dataType)
  })

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

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

  test('serializes the enabled when set', () => {
    const instance = new EqualAssertion('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 EqualAssertion()
    assert.isUndefined(instance.enabled)
  })
})
