+ describe "link headers" do
+ test "preserves parameters in link headers" do
+ %{user: user, conn: conn} = oauth_access(["read:notifications"])
+ other_user = insert(:user)
+
+ {:ok, activity1} =
+ CommonAPI.post(other_user, %{
+ "status" => "hi @#{user.nickname}",
+ "visibility" => "public"
+ })
+
+ {:ok, activity2} =
+ CommonAPI.post(other_user, %{
+ "status" => "hi @#{user.nickname}",
+ "visibility" => "public"
+ })
+
+ notification1 = Repo.get_by(Notification, activity_id: activity1.id)
+ notification2 = Repo.get_by(Notification, activity_id: activity2.id)
+
+ conn =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/notifications", %{media_only: true})
+
+ assert [link_header] = get_resp_header(conn, "link")
+ assert link_header =~ ~r/media_only=true/
+ assert link_header =~ ~r/min_id=#{notification2.id}/
+ assert link_header =~ ~r/max_id=#{notification1.id}/
+ end
+ end
+
+ describe "from specified user" do
+ test "account_id" do
+ %{user: user, conn: conn} = oauth_access(["read:notifications"])
+
+ %{id: account_id} = other_user1 = insert(:user)
+ other_user2 = insert(:user)
+
+ {:ok, _activity} = CommonAPI.post(other_user1, %{"status" => "hi @#{user.nickname}"})
+ {:ok, _activity} = CommonAPI.post(other_user2, %{"status" => "bye @#{user.nickname}"})
+
+ assert [%{"account" => %{"id" => ^account_id}}] =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/notifications", %{account_id: account_id})
+ |> json_response(200)
+
+ assert %{"error" => "Account is not found"} =
+ conn
+ |> assign(:user, user)
+ |> get("/api/v1/notifications", %{account_id: "cofe"})
+ |> json_response(404)
+ end
+ end
+