<commit_before>defmodule Appointments.EmployeeControllerTest do
  use Appointments.ConnCase
  alias Appointments.{Repo, Employee}

  @valid_attrs %{ email: "<EMAIL>", name: "<NAME>", role: "restricted" }
  @invalid_attrs %{ }

  import OpenmaizeJWT.Create

  setup do
    company = insert(:company)
    employee = insert(:employee, company_id: company.id)

    {:ok, user_token} = %{
      id: employee.id, email: "<EMAIL>", role: "full",
      name: "p", company_id: company.id, company_name: company.name
    }
    |> generate_token({ 0, 86400 })

    conn = conn() |> put_req_cookie("access_token", user_token)

    {:ok, conn: conn, user_token: user_token, company: company}
  end

  # TODO(krummi): fix
  #test "renders form for new resources", %{conn: conn} do
  #  conn = get conn, employee_path(conn, :new)
  #  assert html_response(conn, 200) =~ "New employee"
  #end

  test "creates resource and redirects when data is valid", %{conn: conn, company: company} do
    employee = Map.put(@valid_attrs, :company_id, company.id)
    conn = post conn, employee_path(conn, :create), employee: employee
    assert redirected_to(conn) == employee_path(conn, :index)
    assert Repo.get_by(Employee, @valid_attrs)
  end

  # TODO(krummi): fix
  #test "does not create resource and renders errors when data is invalid", %{conn: conn} do
  #  conn = post conn, employee_path(conn, :create), employee: @invalid_attrs
  #  assert html_response(conn, 200) =~ "New employee"
  #end

  test "shows chosen resource", %{conn: conn, company: company} do
    employee = insert(:employee, company_id: company.id)
    conn = get conn, employee_path(conn, :show, employee)
    assert html_response(conn, 200) =~ "Show employee"
  end

  test "renders page not found when id is nonexistent", %{conn: conn} do
    assert_error_sent 404, fn ->
      get conn, employee_path(conn, :show, -1)
    end
  end

  # TODO(krummi): fix
  #test "renders form for editing chosen resource", %{conn: conn} do
  #  employee = Repo.insert! %Employee{}
  #  conn = get conn, employee_path(conn, :edit, employee)
  #  assert html_response(conn, 200) =~ "Edit employee"
  #end

  test "updates chosen resource and redirects when data is valid",
    %{conn: conn, company: company} do
    employee = Repo.insert! %Employee{
      email: "<EMAIL>", name: "ari", role: "full", company_id: company.id
    }
    conn = put conn, employee_path(conn, :update, employee), employee: @valid_attrs
    assert redirected_to(conn) == employee_path(conn, :show, employee)
    assert Repo.get_by(Employee, @valid_attrs)
  end

  # TODO(krummi): fix
  #test "does not update chosen resource and renders errors when data is invalid", %{conn: conn} do
  #  employee = Repo.insert! %Employee{}
  #  conn = put conn, employee_path(conn, :update, employee), employee: @invalid_attrs
  #  assert html_response(conn, 200) =~ "Edit employee"
  #end

  test "deletes chosen resource", %{conn: conn, company: company} do
    employee = Repo.insert! %Employee{<commit_msg>Adds more detailed tests for employees<commit_after>defmodule Appointments.EmployeeControllerTest do
  use Appointments.ConnCase
  alias Appointments.{Repo, Employee}

  @valid_attrs %{ email: "<EMAIL>", name: "<NAME>", role: "restricted" }
  @invalid_attrs %{ }

  import OpenmaizeJWT.Create

  setup do
    company = insert(:company)
    employee = insert(:employee, company_id: company.id)

    {:ok, user_token} = %{
      id: employee.id, email: "<EMAIL>", role: "full",
      name: "p", company_id: company.id, company_name: company.name
    }
    |> generate_token({ 0, 86400 })

    conn = conn() |> put_req_cookie("access_token", user_token)

    {:ok, conn: conn, user_token: user_token, company: company}
  end

  test "renders form for new resources", %{conn: conn} do
    conn = get conn, employee_path(conn, :new)
    assert html_response(conn, 200) =~ "Basic Information"
  end

  test "creates resource and redirects when data is valid", %{conn: conn, company: company} do
    employee = Map.put(@valid_attrs, :company_id, company.id)
    conn = post conn, employee_path(conn, :create), employee: employee
    assert redirected_to(conn) == employee_path(conn, :index)
    assert Repo.get_by(Employee, @valid_attrs)
  end

  test "does not create resource and renders errors when data is invalid", %{conn: conn} do
    conn = post conn, employee_path(conn, :create), employee: @invalid_attrs
    assert html_response(conn, 200) =~ "Basic Information"
  end

  test "shows chosen resource", %{conn: conn, company: company} do
    employee = insert(:employee, company_id: company.id)
    conn = get conn, employee_path(conn, :show, employee)
    assert html_response(conn, 200) =~ "Show employee"
  end

  test "renders page not found when id is nonexistent", %{conn: conn} do
    assert_error_sent 404, fn ->
      get conn, employee_path(conn, :show, -1)
    end
  end

  test "renders page not found when id belongs to another company", %{conn: conn} do
    company2 = insert(:company)
    employee = insert(:employee, company_id: company2.id)
    assert_error_sent 404, fn ->
      get conn, employee_path(conn, :show, employee.id)
    end
  end

  # TODO(krummi): fix
  #test "renders form for editing chosen resource", %{conn: conn} do
  #  employee = Repo.insert! %Employee{}
  #  conn = get conn, employee_path(conn, :edit, employee)
  #  assert html_response(conn, 200) =~ "Edit employee"
  #end

  test "updates chosen resource and redirects when data is valid",
    %{conn: conn, company: company} do
    employee = Repo.insert! %Employee{
      email: "<EMAIL>", name: "ari", role: "full", company_id: company.id
    }
    conn = put conn, employee_path(conn, :update, employee), employee: @valid_attrs
    assert redirected_to(conn) == employee_path(conn, :show, employee)
    assert Repo.get_by(Employee, @valid_attrs)
  end

  # TODO(krummi): fix
  #test "does not update chosen resource and renders errors when data is invalid", %{conn: conn} do
  #  employee = Repo.insert! %Employee{}
  #  conn = put conn, employee_path(conn, :update, employee), employee: @invalid_attrs
  #  assert html_response(conn, 200) =~ "Edit employee"
  #end

  test "deletes chosen resource", %{conn: conn, company: company} do
    employee = Repo.insert! %Employee{
{'fraction_non_alphanumeric': 0.1256761056315622, 'fraction_numerical': 0.008749602290804964, 'mean_word_length': 4.082457558609539, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 18, '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': '6879640', 'n_tokens_mistral': 2106, 'n_tokens_neox': 1971, 'n_words': 638}