<commit_before>require "test_helper"
require "indexer"

describe Indexer::DocumentPreparer do
  describe "#prepared" do
    let(:doc_hash) { {"link" => "some-slug" } }

    before do
      Indexer::TagLookup.stubs(:prepare_tags).returns(doc_hash)
    end

    describe "alpha taxonomies" do
      it "adds an alpha taxonomy to the doc if a match is found" do
        ::TaxonomyPrototype::TaxonFinder.stubs(:find_by).returns(["taxon-1", "taxon-2"])

        updated_doc_hash = Indexer::DocumentPreparer.new("fake_client").prepared(doc_hash, nil, true)
        assert_equal doc_hash.merge("alpha_taxonomy" => ["taxon-1", "taxon-2"]), updated_doc_hash
      end

      it "does nothing to the doc if no match is found" do
        ::TaxonomyPrototype::TaxonFinder.stubs(:find_by).returns(nil)

        updated_doc_hash = Indexer::DocumentPreparer.new("fake_client").prepared(doc_hash, nil, true)
        assert_equal doc_hash, updated_doc_hash
      end
    end
  end
end<commit_msg>Simplify tests for document preparer<commit_after>require "test_helper"
require "indexer"

describe Indexer::DocumentPreparer do
  describe "#prepared" do
    describe "alpha taxonomies" do
      before do
        Indexer::TagLookup.stubs(:prepare_tags).returns({"link" => "some-slug" })
      end

      it "adds an alpha taxonomy to the doc if a match is found" do
        ::TaxonomyPrototype::TaxonFinder.stubs(:find_by).returns(["taxon-1", "taxon-2"])

        updated_doc_hash = Indexer::DocumentPreparer.new("fake_client").prepared({}, nil, true)

        assert_equal ["taxon-1", "taxon-2"], updated_doc_hash['alpha_taxonomy']
      end

      it "does nothing to the doc if no match is found" do
        ::TaxonomyPrototype::TaxonFinder.stubs(:find_by).returns(nil)

        updated_doc_hash = Indexer::DocumentPreparer.new("fake_client").prepared({}, nil, true)

        assert_nil updated_doc_hash['alpha_taxonomy']
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.11956521739130435, 'fraction_numerical': 0.004140786749482402, 'mean_word_length': 3.808457711442786, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 6, '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': '4253704', 'n_tokens_mistral': 628, 'n_tokens_neox': 610, 'n_words': 141}