<commit_before># frozen_string_literal: true

require "test_helper"

# Tests to assure admins can manage projects.
class ProjectsControllerTest < ActionDispatch::IntegrationTest
  setup do
    @project = projects(:one)
    @admin = users(:admin)
  end

  def project_params
    {
      name: @project.name,
      slug: @project.slug,
      short_description: @project.short_description,
      consent: @project.consent,
      launch_date: @project.launch_date,
      theme: @project.theme,
      access_token: "<PASSWORD>",
      published: "1",
      slice_site_id: "12345",
      code_prefix: "TEST"
    }
  end

  test "should get index" do
    login(@admin)
    get projects_path
    assert_response :success
  end

  test "should get new" do
    login(@admin)
    get new_project_path
    assert_response :success
  end

  test "should create project" do
    login(@admin)
    assert_difference("Project.count") do
      post projects_path, params: {
        project: project_params.merge(slug: "new-project")
      }
    end
    assert_redirected_to project_path(Project.last)
  end

  test "should show project" do
    login(@admin)
    get project_path(@project)
    assert_response :success
  end

  test "should get edit" do
    login(@admin)
    get edit_project_path(@project)
    assert_response :success
  end

  test "should update project" do
    login(@admin)
    patch project_path(@project), params: { project: project_params }
    assert_redirected_to project_path(@project)
  end

  test "should destroy project" do
    login(@admin)
    assert_difference("Project.current.count", -1) do
      delete project_path(@project)
    end
    @project.reload
    assert_nil @project.slug
    assert_redirected_to projects_path<commit_msg>Use `_url` in tests instead of `_path`<commit_after># frozen_string_literal: true

require "test_helper"

# Tests to assure admins can manage projects.
class ProjectsControllerTest < ActionDispatch::IntegrationTest
  setup do
    @project = projects(:one)
    @admin = users(:admin)
  end

  def project_params
    {
      name: @project.name,
      slug: @project.slug,
      short_description: @project.short_description,
      consent: @project.consent,
      launch_date: @project.launch_date,
      theme: @project.theme,
      access_token: "access-<PASSWORD>",
      published: "1",
      slice_site_id: "12345",
      code_prefix: "TEST"
    }
  end

  test "should get index" do
    login(@admin)
    get projects_url
    assert_response :success
  end

  test "should get new" do
    login(@admin)
    get new_project_url
    assert_response :success
  end

  test "should create project" do
    login(@admin)
    assert_difference("Project.count") do
      post projects_url, params: {
        project: project_params.merge(slug: "new-project")
      }
    end
    assert_redirected_to project_url(Project.last)
  end

  test "should show project" do
    login(@admin)
    get project_url(@project)
    assert_response :success
  end

  test "should get edit" do
    login(@admin)
    get edit_project_url(@project)
    assert_response :success
  end

  test "should update project" do
    login(@admin)
    patch project_url(@project), params: { project: project_params }
    assert_redirected_to project_url(@project)
  end

  test "should destroy project" do
    login(@admin)
    assert_difference("Project.current.count", -1) do
      delete project_url(@project)
    end
    @project.reload
    assert_nil @project.slug
    assert_redirected_to projects_url
{'fraction_non_alphanumeric': 0.08990357345433919, 'fraction_numerical': 0.003970504821327283, 'mean_word_length': 3.2699757869249395, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '6072234', 'n_tokens_mistral': 1088, 'n_tokens_neox': 1063, 'n_words': 281}