<commit_before># frozen_string_literal: true

require 'rails_helper'

describe 'api/pages' do
  def json
    JSON.parse(response.body)
  end

  let(:expected) do
    %w[
      id
      title
      slug
      content
      created_at
      updated_at
      publish_status
      campaign_action_count
      action_count
      language
      featured
      image
      imageset
      url
      donation_page
      plugin_names
      percentage_completed
    ]
  end

  describe 'GET index' do
    before do
      create(:page, :published, title: 'Foo', content: 'Bar')
    end

    subject { JSON.parse(response.body) }
    before { get('/api/pages.json') }

    it 'returns list of pages' do
      expect(subject.size).to eq(1)
      expect(subject.first.keys).to match_array(expected)
      expect(subject.first.symbolize_keys).to include(title: 'Foo',
                                                      content: 'Bar')
    end
  end

  describe 'GET featured' do
    before do
      create(:page, :published, featured: true, title: 'Foo', content: 'Bar')
      create(:page, featured: false)
    end

    subject { JSON.parse(response.body) }
    before { get(featured_api_pages_path(format: :json)) }

    it 'returns list of pages' do
      expect(subject.size).to eq(1)
      expect(subject.first.keys).to match_array(expected)
      expect(subject.first.symbolize_keys).to include(title: 'Foo',
                                                      content: 'Bar')
    end
  end

  describe 'GET show' do
    let(:page) { create(:page, title: 'Foo', content: 'Bar') }

    subject { JSON.parse(response.body) }

    before { get(api_page_path(page, format: :json)) }

    it 'returns page' do
      expected = %w[
        id
        title
        slug
        content
        created_at
        updated_at
        publish_status
        featured
        action_count
        language
        campaign_action_count
        share_buttons
        sources
        meta_description
        template_name
        follow_up_template
      ]
      expect(subject.keys).to match_array(expected)
      expect(subject.symbolize_keys).to include(title: 'Foo',
                                                id: page.id)
    end
  end

  describe 'GET actions' do
    let(:page) { create :page }
    let!(:actions) do
      %i[default published hidden].map do |status|
        create :action, page: page, publish_status: status, form_data: { action_foo: status }
      end
    end

    subject { get api_page_actions_path(page) }

    it 'returns a 403 if the page publish_actions is secure' do
      page.update!(publish_actions: :secure)
      subject
      expect(response.code).to eq '403'
      expect(response.body).to be_empty
    end<commit_msg>fixed expected page returns-test case<commit_after># frozen_string_literal: true

require 'rails_helper'

describe 'api/pages' do
  def json
    JSON.parse(response.body)
  end

  let(:expected) do
    %w[
      id
      title
      slug
      content
      created_at
      updated_at
      publish_status
      campaign_action_count
      action_count
      language
      featured
      image
      imageset
      url
      donation_page
      plugin_names
      percentage_completed
    ]
  end

  describe 'GET index' do
    before do
      create(:page, :published, title: 'Foo', content: 'Bar')
    end

    subject { JSON.parse(response.body) }
    before { get('/api/pages.json') }

    it 'returns list of pages' do
      expect(subject.size).to eq(1)
      expect(subject.first.keys).to match_array(expected)
      expect(subject.first.symbolize_keys).to include(title: 'Foo',
                                                      content: 'Bar')
    end
  end

  describe 'GET featured' do
    before do
      create(:page, :published, featured: true, title: 'Foo', content: 'Bar')
      create(:page, featured: false)
    end

    subject { JSON.parse(response.body) }
    before { get(featured_api_pages_path(format: :json)) }

    it 'returns list of pages' do
      expect(subject.size).to eq(1)
      expect(subject.first.keys).to match_array(expected)
      expect(subject.first.symbolize_keys).to include(title: 'Foo',
                                                      content: 'Bar')
    end
  end

  describe 'GET show' do
    let(:page) { create(:page, title: 'Foo', content: 'Bar') }

    subject { JSON.parse(response.body) }

    before { get(api_page_path(page, format: :json)) }

    it 'returns page' do
      expected = %w[
        id
        title
        slug
        content
        created_at
        updated_at
        publish_status
        featured
        action_count
        language
        campaign_action_count
        share_buttons
        shares
        sources
        meta_description
        template_name
        follow_up_template
      ]
      expect(subject.keys).to match_array(expected)
      expect(subject.symbolize_keys).to include(title: 'Foo',
                                                id: page.id)
    end
  end

  describe 'GET actions' do
    let(:page) { create :page }
    let!(:actions) do
      %i[default published hidden].map do |status|
        create :action, page: page, publish_status: status, form_data: { action_foo: status }
      end
    end

    subject { get api_page_actions_path(page) }

    it 'returns a 403 if the page publish_actions is secure' do
      page.update!(publish_actions: :secure)
      subject
      expect(response.code).to eq '403'
      expect(response.body).to be_empty
    end
{'fraction_non_alphanumeric': 0.09087624209575429, 'fraction_numerical': 0.002890695573622403, 'mean_word_length': 2.007061379684954, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2246261', 'n_tokens_mistral': 1622, 'n_tokens_neox': 1572, 'n_words': 408}