# Pleroma: A lightweight social networking server
# Copyright © 2017-2018 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.Push.ImplTest do
use Pleroma.DataCase
alias Pleroma.Web.Push.Impl
alias Pleroma.Web.Push.Subscription
import Pleroma.Factory
setup_all do
Tesla.Mock.mock_global(fn
%{method: :post, url: "https://example.com/example/1234"} ->
%Tesla.Env{status: 200}
%{method: :post, url: "https://example.com/example/not_found"} ->
%Tesla.Env{status: 400}
%{method: :post, url: "https://example.com/example/bad"} ->
%Tesla.Env{status: 100}
end)
: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 fini..."
test "performs sending notifications" do
user = insert(:user)
user2 = insert(:user)
insert(:push_subscription, user: user, data: %{alerts: %{"mention" => true}})
insert(:push_subscription, user: user2, data: %{alerts: %{"mention" => true}})
insert(:push_subscription,
user: user,
data: %{alerts: %{"follow" => true, "mention" => true}}
)
insert(:push_subscription,
user: user,
data: %{alerts: %{"follow" => true, "mention" => false}}
)
notif =
insert(:notification,
user: user,
activity: %Pleroma.Activity{
data: %{
"type" => "Create",
"actor" => user.ap_id,
"object" => %{"content" => " "Create",
"object" => %{
"content" =>
"Lorem ipsum dolor sit amet, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
}
}
}
},
%{nickname: "Bob"}
) ==
"@Bob: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
end
test "renders body for follow activity" do
assert Impl.format_body(%{activity: %{data: %{"type" => "Follow"}}}, %{nickname: "Bob"}) ==
"@Bob has followed you"
end
test "renders body for announce activity" do
user = insert(:user)
note =
insert(:note, %{
data: %{
"content" =>
"Lorem ipsum dolor sit amet, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis."
}
})
note_activity = insert(:note_activity, %{note: note})
announce_activity = insert(:announce_activity, %{user: user, note_activity: note_activity})
assert Impl.format_body(%{activity: announce_activity}, user) ==
"@#{user.nickname} repeated: Lorem ipsum dolor sit amet, consectetur adipiscing elit. Fusce sagittis fini..."
end
test "renders body for like activity" do
assert Impl.format_body(%{activity: %{data: %{"type" => "Like"}}}, %{nickname: "Bob"}) ==
"@Bob has favorited your post"
end
end