1 defmodule Pleroma.Web.MastodonAPI.TagControllerTest do
2 use Pleroma.Web.ConnCase
10 mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
14 describe "GET /api/v1/tags/:id" do
15 test "returns 200 with tag" do
16 %{user: user, conn: conn} = oauth_access(["read"])
18 tag = insert(:hashtag, name: "jubjub")
19 {:ok, _user} = User.follow_hashtag(user, tag)
23 |> get("/api/v1/tags/jubjub")
24 |> json_response_and_validate_schema(200)
28 "url" => "http://localhost:4001/tags/jubjub",
34 test "returns 404 with unknown tag" do
35 %{conn: conn} = oauth_access(["read"])
38 |> get("/api/v1/tags/jubjub")
39 |> json_response_and_validate_schema(404)
43 describe "POST /api/v1/tags/:id/follow" do
44 test "should follow a hashtag" do
45 %{user: user, conn: conn} = oauth_access(["write:follows"])
46 hashtag = insert(:hashtag, name: "jubjub")
50 |> post("/api/v1/tags/jubjub/follow")
51 |> json_response_and_validate_schema(200)
53 assert response["following"] == true
54 user = User.get_cached_by_ap_id(user.ap_id)
55 assert User.following_hashtag?(user, hashtag)
58 test "should 404 if hashtag doesn't exist" do
59 %{conn: conn} = oauth_access(["write:follows"])
63 |> post("/api/v1/tags/rubrub/follow")
64 |> json_response_and_validate_schema(404)
66 assert response["error"] == "Hashtag not found"
70 describe "POST /api/v1/tags/:id/unfollow" do
71 test "should unfollow a hashtag" do
72 %{user: user, conn: conn} = oauth_access(["write:follows"])
73 hashtag = insert(:hashtag, name: "jubjub")
74 {:ok, user} = User.follow_hashtag(user, hashtag)
78 |> post("/api/v1/tags/jubjub/unfollow")
79 |> json_response_and_validate_schema(200)
81 assert response["following"] == false
82 user = User.get_cached_by_ap_id(user.ap_id)
83 refute User.following_hashtag?(user, hashtag)
86 test "should 404 if hashtag doesn't exist" do
87 %{conn: conn} = oauth_access(["write:follows"])
91 |> post("/api/v1/tags/rubrub/unfollow")
92 |> json_response_and_validate_schema(404)
94 assert response["error"] == "Hashtag not found"