<commit_before>require_relative '../test_helper'

class AdminIntegrationTest < ActionDispatch::IntegrationTest
  include Devise::Test::IntegrationHelpers

  def setup
    WebMock.stub_request(:post, /#{Regexp.escape(CONFIG['bridge_reader_url_private'])}.*/) unless CONFIG['bridge_reader_url_private'].blank?
    @team = create_team
    Team.stubs(:current).returns(@team)
    @user = create_user login: 'test', password: '<PASSWORD>', password_confirmation: '<PASSWORD>', email: '<EMAIL>', confirm: false
    @user.confirm
    @admin_user = create_user login: 'admin_user', password: '<PASSWORD>', password_confirmation: '<PASSWORD>', email: '<EMAIL>', confirm: false
    @admin_user.confirm
    @admin_user.is_admin = true
    @admin_user.save!
    @project = create_project user: @user, team: @team
    Object.any_instance.stubs(:notify_pusher)
    Sidekiq::Testing.fake!
  end

  def teardown
    super
    Team.unstub(:current)
  end

  test "should redirect to root if not logged user access admin UI" do
    get '/admin'
    assert_redirected_to '/'
  end

  test "should access admin UI if admin" do
    sign_in @user
    get '/admin'
    assert_redirected_to '/403.html'
    sign_out @user

    @user.is_admin = true
    @user.save!
    sign_in @user
    get '/admin'
    assert_response :success
  end

  test "should not access Admin UI if user has no role" do
    assert_nil @user.role
<commit_msg>Fixing flake test<commit_after>require_relative '../test_helper'

class AdminIntegrationTest < ActionDispatch::IntegrationTest
  include Devise::Test::IntegrationHelpers

  def setup
    WebMock.stub_request(:post, /#{Regexp.escape(CONFIG['bridge_reader_url_private'])}.*/) unless CONFIG['bridge_reader_url_private'].blank?
    @team = create_team
    Team.stubs(:current).returns(@team)
    @user = create_user login: 'test', password: '<PASSWORD>', password_confirmation: '<PASSWORD>', email: '<EMAIL>', confirm: false
    @user.confirm
    @admin_user = create_user login: 'admin_user', password: '<PASSWORD>', password_confirmation: '<PASSWORD>', email: '<EMAIL>', confirm: false
    @admin_user.confirm
    @admin_user.is_admin = true
    @admin_user.save!
    @project = create_project user: @user, team: @team
    Object.any_instance.stubs(:notify_pusher)
    Sidekiq::Testing.fake!
    RequestStore.store[:skip_cached_field_update] = true
  end

  def teardown
    super
    Team.unstub(:current)
  end

  test "should redirect to root if not logged user access admin UI" do
    get '/admin'
    assert_redirected_to '/'
  end

  test "should access admin UI if admin" do
    sign_in @user
    get '/admin'
    assert_redirected_to '/403.html'
    sign_out @user

    @user.is_admin = true
    @user.save!
    sign_in @user
    get '/admin'
    assert_response :success
  end

  test "should not access Admin UI if user has no role" do
    assert_nil @user.role

{'fraction_non_alphanumeric': 0.11566516151441472, 'fraction_numerical': 0.0020840569642236887, 'mean_word_length': 3.9913344887348354, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 15, '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': '3619861', 'n_tokens_mistral': 912, 'n_tokens_neox': 917, 'n_words': 236}