import { test } from '@japa/runner'
import { assert } from '@esm-bundle/chai'
import { RoundStep, RoundStepKind } from '../../../../../src/models/http-flows/steps/transformation/RoundStep.js'

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

  test('initializes from the schema', () => {
    const instance = new RoundStep({
      kind: RoundStepKind,
      precision: 5,
      enabled: false,
    })
    assert.equal(instance.precision, 5)
    assert.isFalse(instance.enabled)
  })

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

test.group('RoundStep checkValidity()', () => {
  test('returns true with value', () => {
    const instance = new RoundStep(10)
    assert.isTrue(instance.checkValidity())
  })

  test('returns true when has no value', () => {
    const instance = new RoundStep()
    // default to 0
    assert.isTrue(instance.checkValidity())
  })
})

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

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

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

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

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