     @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"]
+      attrs = @valid_attrs |> Map.merge(%{project: project, user: current_user})
+      json = conn |> request_create(attrs) |> json_response(201)
 
       # 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)
      path = conn |> task_path(:show, task)

      data = conn |> get(path) |> json_response(200) |> Map.get("data")

      assert data["id"] == "#{task.id}"
      assert data["type"] == "task"
      assert data["attributes"]["body"] == task.body
      assert data["attributes"]["markdown"] == task.markdown
      assert data["attributes"]["number"] == task.number
      assert data["attributes"]["task-type"] == task.task_type
      assert data["attributes"]["status"] == task.status
      assert data["attributes"]["title"] == task.title
    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 "does not show resource and instead throw error when id is nonexistent", %{conn: conn} do
      path = conn |> task_path(:show, -1)
      assert conn |> get(path) |> json_response(:not_found)
    end
  end


    @tag :authenticated
    test "updates and renders chosen resource when data is valid", %{conn: conn, current_user: current_user} do
      task = insert(:task, user: current_user)
      assert conn |> request_update(task, @valid_attrs) |> json_response(200)
    end

    @tag :authenticated
    test "renders 422 when data is invalid", %{conn: conn, current_user: current_user} do
      task = insert(:task, user: current_user)
      assert conn |> request_update(task, @invalid_attrs) |> json_response(422)
    end

    test "renders 401 when unauthenticated", %{conn: conn} do
      assert conn |> request_update |> json_response(401)
    end

    @tag :authenticated
    test "does not update resource and renders 403 when not authorized", %{conn: conn} do
      assert conn |> request_update |> json_response(403)
    end
  end

