1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.AnnouncementTest do
6 alias Pleroma.Announcement
8 use Pleroma.DataCase, async: true
10 import Pleroma.Factory
12 describe "list_all_visible_when/1" do
13 setup do: {:ok, time: NaiveDateTime.utc_now()}
15 test "with no start or end time", %{time: time} do
16 _announcement = insert(:announcement)
18 assert [_] = Announcement.list_all_visible_when(time)
21 test "with start time before current", %{time: time} do
22 before_now = NaiveDateTime.add(time, -10, :second)
24 _announcement = insert(:announcement, %{starts_at: before_now})
26 assert [_] = Announcement.list_all_visible_when(time)
29 test "with start time after current", %{time: time} do
30 after_now = NaiveDateTime.add(time, 10, :second)
32 _announcement = insert(:announcement, %{starts_at: after_now})
34 assert [] = Announcement.list_all_visible_when(time)
37 test "with end time after current", %{time: time} do
38 after_now = NaiveDateTime.add(time, 10, :second)
40 _announcement = insert(:announcement, %{ends_at: after_now})
42 assert [_] = Announcement.list_all_visible_when(time)
45 test "with end time before current", %{time: time} do
46 before_now = NaiveDateTime.add(time, -10, :second)
48 _announcement = insert(:announcement, %{ends_at: before_now})
50 assert [] = Announcement.list_all_visible_when(time)
53 test "with both start and end time", %{time: time} do
54 before_now = NaiveDateTime.add(time, -10, :second)
55 after_now = NaiveDateTime.add(time, 10, :second)
57 _announcement = insert(:announcement, %{starts_at: before_now, ends_at: after_now})
59 assert [_] = Announcement.list_all_visible_when(time)
62 test "with both start and end time, current not in the range", %{time: time} do
63 before_now = NaiveDateTime.add(time, -10, :second)
64 after_now = NaiveDateTime.add(time, 10, :second)
66 _announcement = insert(:announcement, %{starts_at: after_now, ends_at: before_now})
68 assert [] = Announcement.list_all_visible_when(time)
72 describe "announcements formatting" do
73 test "it formats links" do
74 raw = "something on https://pleroma.social ."
75 announcement = insert(:announcement, %{data: %{"content" => raw}})
77 assert announcement.rendered["content"] =~ ~r(<a.+?https://pleroma.social)
78 assert announcement.data["content"] == raw
81 test "it formats mentions" do
83 raw = "something on @#{user.nickname} ."
84 announcement = insert(:announcement, %{data: %{"content" => raw}})
86 assert announcement.rendered["content"] =~ ~r(<a.+?#{user.nickname})
87 assert announcement.data["content"] == raw
90 test "it formats tags" do
91 raw = "something on #mew ."
92 announcement = insert(:announcement, %{data: %{"content" => raw}})
94 assert announcement.rendered["content"] =~ ~r(<a.+?#mew)
95 assert announcement.data["content"] == raw