<commit_before>require 'rails_helper'

RSpec.describe RootBrowsePagePresenter do

  describe "#render_for_publishing_api" do
    it "raises a RunTimeError if top-level browse pages are not present" do
      expect {
        RootBrowsePagePresenter.new.render_for_publishing_api
      }.to raise_error(RuntimeError)
    end

    context "with top level browse pages" do

      let!(:top_level_page_1) { create(
        :mainstream_browse_page,
        :title => "Top-Level Page 1",
      )}
      let!(:top_level_page_2) { create(
        :mainstream_browse_page,
        :title => "Top-Level Page 2",
      )}

      let(:rendered) { RootBrowsePagePresenter.new.render_for_publishing_api}

      it "is valid against the schema" do
        expect(rendered).to be_valid_against_schema('mainstream_browse_page')
      end

      it "includes all the top-level browse pages" do
        expect(rendered[:links]["top_level_browse_pages"]).to eq([
          top_level_page_1.content_id,
          top_level_page_2.content_id,
        ])
      end

      context "top_level_page_1 updated before top_level_page_2" do
        it "#public_updated_at should equal most recent #updated_time" do
          Timecop.travel 3.hours.ago do
            top_level_page_1.touch
          end
          top_level_page_2.touch

          expect(rendered[:public_updated_at]).to eq(
            top_level_page_2.updated_at.iso8601
          )
        end
      end
    end
  end
end
<commit_msg>Refactor RootBrowsePagePresenter spec<commit_after>require 'rails_helper'

RSpec.describe RootBrowsePagePresenter do
  describe "#render_for_publishing_api" do
    it "raises if top-level browse pages are not present" do
      expect {
        RootBrowsePagePresenter.new.render_for_publishing_api
      }.to raise_error(RuntimeError)
    end

    it "is valid against the schema" do
      create(:mainstream_browse_page, title: "Top-Level Page 1")
      create(:mainstream_browse_page, title: "Top-Level Page 2")

      rendered = RootBrowsePagePresenter.new.render_for_publishing_api

      expect(rendered).to be_valid_against_schema('mainstream_browse_page')
    end

    it "includes draft and published top-level browse pages" do
      page_1 = create(:mainstream_browse_page, :published, title: "Top-Level Page 1")
      page_2 = create(:mainstream_browse_page, :draft, title: "Top-Level Page 2")

      rendered = RootBrowsePagePresenter.new.render_for_publishing_api

      expect(rendered[:links]["top_level_browse_pages"]).to eq([
        page_1.content_id,
        page_2.content_id,
      ])
    end

    it ":public_updated_at equals the time of last browse page update" do
      page_1 = create(:mainstream_browse_page, title: "Top-Level Page 1")
      page_2 = create(:mainstream_browse_page, title: "Top-Level Page 2")

      Timecop.travel 3.hours.ago do
        page_1.touch
      end
      page_2.touch

      rendered = RootBrowsePagePresenter.new.render_for_publishing_api

      expect(rendered[:public_updated_at]).to eq(page_2.updated_at.iso8601)
    end
  end
end

{'fraction_non_alphanumeric': 0.07998694090760693, 'fraction_numerical': 0.011753183153770812, 'mean_word_length': 3.074468085106383, 'pattern_counts': {'":': 1, '<': 3, '<?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': '1210512', 'n_tokens_mistral': 1033, 'n_tokens_neox': 961, 'n_words': 212}