<commit_before>require 'rails_helper'

RSpec.describe ErrorStore do
  let(:website) { create :website }
  let(:group) { create :grouped_issue, website: website }
  let(:subscriber) { create :subscriber, website: website }
  let!(:issue_error) { create :issue, subscriber: subscriber, group: group }
  let(:request) { post_error_request(website.app_key, website.app_secret, web_response_factory('ruby_exception')) }

  describe 'create!', truncation: true do
    it 'calls error.create!' do
      expect_any_instance_of(ErrorStore::Error).to receive(:create!)
      ErrorStore.create!(request)
    end
    it 'returns the error id' do
      event_id = ErrorStore.create!(request)
      expect(event_id).to be_kind_of(String)
      expect(event_id.length).to eq(32)
    end
  end

  describe 'find' do
    it 'calls error.find' do
      expect_any_instance_of(ErrorStore::Error).to receive(:find)
      subject.find(issue_error)
    end
    it 'returns the error record' do
      expect_any_instance_of(ErrorStore::Error).to receive(:find).and_return(issue_error)
      subject.find(issue_error)
    end
  end

  describe 'find_interfaces' do
    it 'contains all the interfaces in the folder' do
      expect(ErrorStore.find_interfaces.any? { |a| a.include?('query.rb' && 'frame.rb' && 'message.rb' && 'exception.rb' && 'stacktrace.rb' && 'template.rb' && 'template.rb' && 'user.rb' && 'single_exception.rb' && 'http.rb')
        }).to be(true)
      expect(ErrorStore.find_interfaces.length).to eq(9)
    end
  end

  describe 'available_interfaces' do
    it 'retuns assigns the interfaces_list'
    it 'returns the interfaces array' do
      expect(ErrorStore.find_interfaces).to eq(
        [
          "#{Dir.home}/epiclogger/lib/error_store/interfaces/query.rb",
          "#{Dir.home}/epiclogger/lib/error_store/interfaces/frame.rb",
          "#{Dir.home}/epiclogger/lib/error_store/interfaces/message.rb",
          "#{Dir.home}/epiclogger/lib/error_store/interfaces/exception.rb",
          "#{Dir.home}/epiclogger/lib/error_store/interfaces/stacktrace.rb",
          "#{Dir.home}/epiclogger/lib/error_store/interfaces/template.rb",
          "#{Dir.home}/epiclogger/lib/error_store/interfaces/user.rb",
          "#{Dir.home}/epiclogger/lib/error_store/interfaces/single_exception.rb",
          "#{Dir.home}/epiclogger/lib/error_store/interfaces/http.rb"
        ]
      )
    end
    xit 'gives the interfaces with all of them if find_interfaces called'
  end

  xdescribe 'interfaces_types' do
    it 'returns an array of interfaces types'
  end

  describe 'get_interface' do
    it 'raises ErrorStore::InvalidInterface if not found' do
      expect { ErrorStore.get_interface(:random) }.to raise_exception(ErrorStore::InvalidInterface)
    end
    it 'returns the interface'
  end

  describe 'constants' do
    it 'INTERFACES holds the interfaces' do
      expect(ErrorStore::INTERFACES).to eq(
        {
          :exception=>:exception,
          :logentry=>:message,
          :request=>:http,
          :stacktrace=>:stacktrace,
          :template=>:template,
          :query=>:query,
          :user=>:user,
          :csp=>:csp,
          :http=>:http,<commit_msg>change error_store specs<commit_after>require 'rails_helper'

RSpec.describe ErrorStore do
  let(:website) { create :website }
  let(:group) { create :grouped_issue, website: website }
  let(:subscriber) { create :subscriber, website: website }
  let!(:issue_error) { create :issue, subscriber: subscriber, group: group }
  let(:request) { post_error_request(website.app_key, website.app_secret, web_response_factory('ruby_exception')) }

  describe 'create!', truncation: true do
    it 'calls error.create!' do
      expect_any_instance_of(ErrorStore::Error).to receive(:create!)
      subject.create!(request)
    end
    it 'returns the error id' do
      event_id = subject.create!(request)
      expect(event_id).to be_kind_of(String)
      expect(event_id.length).to eq(32)
    end
  end

  describe 'find' do
    it 'calls error.find' do
      expect_any_instance_of(ErrorStore::Error).to receive(:find)
      subject.find(issue_error)
    end
    it 'returns the error record' do
      expect_any_instance_of(ErrorStore::Error).to receive(:find).and_return(issue_error)
      subject.find(issue_error)
    end
  end

  describe 'find_interfaces' do
    it 'contains all the interfaces in the folder' do
      interfaces = subject.find_interfaces
      check = interfaces.map do |i|
        true if i.match(/query|frame|message|exception|stacktrace|template|template|user|single_exception|http/)
      end.uniq
      expect(check).to eq([true])
      expect(interfaces.length).to eq(9)
    end
  end

  describe 'available_interfaces' do
    before { allow(ErrorStore::BaseInterface).to receive(:available).and_return(true) }

    it 'retuns assigns the interfaces_list' do
      # if we don't run the find_interfaces method then it's blank
      expect(subject.available_interfaces).to eq([])
      expect(subject.available_interfaces).to eq(subject.class_variable_get(:@@interfaces_list))
    end

    it 'returns the interfaces array' do
      expect(subject.available_interfaces).to be_kind_of(Array)
      expect(subject.available_interfaces.length).to eq(0)
    end

    it 'gives the interfaces with all of them if find_interfaces called' do
      subject.find_interfaces # we do a find of the interfaces and we should get them set now
      expect(subject.available_interfaces).to be_kind_of(Array)
      expect(subject.available_interfaces.length).to eq(9)
      expect(subject.available_interfaces).to eq(subject.class_variable_get(:@@interfaces_list))
    end
  end

  describe 'interfaces_types' do
    it 'returns an array of interfaces types' do
      allow(ErrorStore::BaseInterface).to receive(:available).and_return(true)
      subject.class_variable_set(:@@interfaces_list, []) # reset the interfaces list
      subject.find_interfaces

      expect(subject.interfaces_types).to eq([:exception, :frame, :http, :message, :query, :single_exception, :stacktrace, :template, :user])
    end
  end

  describe 'get_interface' do
    before do
      allow(ErrorStore::BaseInterface).to receive(:available).and_return(true)
      subject.find_interfaces
    end
    it 'raises ErrorStore::InvalidInterface if not found' do
      expect { subject.get_interface(:random) }.to raise_exception(ErrorStore::InvalidInterface)
    end

    it 'returns the interface' do
      expect(subject.get_interface(:exception)).to eq(ErrorStore::Interfaces::Exception)
    end
  end

  describe 'constants' do
    it 'INTERFACES holds the interfaces' do
      expect(ErrorStore::INTERFACES).to eq(
        {
          :exception=>:exception,
          :logentry=>:message,
          :request=>:http,
          :stacktrace=>:stacktrace,
          :template=>:template,
          :query=>:query,
          :user=>:user,
          :csp=>:csp,
          :http=>:http,
{'fraction_non_alphanumeric': 0.11664029915144541, 'fraction_numerical': 0.0011505824823817058, 'mean_word_length': 3.5185185185185186, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2824953', 'n_tokens_mistral': 2164, 'n_tokens_neox': 2117, 'n_words': 458}