require 'brakeman/scanner'

RSpec.describe Inquisition::Brakeman::Vulnerability do
  describe '#to_h' do
    subject(:vulnerability) { described_class.new(warning) }

    let(:message) do
      instance_double(Brakeman::Messages::Message, to_s: 'Potentially dangerous key allowed for mass assignment')
    end
    let(:warning) do
      instance_double(
        Brakeman::Warning,
        confidence: confidence,
        line: 42,
        relative_path: 'app/controllers/users_controller.rb',
        message: message,
        warning_type: 'Cross-Site Scripting'
      )
    end
    let(:options) do
      {
        severity: severity,
        message: message.to_s,
        path: warning.relative_path,
        line: warning.line,
        context: warning.warning_type
      }
    end

    context 'when warning confidence is 0' do
      let(:confidence) { 0 }
      let(:severity) { Inquisition::Severity::HIGH }

      it { expect(vulnerability.to_h).to include(options) }
    end

    context 'when warning confidence is 1' do
      let(:confidence) { 1 }
      let(:severity) { Inquisition::Severity::MEDIUM }

      it { expect(vulnerability.to_h).to include(options) }
    end

    context 'when warning confidence is 2' do
      let(:confidence) { 2 }
      let(:severity) { Inquisition::Severity::LOW }

      it { expect(vulnerability.to_h).to include(options) }
    end
  end
end
