Merge branch 'authenticated-profile-fetching' into 'develop'
[akkoma] / test / web / twitter_api / twitter_api_controller_test.exs
index 2c89509ff1bed8aad114039ab4f01ed31cdf4d84..798309f7d2505fc631f8273e3a3ef72754ff8179 100644 (file)
@@ -5,6 +5,7 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
   alias Pleroma.{Repo, Activity, User, Object}
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.TwitterAPI.UserView
+  alias Pleroma.Web.CommonAPI
 
   import Pleroma.Factory
 
@@ -404,11 +405,13 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
   describe "GET /api/externalprofile/show" do
     test "it returns the user", %{conn: conn} do
       user = insert(:user)
+      other_user = insert(:user)
 
       conn = conn
-      |> get("/api/externalprofile/show", %{profileurl: user.ap_id})
+      |> assign(:user, user)
+      |> get("/api/externalprofile/show", %{profileurl: other_user.ap_id})
 
-      assert json_response(conn, 200) == UserView.render("show.json", %{user: user})
+      assert json_response(conn, 200) == UserView.render("show.json", %{user: other_user})
     end
   end
 
@@ -473,4 +476,36 @@ defmodule Pleroma.Web.TwitterAPI.ControllerTest do
     header_content = "Basic " <> Base.encode64("#{username}:#{password}")
     put_req_header(conn, "authorization", header_content)
   end
+
+  describe "GET /api/search.json" do
+    test "it returns search results", %{conn: conn} do
+      user = insert(:user)
+      user_two = insert(:user, %{nickname: "shp@shitposter.club"})
+
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "This is about 2hu"})
+      {:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
+
+      conn = conn
+      |> get("/api/search.json", %{"q" => "2hu", "page" => "1", "rpp" => "1"})
+
+      assert [status] = json_response(conn, 200)
+      assert status["id"] == activity.id
+    end
+  end
+
+  describe "GET /api/statusnet/tags/timeline/:tag.json" do
+    test "it returns the tags timeline" do
+      user = insert(:user)
+      user_two = insert(:user, %{nickname: "shp@shitposter.club"})
+
+      {:ok, activity} = CommonAPI.post(user, %{"status" => "This is about #2hu"})
+      {:ok, _} = CommonAPI.post(user_two, %{"status" => "This isn't"})
+
+      conn = conn
+      |> get("/api/statusnet/tags/timeline/2hu.json")
+
+      assert [status] = json_response(conn, 200)
+      assert status["id"] == activity.id
+    end
+  end
 end