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

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

  import OpenmaizeJWT.Create

  setup do
    # TODO(krummi): Use https://github.com/thoughtbot/ex_machina
    company = Repo.insert! %Company{name: "The Test Company!"}

    employee_params = %{
      email: "<EMAIL>",
      name: "<NAME>",
      role: "full",
      password: "<PASSWORD>",
      company_id: company.id
    }

    key = "<KEY>"
    employee = %Employee{}
    |> Employee.auth_changeset(employee_params, key)
    |> Employee.reset_changeset(employee_params, key)
    |> Repo.insert!

    {:ok, user_token} = %{
      id: employee.id, email: "<EMAIL>", role: "full",
      name: "p", company_id: 1, company_name: "hehe"
    }
    |> 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<commit_msg>Fix tests<commit_after>defmodule Appointments.EmployeeControllerTest do
  use Appointments.ConnCase
  alias Appointments.{Repo, Employee, Company}

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

  import OpenmaizeJWT.Create

  setup do
    # TODO(krummi): Use https://github.com/thoughtbot/ex_machina
    company = Repo.insert! %Company{name: "The Test Company!"}

    employee_params = %{
      email: "<EMAIL>",
      name: "<NAME>",
      role: "full",
      password: "<PASSWORD>",
      company_id: company.id
    }

    key = "<KEY>"
    employee = %Employee{}
    |> Employee.auth_changeset(employee_params, key)
    |> Employee.reset_changeset(employee_params, key)
    |> Repo.insert!

    {: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
{'fraction_non_alphanumeric': 0.14065678581807614, 'fraction_numerical': 0.005521650682941005, 'mean_word_length': 3.75414364640884, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 27, 'https://': 2, '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': '2758083', 'n_tokens_mistral': 1200, 'n_tokens_neox': 1118, 'n_words': 302}