<commit_before>require_relative '../test_helper'

class TravelAdviceControllerTest < ActionController::TestCase

  context "GET index" do
    context "given countries exist" do
      setup do
        @json_data = File.read(Rails.root.join('test/fixtures/foreign-travel-advice/index2.json'))
        @index_artefact = GdsApi::ContentApi::Response.new(
          stub("HTTP_Response", :code => 200, :body => @json_data),
          :web_urls_relative_to => "https://www.gov.uk"
        )
        GdsApi::ContentApi.any_instance.stubs(:artefact).with('foreign-travel-advice').returns(@index_artefact)
      end

      should "be a successful request" do
        get :index

        assert response.success?
      end

      should "make a request to the content api for the travel advice top-level artefact" do
        GdsApi::ContentApi.any_instance.expects(:artefact).with('foreign-travel-advice').returns(@index_artefact)

        get :index
        assert_equal @index_artefact, assigns(:artefact)
      end

      should "send the artefact to slimmer" do
        get :index

        assert_equal JSON.dump(@index_artefact.to_hash), @response.headers["X-Slimmer-Artefact"]
      end

      should "set other slimmer headers" do
        get :index<commit_msg>Migrate travel advice index to use fetch_artefact method<commit_after>require_relative '../test_helper'

class TravelAdviceControllerTest < ActionController::TestCase

  context "GET index" do
    context "given countries exist" do
      setup do
        @json_data = File.read(Rails.root.join('test/fixtures/foreign-travel-advice/index2.json'))
        @index_artefact = GdsApi::ContentApi::Response.new(
          stub("HTTP_Response", :code => 200, :body => @json_data),
          :web_urls_relative_to => "https://www.gov.uk"
        )
        @controller.stubs(:fetch_artefact).returns(@index_artefact)
      end

      should "be a successful request" do
        get :index

        assert response.success?
      end

      should "make a request to the content api for the travel advice top-level artefact" do
        @controller.expects(:fetch_artefact).returns(@index_artefact)

        get :index
        assert_equal @index_artefact, assigns(:artefact)
      end

      should "send the artefact to slimmer" do
        get :index

        assert_equal JSON.dump(@index_artefact.to_hash), @response.headers["X-Slimmer-Artefact"]
      end

      should "set other slimmer headers" do
        get :index
{'fraction_non_alphanumeric': 0.10198300283286119, 'fraction_numerical': 0.003237555645487657, 'mean_word_length': 2.9870967741935486, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, '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': '1684708', 'n_tokens_mistral': 741, 'n_tokens_neox': 727, 'n_words': 172}