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

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

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

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

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

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

test.group('MatchesAssertion toJSON()', () => {
  test('serializes the kind', () => {
    const instance = new MatchesAssertion('test-value')
    assert.equal(instance.kind, MatchesAssertionKind)
  })

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

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

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

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