X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fmastodon_api%2Fcontrollers%2Fnotification_controller_test.exs;h=23f94e3a609ada410da2636ec0fa51edf0ad2a90;hb=9bae9b1b1bf4f48e20ce0b2d9b670648d052e069;hp=86303f92f13602200f3d5e57b44807a130df46f5;hpb=1630ecaa20894c6e18b83ce1a830184d577150c3;p=akkoma
diff --git a/test/web/mastodon_api/controllers/notification_controller_test.exs b/test/web/mastodon_api/controllers/notification_controller_test.exs
index 86303f92f..23f94e3a6 100644
--- a/test/web/mastodon_api/controllers/notification_controller_test.exs
+++ b/test/web/mastodon_api/controllers/notification_controller_test.exs
@@ -1,5 +1,5 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2019 Pleroma Authors
+# Copyright © 2017-2020 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
@@ -304,6 +304,51 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
end
+ test "filters notifications using include_types" do
+ %{user: user, conn: conn} = oauth_access(["read:notifications"])
+ other_user = insert(:user)
+
+ {:ok, mention_activity} = CommonAPI.post(other_user, %{"status" => "hey @#{user.nickname}"})
+ {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"})
+ {:ok, favorite_activity, _} = CommonAPI.favorite(create_activity.id, other_user)
+ {:ok, reblog_activity, _} = CommonAPI.repeat(create_activity.id, other_user)
+ {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user)
+
+ mention_notification_id = get_notification_id_by_activity(mention_activity)
+ favorite_notification_id = get_notification_id_by_activity(favorite_activity)
+ reblog_notification_id = get_notification_id_by_activity(reblog_activity)
+ follow_notification_id = get_notification_id_by_activity(follow_activity)
+
+ conn_res = get(conn, "/api/v1/notifications", %{include_types: ["follow"]})
+
+ assert [%{"id" => ^follow_notification_id}] = json_response(conn_res, 200)
+
+ conn_res = get(conn, "/api/v1/notifications", %{include_types: ["mention"]})
+
+ assert [%{"id" => ^mention_notification_id}] = json_response(conn_res, 200)
+
+ conn_res = get(conn, "/api/v1/notifications", %{include_types: ["favourite"]})
+
+ assert [%{"id" => ^favorite_notification_id}] = json_response(conn_res, 200)
+
+ conn_res = get(conn, "/api/v1/notifications", %{include_types: ["reblog"]})
+
+ assert [%{"id" => ^reblog_notification_id}] = json_response(conn_res, 200)
+
+ result = conn |> get("/api/v1/notifications") |> json_response(200)
+
+ assert length(result) == 4
+
+ result =
+ conn
+ |> get("/api/v1/notifications", %{
+ include_types: ["follow", "mention", "favourite", "reblog"]
+ })
+ |> json_response(200)
+
+ assert length(result) == 4
+ end
+
test "destroy multiple" do
%{user: user, conn: conn} = oauth_access(["read:notifications", "write:notifications"])
other_user = insert(:user)
@@ -407,20 +452,29 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
assert length(json_response(conn, 200)) == 1
end
- test "see move notifications with `with_move` parameter" do
+ @tag capture_log: true
+ test "see move notifications" do
old_user = insert(:user)
new_user = insert(:user, also_known_as: [old_user.ap_id])
%{user: follower, conn: conn} = oauth_access(["read:notifications"])
+ old_user_url = old_user.ap_id
+
+ body =
+ File.read!("test/fixtures/users_mock/localhost.json")
+ |> String.replace("{{nickname}}", old_user.nickname)
+ |> Jason.encode!()
+
+ Tesla.Mock.mock(fn
+ %{method: :get, url: ^old_user_url} ->
+ %Tesla.Env{status: 200, body: body}
+ end)
+
User.follow(follower, old_user)
Pleroma.Web.ActivityPub.ActivityPub.move(old_user, new_user)
Pleroma.Tests.ObanHelpers.perform_all()
- ret_conn = get(conn, "/api/v1/notifications")
-
- assert json_response(ret_conn, 200) == []
-
- conn = get(conn, "/api/v1/notifications", %{"with_move" => "true"})
+ conn = get(conn, "/api/v1/notifications")
assert length(json_response(conn, 200)) == 1
end
@@ -457,6 +511,30 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
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
+
defp get_notification_id_by_activity(%{id: id}) do
Notification
|> Repo.get_by(activity_id: id)