summaryrefslogtreecommitdiff
path: root/test/web/static_fe/static_fe_controller_test.exs
blob: 9099540bd2302acd00a3e5b55cbad1fc0ab7cfce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
defmodule Pleroma.Web.StaticFE.StaticFEControllerTest do
  use Pleroma.Web.ConnCase
  alias Pleroma.Web.CommonAPI
  import Pleroma.Factory

  clear_config_all([:static_fe, :enabled]) do
    Pleroma.Config.put([:static_fe, :enabled], true)
  end

  describe "user profile page" do
    test "just the profile as HTML", %{conn: conn} do
      user = insert(:user)
      conn = conn
      |> put_req_header("accept", "text/html")
      |> get("/users/#{user.nickname}")

      assert html_response(conn, 200) =~ user.nickname
    end

    test "renders json unless there's an html accept header", %{conn: conn} do
      user = insert(:user)
      conn = conn
      |> put_req_header("accept", "application/json")
      |> get("/users/#{user.nickname}")

      assert json_response(conn, 200)
    end

    test "404 when user not found", %{conn: conn} do
      conn = conn
      |> put_req_header("accept", "text/html")
      |> get("/users/limpopo")

      assert html_response(conn, 404) =~ "not found"
    end

    test "pagination", %{conn: conn} do
      user = insert(:user)
      Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
      conn = conn
      |> put_req_header("accept", "text/html")
      |> get("/users/#{user.nickname}")
      html = html_response(conn, 200)

      assert html =~ ">test30<"
      assert html =~ ">test11<"
      refute html =~ ">test10<"
      refute html =~ ">test1<"
    end

    test "pagination, page 2", %{conn: conn} do
      user = insert(:user)
      activities =
        Enum.map(1..30, fn i -> CommonAPI.post(user, %{"status" => "test#{i}"}) end)
      {:ok, a11} = Enum.at(activities, 11)
      conn = conn
      |> put_req_header("accept", "text/html")
      |> get("/users/#{user.nickname}?max_id=#{a11.id}")
      html = html_response(conn, 200)

      assert html =~ ">test1<"
      assert html =~ ">test10<"
      refute html =~ ">test20<"
      refute html =~ ">test29<"
    end
  end

  describe "notice rendering" do
    test "single notice page", %{conn: conn} do
      user = insert(:user)
      {:ok, activity} = CommonAPI.post(user, %{"status" => "testing a thing!"})

      conn = conn
      |> put_req_header("accept", "text/html")
      |> get("/notice/#{activity.id}")

      html = html_response(conn, 200)
      assert html =~ "<header>"
      assert html =~ user.nickname
      assert html =~ "testing a thing!"
    end

    test "404 when notice not found", %{conn: conn} do
      conn = conn
      |> put_req_header("accept", "text/html")
      |> get("/notice/88c9c317")

      assert html_response(conn, 404) =~ "not found"
    end
  end
end