Merge remote-tracking branch 'origin/develop' into bugfix/elixir-1.15
This commit is contained in:
commit
e43e09a04c
12 changed files with 187 additions and 112 deletions
|
|
@ -952,9 +952,16 @@ defmodule Pleroma.UserTest do
|
|||
|
||||
{:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
|
||||
|
||||
assert user.inbox
|
||||
# Oban job was generated to refresh the stale user
|
||||
assert_enqueued(worker: "Pleroma.Workers.UserRefreshWorker", args: %{"ap_id" => user.ap_id})
|
||||
|
||||
refute user.last_refreshed_at == orig_user.last_refreshed_at
|
||||
# Run job to refresh the user; just capture its output instead of fetching it again
|
||||
assert {:ok, updated_user} =
|
||||
perform_job(Pleroma.Workers.UserRefreshWorker, %{"ap_id" => user.ap_id})
|
||||
|
||||
assert updated_user.inbox
|
||||
|
||||
refute updated_user.last_refreshed_at == orig_user.last_refreshed_at
|
||||
end
|
||||
|
||||
test "if nicknames clash, the old user gets a prefix with the old id to the nickname" do
|
||||
|
|
|
|||
|
|
@ -0,0 +1,14 @@
|
|||
defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiTagBuildingTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
alias Pleroma.Web.ActivityPub.Transmogrifier
|
||||
|
||||
test "it encodes the id to be a valid url" do
|
||||
name = "hanapog"
|
||||
url = "https://misskey.local.live/emojis/hana pog.png"
|
||||
|
||||
tag = Transmogrifier.build_emoji_tag({name, url})
|
||||
|
||||
assert tag["id"] == "https://misskey.local.live/emojis/hana%20pog.png"
|
||||
end
|
||||
end
|
||||
|
|
@ -5,6 +5,7 @@
|
|||
defmodule Pleroma.Web.Push.ImplTest do
|
||||
use Pleroma.DataCase, async: true
|
||||
|
||||
import ExUnit.CaptureLog
|
||||
import Mox
|
||||
import Pleroma.Factory
|
||||
|
||||
|
|
@ -32,17 +33,6 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
:ok
|
||||
end
|
||||
|
||||
@sub %{
|
||||
endpoint: "https://example.com/example/1234",
|
||||
keys: %{
|
||||
auth: "8eDyX_uCN0XRhSbY5hs7Hg==",
|
||||
p256dh:
|
||||
"BCIWgsnyXDv1VkhqL2P7YRBvdeuDnlwAPT2guNhdIoW3IP7GmHh1SMKPLxRf7x8vJy6ZFK3ol2ohgn_-0yP7QQA="
|
||||
}
|
||||
}
|
||||
@api_key "BASgACIHpN1GYgzSRp"
|
||||
@message "@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis finibus turpis."
|
||||
|
||||
test "performs sending notifications" do
|
||||
user = insert(:user)
|
||||
user2 = insert(:user)
|
||||
|
|
@ -68,37 +58,65 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
type: "mention"
|
||||
)
|
||||
|
||||
assert Impl.perform(notif) == {:ok, [:ok, :ok]}
|
||||
Impl.build(notif)
|
||||
|> Enum.each(fn push -> assert match?(:ok, Impl.deliver(push)) end)
|
||||
end
|
||||
|
||||
test "returns error if notif does not match " do
|
||||
assert Impl.perform(%{}) == {:error, :unknown_type}
|
||||
end
|
||||
|
||||
test "successful message sending" do
|
||||
assert Impl.push_message(@message, @sub, @api_key, %Subscription{}) == :ok
|
||||
test "returns error if notification activity type does not match" do
|
||||
assert capture_log(fn ->
|
||||
assert Impl.build(%{}) == []
|
||||
end) =~ "WebPush: unknown activity type"
|
||||
end
|
||||
|
||||
test "fail message sending" do
|
||||
assert Impl.push_message(
|
||||
@message,
|
||||
Map.merge(@sub, %{endpoint: "https://example.com/example/bad"}),
|
||||
@api_key,
|
||||
%Subscription{}
|
||||
) == :error
|
||||
user = insert(:user)
|
||||
|
||||
insert(:push_subscription,
|
||||
user: user,
|
||||
endpoint: "https://example.com/example/bad",
|
||||
data: %{alerts: %{"follow" => true}}
|
||||
)
|
||||
|
||||
other_user = insert(:user)
|
||||
{:ok, _, _, activity} = CommonAPI.follow(user, other_user)
|
||||
|
||||
notif =
|
||||
insert(:notification,
|
||||
user: user,
|
||||
activity: activity,
|
||||
type: "follow"
|
||||
)
|
||||
|
||||
[push] = Impl.build(notif)
|
||||
|
||||
assert Impl.deliver(push) == :error
|
||||
end
|
||||
|
||||
test "delete subscription if result send message between 400..500" do
|
||||
subscription = insert(:push_subscription)
|
||||
user = insert(:user)
|
||||
|
||||
assert Impl.push_message(
|
||||
@message,
|
||||
Map.merge(@sub, %{endpoint: "https://example.com/example/not_found"}),
|
||||
@api_key,
|
||||
subscription
|
||||
) == :ok
|
||||
bad_subscription =
|
||||
insert(:push_subscription,
|
||||
user: user,
|
||||
endpoint: "https://example.com/example/not_found",
|
||||
data: %{alerts: %{"follow" => true}}
|
||||
)
|
||||
|
||||
refute Pleroma.Repo.get(Subscription, subscription.id)
|
||||
other_user = insert(:user)
|
||||
{:ok, _, _, activity} = CommonAPI.follow(user, other_user)
|
||||
|
||||
notif =
|
||||
insert(:notification,
|
||||
user: user,
|
||||
activity: activity,
|
||||
type: "follow"
|
||||
)
|
||||
|
||||
[push] = Impl.build(notif)
|
||||
|
||||
assert Impl.deliver(push) == :ok
|
||||
|
||||
refute Pleroma.Repo.get(Subscription, bad_subscription.id)
|
||||
end
|
||||
|
||||
test "deletes subscription when token has been deleted" do
|
||||
|
|
@ -403,4 +421,23 @@ defmodule Pleroma.Web.Push.ImplTest do
|
|||
}
|
||||
end
|
||||
end
|
||||
|
||||
test "build/1 notification payload body starts with nickname of actor the notification originated from" do
|
||||
user = insert(:user, nickname: "Bob")
|
||||
user2 = insert(:user, nickname: "Tom")
|
||||
insert(:push_subscription, user: user2, data: %{alerts: %{"mention" => true}})
|
||||
|
||||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{
|
||||
status: "@Tom Hey are you okay?"
|
||||
})
|
||||
|
||||
{:ok, [notification]} = Notification.create_notifications(activity)
|
||||
|
||||
[push] = Impl.build(notification)
|
||||
|
||||
{:ok, payload} = Jason.decode(push.payload)
|
||||
|
||||
assert String.starts_with?(payload["body"], "@Bob:")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue