+ test "EmojiReact notification with remote custom emoji" do
+ proxyBaseUrl = "https://cache.pleroma.social"
+ clear_config([:media_proxy, :base_url], proxyBaseUrl)
+
+ for testProxy <- [true, false] do
+ clear_config([:media_proxy, :enabled], testProxy)
+
+ user = insert(:user)
+ other_user = insert(:user, local: false)
+
+ {:ok, activity} = CommonAPI.post(user, %{status: "#morb"})
+
+ {:ok, emoji_react, _} =
+ Builder.emoji_react(other_user, Object.normalize(activity, fetch: false), ":100a:")
+
+ remoteUrl = "http://evil.website/emoji/100a.png"
+ [tag] = emoji_react["tag"]
+ tag = put_in(tag["id"], remoteUrl)
+ tag = put_in(tag["icon"]["url"], remoteUrl)
+ emoji_react = put_in(emoji_react["tag"], [tag])
+
+ {:ok, _activity, _} = Pipeline.common_pipeline(emoji_react, local: false)
+
+ activity = Repo.get(Activity, activity.id)
+
+ [notification] = Notification.for_user(user)
+
+ assert notification
+
+ expected = %{
+ id: to_string(notification.id),
+ pleroma: %{is_seen: false, is_muted: false},
+ type: "pleroma:emoji_reaction",
+ emoji: ":100a:",
+ emoji_url: if(testProxy, do: MediaProxy.encode_url(remoteUrl), else: remoteUrl),
+ account: AccountView.render("show.json", %{user: other_user, for: user}),
+ status: StatusView.render("show.json", %{activity: activity, for: user}),
+ created_at: Utils.to_masto_date(notification.inserted_at)
+ }
+
+ test_notifications_rendering([notification], user, [expected])
+ end
+ end
+
+ test "Poll notification" do
+ user = insert(:user)
+ activity = insert(:question_activity, user: user)
+ {:ok, [notification]} = Notification.create_poll_notifications(activity)
+
+ expected = %{
+ id: to_string(notification.id),
+ pleroma: %{is_seen: false, is_muted: false},
+ type: "poll",
+ account:
+ AccountView.render("show.json", %{
+ user: user,
+ for: user
+ }),
+ status: StatusView.render("show.json", %{activity: activity, for: user}),
+ created_at: Utils.to_masto_date(notification.inserted_at)
+ }
+
+ test_notifications_rendering([notification], user, [expected])
+ end
+
+ test "Report notification" do
+ reporting_user = insert(:user)
+ reported_user = insert(:user)
+ {:ok, moderator_user} = insert(:user) |> User.admin_api_update(%{is_moderator: true})
+
+ {:ok, activity} = CommonAPI.report(reporting_user, %{account_id: reported_user.id})
+ {:ok, [notification]} = Notification.create_notifications(activity)
+
+ expected = %{
+ id: to_string(notification.id),
+ pleroma: %{is_seen: false, is_muted: false},
+ type: "pleroma:report",
+ account: AccountView.render("show.json", %{user: reporting_user, for: moderator_user}),
+ created_at: Utils.to_masto_date(notification.inserted_at),
+ report: ReportView.render("show.json", Report.extract_report_info(activity))
+ }
+
+ test_notifications_rendering([notification], moderator_user, [expected])
+ end
+