<commit_before>require './test/app_helper'
require './test/vcr_helper'

class AppRoutesUserTest < Minitest::Test
  include Rack::Test::Methods

  def app
    Xapi::App
  end

  def test_protected_endpoints
    [
      '/exercises/ruby',
      '/exercises',
      '/exercises/restore'
    ].each do |endpoint|
      get endpoint
      assert_equal 401, last_response.status, "GET #{endpoint} should be protected"
    end
  end

  # Acceptance tests. Relies on real language-specific data.
  # Expect it to fail regularly, since exercises get updated fairly frequently.

  def test_get_problems_by_language
    VCR.use_cassette('exercism_api_current_exercises') do
      get '/exercises/ruby', :key => 'abc123'
      options = {:format => :json, :name => 'get_current_problems_by_language'}
      Approvals.verify(last_response.body, options)
    end
  end

  def test_get_problems
    VCR.use_cassette('exercism_api_current_exercises') do
      get '/exercises', :key => 'abc123'

      options = {:format => :json, :name => 'get_current_problems'}
      Approvals.verify(last_response.body, options)
    end
  end

  def test_restore_exercises_and_solutions
    VCR.use_cassette('exercism_api_restore') do
      get '/exercises/restore', :key => 'abc123'
      options = {:format => :json, :name => 'restore'}
      Approvals.verify(last_response.body, options)
    end
  end

  def test_api_error
    VCR.use_cassette('exercism_api_error') do
      get '/exercises', :key => 'no-such-key'
      options = {:format => :json, :name => 'error'}
      Approvals.verify(last_response.body, options)
    end<commit_msg>Investigate failure on CI server<commit_after>require './test/app_helper'
require './test/vcr_helper'

class AppRoutesUserTest < Minitest::Test
  include Rack::Test::Methods

  def app
    Xapi::App
  end

  def test_protected_endpoints
    [
      '/exercises/ruby',
      '/exercises',
      '/exercises/restore'
    ].each do |endpoint|
      get endpoint
      assert_equal 401, last_response.status, "GET #{endpoint} should be protected"
    end
  end

  # Acceptance tests. Relies on real language-specific data.
  # Expect it to fail regularly, since exercises get updated fairly frequently.

  def test_get_problems_by_language
    VCR.use_cassette('exercism_api_current_exercises') do
      get '/exercises/ruby', :key => 'abc123'
      options = {:format => :json, :name => 'get_current_problems_by_language'}
      Approvals.verify(last_response.body, options)
    end
  end

  def test_get_problems
    VCR.use_cassette('exercism_api_current_exercises') do
      get '/exercises', :key => 'abc123'

      expected = JSON.parse(File.read("./test/fixtures/approvals/get_current_problems.approved.json"))
      actual = JSON.parse(last_response.body)
      assert_equal expected, actual

      options = {:format => :json, :name => 'get_current_problems'}
      Approvals.verify(last_response.body, options)
    end
  end

  def test_restore_exercises_and_solutions
    VCR.use_cassette('exercism_api_restore') do
      get '/exercises/restore', :key => 'abc123'
      options = {:format => :json, :name => 'restore'}
      Approvals.verify(last_response.body, options)
    end
  end

  def test_api_error
    VCR.use_cassette('exercism_api_error') do
      get '/exercises', :key => 'no-such-key'
      options = {:format => :json, :name => 'error'}
      Approvals.verify(last_response.body, options)
    end
{'fraction_non_alphanumeric': 0.11535100495193708, 'fraction_numerical': 0.006990969997087096, 'mean_word_length': 3.4830287206266317, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 27, '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': '7193892', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1119, 'n_words': 246}