Add tests for static_fe controller.
authorPhil Hagelberg <phil@hagelb.org>
Fri, 8 Nov 2019 06:29:46 +0000 (22:29 -0800)
committerPhil Hagelberg <phil@hagelb.org>
Sun, 10 Nov 2019 02:08:45 +0000 (18:08 -0800)
test/web/static_fe/static_fe_controller_test.exs [new file with mode: 0644]

diff --git a/test/web/static_fe/static_fe_controller_test.exs b/test/web/static_fe/static_fe_controller_test.exs
new file mode 100644 (file)
index 0000000..9099540
--- /dev/null
@@ -0,0 +1,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