<commit_before>require "integration_spec_helper"

RSpec.feature "Person page" do
  before do
    name = "<NAME>"
    slug = "rufus-scrimgeour"
    base_path = "/government/people/#{slug}"

    stub_person_page_content_item(base_path, name)
    stub_person_page_search_query(slug)

    visit base_path
  end

  scenario "displays the person page" do
    expect(page).to have_title("Rufus Scrimgeour - GOV.UK")
  end

  scenario "shows schema.org Person structured data" do
    schema_sections = page.find_all("script[type='application/ld+json']", visible: false)
    schemas = schema_sections.map { |section| JSON.parse(section.text(:all)) }

    person_schema = schemas.detect { |schema| schema["@type"] == "Person" }
    expect("Rufus Scrimgeour").to eq(person_schema["name"])
  end

  def stub_person_page_content_item(base_path, name)
    content_item.merge!(
      "title" => name,
      "base_path" => base_path,
    )

    stub_content_store_has_item(base_path, content_item)
  end

  def stub_person_page_search_query(slug)
    stub_request(:get, "https://search.test.gov.uk/search.json")
      .with(query: {
        count: 10,
        fields: %w[content_store_document_type link public_timestamp title],
        filter_people: slug,
        order: "-public_timestamp",
        reject_content_purpose_supergroup: "other",
      })
      .to_return(body: { results: [] }.to_json)
  end

  def content_item
    @content_item ||= GovukSchemas::RandomExample.for_schema(frontend_schema: "person")
  end
end<commit_msg>Revert "Fix flaky person test"<commit_after>require "integration_spec_helper"

RSpec.feature "Person page" do
  before do
    name = "<NAME>"
    slug = "rufus-scrimgeour"
    base_path = "/government/people/#{slug}"

    stub_person_page_content_item(base_path, name)
    stub_person_page_search_query(slug)

    visit base_path
  end

  scenario "displays the person page" do
    expect(page).to have_title("Rufus Scrimgeour - GOV.UK")
  end

  scenario "shows schema.org Person structured data" do
    schema_sections = page.find_all("script[type='application/ld+json']", visible: false)
    schemas = schema_sections.map { |section| JSON.parse(section.text(:all)) }

    person_schema = schemas.detect { |schema| schema["@type"] == "Person" }
    expect("<NAME>").to eq(person_schema["name"])
  end

  def stub_person_page_content_item(base_path, name)
    content_item = GovukSchemas::RandomExample.for_schema(frontend_schema: "person").merge(
      "title" => name,
      "base_path" => base_path,
    )

    stub_content_store_has_item(base_path, content_item)
  end

  def stub_person_page_search_query(slug)
    stub_request(:get, "https://search.test.gov.uk/search.json")
      .with(query: {
        count: 10,
        fields: %w[content_store_document_type link public_timestamp title],
        filter_people: slug,
        order: "-public_timestamp",
        reject_content_purpose_supergroup: "other",
      })
      .to_return(body: { results: [] }.to_json)
  end
end
{'fraction_non_alphanumeric': 0.12050599201065246, 'fraction_numerical': 0.0013315579227696406, 'mean_word_length': 3.902120717781403, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, 'https://': 2, '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': '3489446', 'n_tokens_mistral': 1021, 'n_tokens_neox': 1003, 'n_words': 188}