<commit_before>require_relative '../../app.rb'
require_relative '../helpers/test_helper.rb'

class TestInterfaceTest < MiniTest::Test

  include Rack::Test::Methods

  include Capybara::DSL


  def setup
    User.destroy_all
    Tweet.destroy_all
    Follow.destroy_all
  end

  def test_creates_new_user_called_test_user
    visit '/test/reset'
    assert User.exists?(user_name: "test_user") , "new test user not created at test reset"
  end

  def test_if_test_user_exists_delete_all_existing_followers
    visit '/test/reset'
    test_user = User.find_by_user_name("test_user")
    assert !Follow.exists?(user_id: test_user.id), "folowers of test user were not deleted"
  end

  def test_if_test_user_exists_delete_all_existing_tweets
    visit '/test/reset'
    test_user = User.find_by_user_name("test_user")
    assert !Tweet.exists?(user_id: test_user.id), "tweets of test user were not deleted"
  end

  def test_reset_redirects_to_test_user_timeline
    visit '/test/reset'
    assert page.has_content?('test_user'), "test reset redirection failed"
  end

  def test_test_seed_creates_n_fake_users
    initial_users_count = User.all.size
    visit '/test/seed/12'
    assert_equal(initial_users_count+12, User.all.size , msg = "seed doesn't create n fake users")
  end

  def test_generate_n_tweets
    test_params = {user_name: "test_user",
                   name:"test user",
                   password: "<PASSWORD>",
                   email: "<EMAIL>"}
    User.create(test_params)
    test_user = User.find_by_user_name("test_user")
    initial_tweets_count = test_user.tweets.count
    visit '/test/tweets/12'
    assert_equal(initial_tweets_count+12, test_user.tweets.count , msg = "doesn't create n tweets for test user")
  end

  def test_test_n_followers_for_test_user
    test_params = {user_name: "test_user",
                   name:"test user",
                   password: "<PASSWORD>",
                   email: "<EMAIL>"}
    User.create(test_params)
    10.times { Fabricate(:user) }
    test_user = User.find_by_user_name("test_user")
    initial_followers_count = test_user.followers.count
    visit '/test/follow/7'
    assert_equal(initial_followers_count+7, test_user.followers.count , msg = "doesn't make n users follow test user")
  end

end<commit_msg>fix test interface unit tests<commit_after>require_relative '../../app.rb'
require_relative '../helpers/test_helper.rb'
require 'sidekiq/testing'

class TestInterfaceTest < MiniTest::Test

  include Rack::Test::Methods
  include Sinatra::TestHelpers

  include Capybara::DSL


  def setup
    User.destroy_all
    Tweet.destroy_all
    Follow.destroy_all
    Sidekiq::Testing.inline!
  end

  def test_creates_new_user_called_test_user
    visit '/test/reset'
    assert !test_user.nil?, "new test user not created at test reset"
  end

  def test_if_test_user_exists_delete_all_existing_followers
    visit '/test/reset'
    assert !Follow.exists?(user: test_user),
           "folowers of test user were not deleted"
  end

  def test_if_test_user_exists_delete_all_existing_tweets
    visit '/test/reset'
    assert !Tweet.exists?(user: test_user),
           "tweets of test user were not deleted"
  end

  def test_test_seed_creates_n_fake_users
    initial_users_count = User.count

    visit '/test/seed/12'
    assert_equal initial_users_count+12, User.count,
                 "seed doesn't create n fake users"
  end

  def test_generate_n_tweets
    create_new_test_user
    initial_tweets_count = test_user.tweets_count

    visit '/test/tweets/12'
    assert_equal initial_tweets_count+12, test_user.tweets_count ,
                 "doesn't create n tweets for test user"
  end

  def test_test_n_followers_for_test_user
    create_new_test_user

    10.times { Fabricate(:user) }

    initial_followers_count = test_user.followers_count

    visit '/test/follow/7'
    assert_equal initial_followers_count+7, test_user.followers_count ,
                 "doesn't make n users follow test user"
  end
end
{'fraction_non_alphanumeric': 0.08662006989515726, 'fraction_numerical': 0.005991013479780329, 'mean_word_length': 3.4720982142857144, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 7, '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': '6253478', 'n_tokens_mistral': 1361, 'n_tokens_neox': 1316, 'n_words': 280}