 
   alias Appointments.Service
 
-  @invalid_attrs %{name: "testing"}
-
   setup do
     company = insert(:company)
     employee = insert(:employee, company_id: company.id)
-    valid_attrs = %{name: "Haircut", duration: 45, company_id: company.id}
+    service = insert(:service, company_id: company.id)
 
     {:ok, token} = create_token(company, employee)
     conn = conn() |> put_req_cookie("access_token", token)
 
-    {:ok, conn: conn, valid_attrs: valid_attrs}
+    {:ok, conn: conn, service: service}
   end
 
   test "lists all entries on index", %{conn: conn} do

  end

  test "renders form for editing chosen resource",
    %{conn: conn, valid_attrs: valid_attrs} do
    service = Repo.insert! Service.changeset(%Service{}, valid_attrs)
    conn = get conn, service_path(conn, :edit, service)
    assert html_response(conn, 200) =~ "Edit service"
  end

  test "updates chosen resource and redirects when data is valid",
    %{conn: conn, valid_attrs: valid_attrs} do
    service = Repo.insert! Service.changeset(%Service{}, valid_attrs)
    update_attrs = Map.put(valid_attrs, :cleanup_duration, 15)
    conn = put conn, service_path(conn, :update, service), service: update_attrs
    assert redirected_to(conn) == service_path(conn, :show, service)
    assert Repo.get_by(Service, update_attrs)
  end

  test "does not update chosen resource and renders errors when data is invalid",
    %{conn: conn, valid_attrs: valid_attrs} do
    service = Repo.insert! Service.changeset(%Service{}, valid_attrs)
    update_attrs = Map.put(valid_attrs, :cleanup_duration, -1)
    conn = put conn, service_path(conn, :update, service), service: update_attrs
    assert html_response(conn, 200) =~ "Edit service"
  end

  test "deletes chosen resource", %{conn: conn, valid_attrs: valid_attrs} do
    service = Repo.insert! Service.changeset(%Service{}, valid_attrs)
    conn = delete conn, service_path(conn, :delete, service)
    assert redirected_to(conn) == service_path(conn, :index)
    refute Repo.get(Service, service.id)

  end

  test "creates resource and redirects when data is valid",
    %{conn: conn, service: service} do
    valid_attrs = %{name: "Test", duration: 50, company_id: service.company_id}
    conn = post conn, service_path(conn, :create), service: valid_attrs
    assert redirected_to(conn) == service_path(conn, :index)
    assert Repo.get_by(Service, valid_attrs)
