Ensure all supported push notification subscription alert types are tested

This commit is contained in:
Mark Felder 2020-11-17 20:14:38 +00:00
parent 499faa82f6
commit 30f140e570

View file

@ -61,9 +61,12 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
"data" => %{ "data" => %{
"alerts" => %{ "alerts" => %{
"mention" => true, "mention" => true,
"test" => true, "favourite" => true,
"follow" => true,
"reblog" => true,
"pleroma:chat_mention" => true, "pleroma:chat_mention" => true,
"pleroma:emoji_reaction" => true "pleroma:emoji_reaction" => true,
"test" => true
} }
}, },
"subscription" => @sub "subscription" => @sub
@ -75,6 +78,9 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
assert %{ assert %{
"alerts" => %{ "alerts" => %{
"mention" => true, "mention" => true,
"favourite" => true,
"follow" => true,
"reblog" => true,
"pleroma:chat_mention" => true, "pleroma:chat_mention" => true,
"pleroma:emoji_reaction" => true "pleroma:emoji_reaction" => true
}, },
@ -133,7 +139,16 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
insert(:push_subscription, insert(:push_subscription,
user: user, user: user,
token: token, token: token,
data: %{"alerts" => %{"mention" => true}} data: %{
"alerts" => %{
"mention" => true,
"favourite" => true,
"follow" => true,
"reblog" => true,
"pleroma:chat_mention" => true,
"pleroma:emoji_reaction" => true
}
}
) )
%{conn: conn, user: user, token: token, subscription: subscription} %{conn: conn, user: user, token: token, subscription: subscription}
@ -142,7 +157,16 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
test "returns error when push disabled ", %{conn: conn} do test "returns error when push disabled ", %{conn: conn} do
assert_error_when_disable_push do assert_error_when_disable_push do
conn conn
|> put("/api/v1/push/subscription", %{data: %{"alerts" => %{"mention" => false}}}) |> put("/api/v1/push/subscription", %{
data: %{
"mention" => false,
"favourite" => false,
"follow" => false,
"reblog" => false,
"pleroma:chat_mention" => false,
"pleroma:emoji_reaction" => false
}
})
|> json_response_and_validate_schema(403) |> json_response_and_validate_schema(403)
end end
end end
@ -151,12 +175,28 @@ defmodule Pleroma.Web.MastodonAPI.SubscriptionControllerTest do
res = res =
conn conn
|> put("/api/v1/push/subscription", %{ |> put("/api/v1/push/subscription", %{
data: %{"alerts" => %{"mention" => false, "follow" => true}} data: %{
"alerts" => %{
"mention" => false,
"favourite" => false,
"follow" => false,
"reblog" => false,
"pleroma:chat_mention" => false,
"pleroma:emoji_reaction" => false
}
}
}) })
|> json_response_and_validate_schema(200) |> json_response_and_validate_schema(200)
expect = %{ expect = %{
"alerts" => %{"follow" => true, "mention" => false}, "alerts" => %{
"mention" => false,
"favourite" => false,
"follow" => false,
"reblog" => false,
"pleroma:chat_mention" => false,
"pleroma:emoji_reaction" => false
},
"endpoint" => "https://example.com/example/1234", "endpoint" => "https://example.com/example/1234",
"id" => to_string(subscription.id), "id" => to_string(subscription.id),
"server_key" => @server_key "server_key" => @server_key