   }
 
   @invalid_attrs %{
+    title: nil,
     task_type: "issue",
     status: "nonexistent"
   }
 
-  defp build_payload, do: %{ "data" => %{"type" => "task"}}
-
   describe "index" do
     test "lists all entries", %{conn: conn} do
-      path = conn |> task_path(:index)
-      json = conn |> get(path) |> json_response(200)
-      assert json["data"] == []
+      [task_1, task_2] = insert_pair(:task)
+
+      conn
+      |> request_index
+      |> json_response(200)
+      |> assert_ids_from_response([task_1.id, task_2.id])
     end
 
     test "lists all entries newest first", %{conn: conn} do

    @tag :authenticated
    test "creates and renders resource when data is valid", %{conn: conn, current_user: current_user} do
      project = insert(:project)

      payload =
        build_payload
        |> put_attributes(@valid_attrs)
        |> put_relationships(current_user, project)

      path = conn |> task_path(:create)
      json = conn |> post(path, payload) |> json_response(201)

      assert json["data"]["id"]

      # ensure record is reloaded from database before serialized, since number is added
      # on database level upon insert

  describe "show" do
    test "shows chosen resource", %{conn: conn} do
      task = insert(:task)

      conn
      |> request_show(task)
      |> json_response(200)
      |> Map.get("data")
      |> assert_result_id(task.id)
    end

    test "shows task by number for project", %{conn: conn} do
      task = insert(:task)

      path = conn |> project_task_path(:show, task.project_id, task.number)
      data = conn |> get(path) |> json_response(200) |> Map.get("data")

      assert data["id"] == "#{task.id}"
      assert data["type"] == "task"
    end

    test "renders 404 when id is nonexistent", %{conn: conn} do
      assert conn |> request_show(:not_found) |> json_response(404)
    end
  end

