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

test.group('NotToBeAssertion constructor()', () => {
  test('initializes from values', () => {
    const instance = new NotToBeAssertion(ToBeTypes.number)
    assert.equal(instance.value, ToBeTypes.number)
    assert.isTrue(instance.enabled)
  })

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

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

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

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

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

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

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

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

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