import { DQRule } from '../models/dq-rules.model'
import { hasFormulaRules } from './hasFormulaRules'

const rule = (overrides: Partial<DQRule>): DQRule => ({
  BASE_COL: 'SOME_COL',
  RULE_TYPE: 'NOTNULL',
  RULE_VALUE: '',
  X: 0,
  ...overrides
})

describe('hasFormulaRules', () => {
  it('is false for an empty rule set', () => {
    expect(hasFormulaRules([])).toBeFalse()
  })

  it('is false when no rule is HARDFORMULA/SOFTFORMULA', () => {
    const rules = [
      rule({ RULE_TYPE: 'NOTNULL' }),
      rule({ RULE_TYPE: 'HARDREGEX' }),
      rule({ RULE_TYPE: 'SOFTREGEX' })
    ]

    expect(hasFormulaRules(rules)).toBeFalse()
  })

  it('is true when a HARDFORMULA rule is present', () => {
    const rules = [rule({ RULE_TYPE: 'HARDFORMULA' })]

    expect(hasFormulaRules(rules)).toBeTrue()
  })

  it('is true when a SOFTFORMULA rule is present', () => {
    const rules = [rule({ RULE_TYPE: 'SOFTFORMULA' })]

    expect(hasFormulaRules(rules)).toBeTrue()
  })

  it('is true when a formula rule is mixed in with unrelated rules', () => {
    const rules = [
      rule({ RULE_TYPE: 'NOTNULL' }),
      rule({ RULE_TYPE: 'SOFTFORMULA' }),
      rule({ RULE_TYPE: 'HARDREGEX' })
    ]

    expect(hasFormulaRules(rules)).toBeTrue()
  })
})
