aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/web/mastodon_api/views/status_view_test.exs8
-rw-r--r--test/web/pleroma_api/controllers/pleroma_api_controller_test.exs24
-rw-r--r--test/web/twitter_api/twitter_api_controller_test.exs142
3 files changed, 158 insertions, 16 deletions
diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs
index fc110417c..ba58e48e8 100644
--- a/test/web/mastodon_api/views/status_view_test.exs
+++ b/test/web/mastodon_api/views/status_view_test.exs
@@ -37,15 +37,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
status = StatusView.render("show.json", activity: activity)
assert status[:pleroma][:emoji_reactions] == [
- %{emoji: "☕", count: 2, reacted: false},
- %{emoji: "🍵", count: 1, reacted: false}
+ %{name: "☕", count: 2, me: false},
+ %{name: "🍵", count: 1, me: false}
]
status = StatusView.render("show.json", activity: activity, for: user)
assert status[:pleroma][:emoji_reactions] == [
- %{emoji: "☕", count: 2, reacted: true},
- %{emoji: "🍵", count: 1, reacted: false}
+ %{name: "☕", count: 2, me: true},
+ %{name: "🍵", count: 1, me: false}
]
end
diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
index be5007de5..36868db38 100644
--- a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
+++ b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs
@@ -14,7 +14,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
import Pleroma.Factory
- test "POST /api/v1/pleroma/statuses/:id/react_with_emoji", %{conn: conn} do
+ test "PUT /api/v1/pleroma/statuses/:id/reactions/:emoji", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
@@ -24,18 +24,19 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
conn
|> assign(:user, other_user)
|> assign(:token, insert(:oauth_token, user: other_user, scopes: ["write:statuses"]))
- |> post("/api/v1/pleroma/statuses/#{activity.id}/react_with_emoji", %{"emoji" => "☕"})
+ |> put("/api/v1/pleroma/statuses/#{activity.id}/reactions/☕")
|> json_response(200)
+ # We return the status, but this our implementation detail.
assert %{"id" => id} = result
assert to_string(activity.id) == id
assert result["pleroma"]["emoji_reactions"] == [
- %{"emoji" => "☕", "count" => 1, "reacted" => true}
+ %{"name" => "☕", "count" => 1, "me" => true}
]
end
- test "POST /api/v1/pleroma/statuses/:id/unreact_with_emoji", %{conn: conn} do
+ test "DELETE /api/v1/pleroma/statuses/:id/reactions/:emoji", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
@@ -46,7 +47,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
conn
|> assign(:user, other_user)
|> assign(:token, insert(:oauth_token, user: other_user, scopes: ["write:statuses"]))
- |> post("/api/v1/pleroma/statuses/#{activity.id}/unreact_with_emoji", %{"emoji" => "☕"})
+ |> delete("/api/v1/pleroma/statuses/#{activity.id}/reactions/☕")
assert %{"id" => id} = json_response(result, 200)
assert to_string(activity.id) == id
@@ -56,7 +57,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
assert object.data["reaction_count"] == 0
end
- test "GET /api/v1/pleroma/statuses/:id/emoji_reactions_by", %{conn: conn} do
+ test "GET /api/v1/pleroma/statuses/:id/reactions", %{conn: conn} do
user = insert(:user)
other_user = insert(:user)
doomed_user = insert(:user)
@@ -65,7 +66,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
result =
conn
- |> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by")
+ |> get("/api/v1/pleroma/statuses/#{activity.id}/reactions")
|> json_response(200)
assert result == []
@@ -77,11 +78,10 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
result =
conn
- |> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by")
+ |> get("/api/v1/pleroma/statuses/#{activity.id}/reactions")
|> json_response(200)
- [%{"emoji" => "🎅", "count" => 1, "accounts" => [represented_user], "reacted" => false}] =
- result
+ [%{"name" => "🎅", "count" => 1, "accounts" => [represented_user], "me" => false}] = result
assert represented_user["id"] == other_user.id
@@ -89,10 +89,10 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
conn
|> assign(:user, other_user)
|> assign(:token, insert(:oauth_token, user: other_user, scopes: ["read:statuses"]))
- |> get("/api/v1/pleroma/statuses/#{activity.id}/emoji_reactions_by")
+ |> get("/api/v1/pleroma/statuses/#{activity.id}/reactions")
|> json_response(200)
- assert [%{"emoji" => "🎅", "count" => 1, "accounts" => [_represented_user], "reacted" => true}] =
+ assert [%{"name" => "🎅", "count" => 1, "accounts" => [_represented_user], "me" => true}] =
result
end
diff --git a/test/web/twitter_api/twitter_api_controller_test.exs b/test/web/twitter_api/twitter_api_controller_test.exs
new file mode 100644
index 000000000..ab0a2c3df
--- /dev/null
+++ b/test/web/twitter_api/twitter_api_controller_test.exs
@@ -0,0 +1,142 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.Web.TwitterAPI.ControllerTest do
+ use Pleroma.Web.ConnCase
+
+ alias Pleroma.Builders.ActivityBuilder
+ alias Pleroma.Repo
+ alias Pleroma.User
+ alias Pleroma.Web.OAuth.Token
+
+ import Pleroma.Factory
+
+ describe "POST /api/qvitter/statuses/notifications/read" do
+ test "without valid credentials", %{conn: conn} do
+ conn = post(conn, "/api/qvitter/statuses/notifications/read", %{"latest_id" => 1_234_567})
+ assert json_response(conn, 403) == %{"error" => "Invalid credentials."}
+ end
+
+ test "with credentials, without any params" do
+ %{user: current_user, conn: conn} =
+ oauth_access(["read:notifications", "write:notifications"])
+
+ conn =
+ conn
+ |> assign(:user, current_user)
+ |> post("/api/qvitter/statuses/notifications/read")
+
+ assert json_response(conn, 400) == %{
+ "error" => "You need to specify latest_id",
+ "request" => "/api/qvitter/statuses/notifications/read"
+ }
+ end
+
+ test "with credentials, with params" do
+ %{user: current_user, conn: conn} =
+ oauth_access(["read:notifications", "write:notifications"])
+
+ other_user = insert(:user)
+
+ {:ok, _activity} =
+ ActivityBuilder.insert(%{"to" => [current_user.ap_id]}, %{user: other_user})
+
+ response_conn =
+ conn
+ |> assign(:user, current_user)
+ |> get("/api/v1/notifications")
+
+ [notification] = response = json_response(response_conn, 200)
+
+ assert length(response) == 1
+
+ assert notification["pleroma"]["is_seen"] == false
+
+ response_conn =
+ conn
+ |> assign(:user, current_user)
+ |> post("/api/qvitter/statuses/notifications/read", %{"latest_id" => notification["id"]})
+
+ [notification] = response = json_response(response_conn, 200)
+
+ assert length(response) == 1
+
+ assert notification["pleroma"]["is_seen"] == true
+ end
+ end
+
+ describe "GET /api/account/confirm_email/:id/:token" do
+ setup do
+ {:ok, user} =
+ insert(:user)
+ |> User.confirmation_changeset(need_confirmation: true)
+ |> Repo.update()
+
+ assert user.confirmation_pending
+
+ [user: user]
+ end
+
+ test "it redirects to root url", %{conn: conn, user: user} do
+ conn = get(conn, "/api/account/confirm_email/#{user.id}/#{user.confirmation_token}")
+
+ assert 302 == conn.status
+ end
+
+ test "it confirms the user account", %{conn: conn, user: user} do
+ get(conn, "/api/account/confirm_email/#{user.id}/#{user.confirmation_token}")
+
+ user = User.get_cached_by_id(user.id)
+
+ refute user.confirmation_pending
+ refute user.confirmation_token
+ end
+
+ test "it returns 500 if user cannot be found by id", %{conn: conn, user: user} do
+ conn = get(conn, "/api/account/confirm_email/0/#{user.confirmation_token}")
+
+ assert 500 == conn.status
+ end
+
+ test "it returns 500 if token is invalid", %{conn: conn, user: user} do
+ conn = get(conn, "/api/account/confirm_email/#{user.id}/wrong_token")
+
+ assert 500 == conn.status
+ end
+ end
+
+ describe "GET /api/oauth_tokens" do
+ setup do
+ token = insert(:oauth_token) |> Repo.preload(:user)
+
+ %{token: token}
+ end
+
+ test "renders list", %{token: token} do
+ response =
+ build_conn()
+ |> assign(:user, token.user)
+ |> get("/api/oauth_tokens")
+
+ keys =
+ json_response(response, 200)
+ |> hd()
+ |> Map.keys()
+
+ assert keys -- ["id", "app_name", "valid_until"] == []
+ end
+
+ test "revoke token", %{token: token} do
+ response =
+ build_conn()
+ |> assign(:user, token.user)
+ |> delete("/api/oauth_tokens/#{token.id}")
+
+ tokens = Token.get_user_tokens(token.user)
+
+ assert tokens == []
+ assert response.status == 201
+ end
+ end
+end