Move subscription notifications to a separate controller
This commit is contained in:
parent
56b60798c2
commit
6042e21b25
8 changed files with 343 additions and 277 deletions
|
|
@ -13,7 +13,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.ScheduledActivity
|
||||
alias Pleroma.SubscriptionNotification
|
||||
alias Pleroma.Tests.ObanHelpers
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.ActivityPub.ActivityPub
|
||||
|
|
@ -1275,197 +1274,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "subscription_notifications" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
subscriber = insert(:user)
|
||||
|
||||
User.subscribe(subscriber, user)
|
||||
|
||||
{:ok, %{user: user, subscriber: subscriber}}
|
||||
end
|
||||
|
||||
test "list of notifications", %{conn: conn, user: user, subscriber: subscriber} do
|
||||
status_text = "Hello"
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, subscriber)
|
||||
|> get("/api/v1/notifications/subscription")
|
||||
|
||||
assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200)
|
||||
assert response == status_text
|
||||
end
|
||||
|
||||
test "getting a single notification", %{conn: conn, user: user, subscriber: subscriber} do
|
||||
status_text = "Hello"
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
|
||||
[notification] = Repo.all(SubscriptionNotification)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, subscriber)
|
||||
|> get("/api/v1/notifications/subscription/#{notification.id}")
|
||||
|
||||
assert %{"status" => %{"content" => response}} = json_response(conn, 200)
|
||||
assert response == status_text
|
||||
end
|
||||
|
||||
test "dismissing a single notification also deletes it", %{
|
||||
conn: conn,
|
||||
user: user,
|
||||
subscriber: subscriber
|
||||
} do
|
||||
status_text = "Hello"
|
||||
{:ok, _activity} = CommonAPI.post(user, %{"status" => status_text})
|
||||
|
||||
[notification] = Repo.all(SubscriptionNotification)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, subscriber)
|
||||
|> post("/api/v1/notifications/subscription/dismiss", %{"id" => notification.id})
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
|
||||
assert Repo.all(SubscriptionNotification) == []
|
||||
end
|
||||
|
||||
test "clearing all notifications also deletes them", %{
|
||||
conn: conn,
|
||||
user: user,
|
||||
subscriber: subscriber
|
||||
} do
|
||||
status_text1 = "Hello"
|
||||
status_text2 = "Hello again"
|
||||
{:ok, _activity1} = CommonAPI.post(user, %{"status" => status_text1})
|
||||
{:ok, _activity2} = CommonAPI.post(user, %{"status" => status_text2})
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, subscriber)
|
||||
|> post("/api/v1/notifications/subscription/clear")
|
||||
|
||||
assert %{} = json_response(conn, 200)
|
||||
|
||||
conn =
|
||||
build_conn()
|
||||
|> assign(:user, subscriber)
|
||||
|> get("/api/v1/notifications/subscription")
|
||||
|
||||
assert json_response(conn, 200) == []
|
||||
|
||||
assert Repo.all(SubscriptionNotification) == []
|
||||
end
|
||||
|
||||
test "paginates notifications using min_id, since_id, max_id, and limit", %{
|
||||
conn: conn,
|
||||
user: user,
|
||||
subscriber: subscriber
|
||||
} do
|
||||
{:ok, activity1} = CommonAPI.post(user, %{"status" => "Hello 1"})
|
||||
{:ok, activity2} = CommonAPI.post(user, %{"status" => "Hello 2"})
|
||||
{:ok, activity3} = CommonAPI.post(user, %{"status" => "Hello 3"})
|
||||
{:ok, activity4} = CommonAPI.post(user, %{"status" => "Hello 4"})
|
||||
|
||||
notification1_id =
|
||||
Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string()
|
||||
|
||||
notification2_id =
|
||||
Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string()
|
||||
|
||||
notification3_id =
|
||||
Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string()
|
||||
|
||||
notification4_id =
|
||||
Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string()
|
||||
|
||||
conn = assign(conn, :user, subscriber)
|
||||
|
||||
# min_id
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications/subscription?limit=2&min_id=#{notification1_id}")
|
||||
|
||||
result = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
|
||||
|
||||
# since_id
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications/subscription?limit=2&since_id=#{notification1_id}")
|
||||
|
||||
result = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result
|
||||
|
||||
# max_id
|
||||
conn_res =
|
||||
get(conn, "/api/v1/notifications/subscription?limit=2&max_id=#{notification4_id}")
|
||||
|
||||
result = json_response(conn_res, 200)
|
||||
assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result
|
||||
end
|
||||
|
||||
test "destroy multiple", %{conn: conn, user: user1, subscriber: user2} do
|
||||
# mutual subscription
|
||||
User.subscribe(user1, user2)
|
||||
|
||||
{:ok, activity1} = CommonAPI.post(user1, %{"status" => "Hello 1"})
|
||||
{:ok, activity2} = CommonAPI.post(user1, %{"status" => "World 1"})
|
||||
{:ok, activity3} = CommonAPI.post(user2, %{"status" => "Hello 2"})
|
||||
{:ok, activity4} = CommonAPI.post(user2, %{"status" => "World 2"})
|
||||
|
||||
notification1_id =
|
||||
Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string()
|
||||
|
||||
notification2_id =
|
||||
Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string()
|
||||
|
||||
notification3_id =
|
||||
Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string()
|
||||
|
||||
notification4_id =
|
||||
Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string()
|
||||
|
||||
conn = assign(conn, :user, user1)
|
||||
|
||||
conn_res = get(conn, "/api/v1/notifications/subscription")
|
||||
|
||||
result = json_response(conn_res, 200)
|
||||
|
||||
Enum.each(result, fn %{"id" => id} ->
|
||||
assert id in [notification3_id, notification4_id]
|
||||
end)
|
||||
|
||||
conn2 = assign(conn, :user, user2)
|
||||
|
||||
conn_res = get(conn2, "/api/v1/notifications/subscription")
|
||||
|
||||
result = json_response(conn_res, 200)
|
||||
|
||||
Enum.each(result, fn %{"id" => id} ->
|
||||
assert id in [notification1_id, notification2_id]
|
||||
end)
|
||||
|
||||
conn_destroy =
|
||||
delete(conn, "/api/v1/notifications/subscription/destroy_multiple", %{
|
||||
"ids" => [notification3_id, notification4_id]
|
||||
})
|
||||
|
||||
assert json_response(conn_destroy, 200) == %{}
|
||||
|
||||
conn_res = get(conn2, "/api/v1/notifications/subscription")
|
||||
|
||||
result = json_response(conn_res, 200)
|
||||
|
||||
Enum.each(result, fn %{"id" => id} ->
|
||||
assert id in [notification1_id, notification2_id]
|
||||
end)
|
||||
|
||||
assert length(Repo.all(SubscriptionNotification)) == 2
|
||||
end
|
||||
end
|
||||
|
||||
describe "reblogging" do
|
||||
test "reblogs and returns the reblogged status", %{conn: conn} do
|
||||
activity = insert(:note_activity)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue