<commit_before>require 'spec_helper'

describe ConversationsArchive do
  before do
    @account = build(:account)
    @conversations = [] 
    @messages = []

    # Create three conversations and three unique messages
    0.upto(2) do |i|
      @conversations.push create(:conversation, account: @account)
      message = create(:message, conversation: @conversations[i], content: "test #{i}")
      
      # Need to have consistent ids for VCR to work
      message.id = "c91d36fb-c406-4a06-a9b0-808c64b80e8#{i}"
      message.save!
      @messages.push message
    end

    # Create indices in Elasticsearch if not provided from VCR
    if !File.exists? Rails.root.join('spec', 'vcr', 'update_search_index.yml')
      VCR.use_cassette('update_search_index') do
        @messages.each { |message| message.__elasticsearch__.index_document }
      end
    end
  end

  describe "search" do
    it "should get conversations in elastic search order" do
      @archive = ConversationsArchive.new(@account, 'test')
      VCR.use_cassette('search_all') do
        # Test for messages/conversations in order of most recently updated
        assert_equal @archive.search_messages.to_a, @messages.sort { |a,b| b.updated_at <=> a.updated_at }
        assert_equal @archive.conversations, @conversations.sort { |a,b| b.updated_at <=> a.updated_at }
      end
    end

    it "should get specific conversations by message content" do
      @archive = ConversationsArchive.new(@account, '0')
      VCR.use_cassette('search_specific') do
        # Test for messages/conversations that match the query term
        assert_equal @archive.search_messages.to_a, [@messages.first]
        assert_equal @archive.conversations, [@conversations.first]
      end
    end
  end

end<commit_msg>Revamp conversation search specs and temporarily remove vcr<commit_after>require 'spec_helper'

describe ConversationsArchive do
  let!(:account) { create(:account) }

  let!(:conversations) {
    Array.new(3) do
      create(:conversation, account: account)
    end
  }

  let!(:messages) {
    Array.new(3) do |i|
      message = create(
        :message,
        conversation: conversations[i],
        content: "test #{i}"
      )

      message.id = "c91d36fb-c406-4a06-a9b0-808c64b80e8#{i}"
      message.save!

      message
    end
  }

  before { Message.import(force: true, refresh: true) }

  describe "search" do
    it "receives multiple messages and conversations" do
      archive = ConversationsArchive.new(account, 'test')

      expect(archive.search_messages.to_a).to match_array(messages)
      expect(archive.conversations).to match_array(conversations)
    end

    it "receives specific conversations by message content" do
      archive = ConversationsArchive.new(account, '0')

      expect(archive.search_messages.first).to eq(messages.first)
      expect(archive.conversations.first).to eq(conversations.first)
    end
  end

end
{'fraction_non_alphanumeric': 0.10321257689678742, 'fraction_numerical': 0.01572112098427888, 'mean_word_length': 3.2792397660818713, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6803507', 'n_tokens_mistral': 935, 'n_tokens_neox': 894, 'n_words': 219}