<commit_before>require 'test_helper'

class CampusesTest < ActiveSupport::TestCase
  include Rack::Test::Methods
  include TestHelpers::AuthHelper
  include TestHelpers::JsonHelper

  def app
    Rails.application
  end

  def campus
    {
      name: 'Cloud',
      mode: 'timetable',
      abbreviation: 'C'
    }
  end

  def test_get_all_campuses
    get '/api/campuses'
    expected_data = Campus.all

    assert_equal expected_data.count, last_response_body.count

    response_keys = %w(name abbreviation)

    last_response_body.each do | data |
      c = Campus.find(data['id'])
      assert_json_matches_model(data, c, response_keys)
    end
  end

  def test_post_campuses
    data_to_post = {
      campus: campus,
      auth_token: auth_token
    }
    post_json '/api/campuses', data_to_post
    assert_equal 201, last_response.status

    response_keys = %w(name abbreviation)
    campus = Campus.find(last_response_body['id'])
    assert_json_matches_model(last_response_body, campus, response_keys)
    assert_equal 0, campus[:mode]
  end

  def test_put_campuses
    campus = Campus.first
    data_to_put = {
      campus: campus,
      auth_token: auth_token
    }
    put_json '/api/campuses/1', data_to_put
    assert_equal 200, last_response.status
  end
end<commit_msg>TEST: Check response in test_put_campuses<commit_after>require 'test_helper'

class CampusesTest < ActiveSupport::TestCase
  include Rack::Test::Methods
  include TestHelpers::AuthHelper
  include TestHelpers::JsonHelper

  def app
    Rails.application
  end

  def campus
    {
      name: 'Cloud',
      mode: 'timetable',
      abbreviation: 'C'
    }
  end

  def test_get_all_campuses
    get '/api/campuses'
    expected_data = Campus.all

    assert_equal expected_data.count, last_response_body.count

    response_keys = %w(name abbreviation)

    last_response_body.each do | data |
      c = Campus.find(data['id'])
      assert_json_matches_model(data, c, response_keys)
    end
  end

  def test_post_campuses
    data_to_post = {
      campus: campus,
      auth_token: auth_token
    }
    post_json '/api/campuses', data_to_post
    assert_equal 201, last_response.status

    response_keys = %w(name abbreviation)
    campus = Campus.find(last_response_body['id'])
    assert_json_matches_model(last_response_body, campus, response_keys)
    assert_equal 0, campus[:mode]
  end

  def test_put_campuses
    data_to_put = {
      campus: campus,
      auth_token: auth_token
    }

    # Update campus with id = 1
    put_json '/api/campuses/1', data_to_put
    assert_equal 200, last_response.status

    response_keys = %w(name abbreviation)
    first_campus = Campus.first
    assert_json_matches_model(last_response_body, first_campus, response_keys)
    assert_equal 0, first_campus[:mode]
  end
end
{'fraction_non_alphanumeric': 0.08140774973338073, 'fraction_numerical': 0.006398862424457874, 'mean_word_length': 3.4106583072100314, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1175017', 'n_tokens_mistral': 965, 'n_tokens_neox': 917, 'n_words': 193}