Merge branch 'develop' into 'reactions'
# Conflicts: # CHANGELOG.md
This commit is contained in:
commit
61097ba6ab
28 changed files with 592 additions and 187 deletions
|
|
@ -6,6 +6,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
use Pleroma.DataCase
|
||||
import Pleroma.Factory
|
||||
alias Pleroma.Conversation.Participation
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
test "getting a participation will also preload things" do
|
||||
|
|
@ -30,6 +31,8 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
{:ok, activity} =
|
||||
CommonAPI.post(user, %{"status" => "Hey @#{other_user.nickname}.", "visibility" => "direct"})
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
other_user = User.get_cached_by_id(user.id)
|
||||
[participation] = Participation.for_user(user)
|
||||
participation = Pleroma.Repo.preload(participation, :recipients)
|
||||
|
||||
|
|
@ -155,6 +158,7 @@ defmodule Pleroma.Conversation.ParticipationTest do
|
|||
[participation] = Participation.for_user_with_last_activity_id(user)
|
||||
|
||||
participation = Repo.preload(participation, :recipients)
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
assert participation.recipients |> length() == 1
|
||||
assert user in participation.recipients
|
||||
|
|
|
|||
43
test/fixtures/bogus-mastodon-announce.json
vendored
Normal file
43
test/fixtures/bogus-mastodon-announce.json
vendored
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
{
|
||||
"type": "Announce",
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"published": "2018-02-17T19:39:15Z",
|
||||
"object": {
|
||||
"type": "Note",
|
||||
"id": "https://mastodon.social/users/emelie/statuses/101849165031453404",
|
||||
"attributedTo": "https://mastodon.social/users/emelie",
|
||||
"content": "this is a public toot",
|
||||
"to": [
|
||||
"https://www.w3.org/ns/activitystreams#Public"
|
||||
],
|
||||
"cc": [
|
||||
"https://mastodon.social/users/emelie",
|
||||
"https://mastodon.social/users/emelie/followers"
|
||||
]
|
||||
},
|
||||
"id": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
|
||||
"cc": [
|
||||
"http://mastodon.example.org/users/admin",
|
||||
"http://mastodon.example.org/users/admin/followers"
|
||||
],
|
||||
"atomUri": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
|
||||
"actor": "http://mastodon.example.org/users/admin",
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"sensitive": "as:sensitive",
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"movedTo": "as:movedTo",
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"Emoji": "toot:Emoji"
|
||||
}
|
||||
]
|
||||
}
|
||||
35
test/fixtures/mastodon-announce-private.json
vendored
Normal file
35
test/fixtures/mastodon-announce-private.json
vendored
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
{
|
||||
"type": "Announce",
|
||||
"to": [
|
||||
"http://mastodon.example.org/users/admin/followers"
|
||||
],
|
||||
"published": "2018-02-17T19:39:15Z",
|
||||
"object": {
|
||||
"type": "Note",
|
||||
"id": "http://mastodon.example.org/@admin/99541947525187368",
|
||||
"attributedTo": "http://mastodon.example.org/users/admin",
|
||||
"content": "this is a private toot",
|
||||
"to": [
|
||||
"http://mastodon.example.org/users/admin/followers"
|
||||
]
|
||||
},
|
||||
"id": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
|
||||
"atomUri": "http://mastodon.example.org/users/admin/statuses/99542391527669785/activity",
|
||||
"actor": "http://mastodon.example.org/users/admin",
|
||||
"@context": [
|
||||
"https://www.w3.org/ns/activitystreams",
|
||||
"https://w3id.org/security/v1",
|
||||
{
|
||||
"toot": "http://joinmastodon.org/ns#",
|
||||
"sensitive": "as:sensitive",
|
||||
"ostatus": "http://ostatus.org#",
|
||||
"movedTo": "as:movedTo",
|
||||
"manuallyApprovesFollowers": "as:manuallyApprovesFollowers",
|
||||
"inReplyToAtomUri": "ostatus:inReplyToAtomUri",
|
||||
"conversation": "ostatus:conversation",
|
||||
"atomUri": "ostatus:atomUri",
|
||||
"Hashtag": "as:Hashtag",
|
||||
"Emoji": "toot:Emoji"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -46,6 +46,14 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("https://mastodon.social/users/emelie/statuses/101849165031453404", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 404,
|
||||
body: ""
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://mastodon.social/users/emelie", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
@ -349,6 +357,14 @@ defmodule HttpRequestMock do
|
|||
}}
|
||||
end
|
||||
|
||||
def get("http://mastodon.example.org/@admin/99541947525187368", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
status: 404,
|
||||
body: ""
|
||||
}}
|
||||
end
|
||||
|
||||
def get("https://shitposter.club/notice/7369654", _, _, _) do
|
||||
{:ok,
|
||||
%Tesla.Env{
|
||||
|
|
|
|||
|
|
@ -479,6 +479,33 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
assert Activity.get_create_by_object_ap_id(data["object"]).id == activity.id
|
||||
end
|
||||
|
||||
test "it works for incoming announces with an inlined activity" do
|
||||
data =
|
||||
File.read!("test/fixtures/mastodon-announce-private.json")
|
||||
|> Poison.decode!()
|
||||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data)
|
||||
|
||||
assert data["actor"] == "http://mastodon.example.org/users/admin"
|
||||
assert data["type"] == "Announce"
|
||||
|
||||
assert data["id"] ==
|
||||
"http://mastodon.example.org/users/admin/statuses/99542391527669785/activity"
|
||||
|
||||
object = Object.normalize(data["object"])
|
||||
|
||||
assert object.data["id"] == "http://mastodon.example.org/@admin/99541947525187368"
|
||||
assert object.data["content"] == "this is a private toot"
|
||||
end
|
||||
|
||||
test "it rejects incoming announces with an inlined activity from another origin" do
|
||||
data =
|
||||
File.read!("test/fixtures/bogus-mastodon-announce.json")
|
||||
|> Poison.decode!()
|
||||
|
||||
assert :error = Transmogrifier.handle_incoming(data)
|
||||
end
|
||||
|
||||
test "it does not clobber the addressing on announce activities" do
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "hey"})
|
||||
|
|
@ -597,6 +624,8 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do
|
|||
|
||||
{:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(update_data)
|
||||
|
||||
assert data["id"] == update_data["id"]
|
||||
|
||||
user = User.get_cached_by_ap_id(data["actor"])
|
||||
assert user.name == "gargle"
|
||||
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
require Pleroma.Constants
|
||||
|
||||
clear_config([:instance, :safe_dm_mentions])
|
||||
clear_config([:instance, :limit])
|
||||
clear_config([:instance, :max_pinned_statuses])
|
||||
|
|
@ -96,11 +98,13 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
test "it adds emoji when updating profiles" do
|
||||
user = insert(:user, %{name: ":firefox:"})
|
||||
|
||||
CommonAPI.update(user)
|
||||
{:ok, activity} = CommonAPI.update(user)
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
[firefox] = user.info.source_data["tag"]
|
||||
|
||||
assert firefox["name"] == ":firefox:"
|
||||
|
||||
assert Pleroma.Constants.as_public() in activity.recipients
|
||||
end
|
||||
|
||||
describe "posting" do
|
||||
|
|
|
|||
|
|
@ -328,7 +328,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
account =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||
|> json_response(200)
|
||||
|
||||
assert account["fields"] == [
|
||||
|
|
@ -344,6 +344,35 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
%{"name" => "link", "value" => "cofe.io"}
|
||||
]
|
||||
|
||||
fields =
|
||||
[
|
||||
"fields_attributes[1][name]=link",
|
||||
"fields_attributes[1][value]=cofe.io",
|
||||
"fields_attributes[0][name]=<a href=\"http://google.com\">foo</a>",
|
||||
"fields_attributes[0][value]=bar"
|
||||
]
|
||||
|> Enum.join("&")
|
||||
|
||||
account =
|
||||
conn
|
||||
|> put_req_header("content-type", "application/x-www-form-urlencoded")
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", fields)
|
||||
|> json_response(200)
|
||||
|
||||
assert account["fields"] == [
|
||||
%{"name" => "foo", "value" => "bar"},
|
||||
%{"name" => "link", "value" => ~S(<a href="http://cofe.io" rel="ugc">cofe.io</a>)}
|
||||
]
|
||||
|
||||
assert account["source"]["fields"] == [
|
||||
%{
|
||||
"name" => "<a href=\"http://google.com\">foo</a>",
|
||||
"value" => "bar"
|
||||
},
|
||||
%{"name" => "link", "value" => "cofe.io"}
|
||||
]
|
||||
|
||||
name_limit = Pleroma.Config.get([:instance, :account_field_name_length])
|
||||
value_limit = Pleroma.Config.get([:instance, :account_field_value_length])
|
||||
|
||||
|
|
@ -354,7 +383,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert %{"error" => "Invalid request"} ==
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||
|> json_response(403)
|
||||
|
||||
long_name = Enum.map(0..name_limit, fn _ -> "x" end) |> Enum.join()
|
||||
|
|
@ -364,7 +393,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert %{"error" => "Invalid request"} ==
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||
|> json_response(403)
|
||||
|
||||
Pleroma.Config.put([:instance, :max_account_fields], 1)
|
||||
|
|
@ -377,8 +406,23 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIController.UpdateCredentialsTest do
|
|||
assert %{"error" => "Invalid request"} ==
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields" => fields})
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||
|> json_response(403)
|
||||
|
||||
fields = [
|
||||
%{"name" => "foo", "value" => ""},
|
||||
%{"name" => "", "value" => "bar"}
|
||||
]
|
||||
|
||||
account =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> patch("/api/v1/accounts/update_credentials", %{"fields_attributes" => fields})
|
||||
|> json_response(200)
|
||||
|
||||
assert account["fields"] == [
|
||||
%{"name" => "foo", "value" => ""}
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -849,4 +849,34 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do
|
|||
assert [] = json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
test "getting a list of mutes", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, user} = User.mute(user, other_user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes")
|
||||
|
||||
other_user_id = to_string(other_user.id)
|
||||
assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "getting a list of blocks", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, user} = User.block(user, other_user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/blocks")
|
||||
|
||||
other_user_id = to_string(other_user.id)
|
||||
assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -10,19 +10,23 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "Conversations", %{conn: conn} do
|
||||
test "returns a list of conversations", %{conn: conn} do
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
user_three = insert(:user)
|
||||
|
||||
{:ok, user_two} = User.follow(user_two, user_one)
|
||||
|
||||
assert User.get_cached_by_id(user_two.id).info.unread_conversation_count == 0
|
||||
|
||||
{:ok, direct} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}, @#{user_three.nickname}!",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
assert User.get_cached_by_id(user_two.id).info.unread_conversation_count == 1
|
||||
|
||||
{:ok, _follower_only} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}!",
|
||||
|
|
@ -52,23 +56,100 @@ defmodule Pleroma.Web.MastodonAPI.ConversationControllerTest do
|
|||
assert is_binary(res_id)
|
||||
assert unread == true
|
||||
assert res_last_status["id"] == direct.id
|
||||
assert User.get_cached_by_id(user_one.id).info.unread_conversation_count == 1
|
||||
end
|
||||
|
||||
test "updates the last_status on reply", %{conn: conn} do
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
{:ok, direct} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
{:ok, direct_reply} =
|
||||
CommonAPI.post(user_two, %{
|
||||
"status" => "reply",
|
||||
"visibility" => "direct",
|
||||
"in_reply_to_status_id" => direct.id
|
||||
})
|
||||
|
||||
[%{"last_status" => res_last_status}] =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> get("/api/v1/conversations")
|
||||
|> json_response(200)
|
||||
|
||||
assert res_last_status["id"] == direct_reply.id
|
||||
end
|
||||
|
||||
test "the user marks a conversation as read", %{conn: conn} do
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
{:ok, direct} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
[%{"id" => direct_conversation_id, "unread" => true}] =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> get("/api/v1/conversations")
|
||||
|> json_response(200)
|
||||
|
||||
%{"unread" => false} =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> post("/api/v1/conversations/#{direct_conversation_id}/read")
|
||||
|> json_response(200)
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).info.unread_conversation_count == 0
|
||||
|
||||
# The conversation is marked as unread on reply
|
||||
{:ok, _} =
|
||||
CommonAPI.post(user_two, %{
|
||||
"status" => "reply",
|
||||
"visibility" => "direct",
|
||||
"in_reply_to_status_id" => direct.id
|
||||
})
|
||||
|
||||
[%{"unread" => true}] =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> get("/api/v1/conversations")
|
||||
|> json_response(200)
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).info.unread_conversation_count == 1
|
||||
|
||||
# A reply doesn't increment the user's unread_conversation_count if the conversation is unread
|
||||
{:ok, _} =
|
||||
CommonAPI.post(user_two, %{
|
||||
"status" => "reply",
|
||||
"visibility" => "direct",
|
||||
"in_reply_to_status_id" => direct.id
|
||||
})
|
||||
|
||||
assert User.get_cached_by_id(user_one.id).info.unread_conversation_count == 1
|
||||
end
|
||||
|
||||
test "(vanilla) Mastodon frontend behaviour", %{conn: conn} do
|
||||
user_one = insert(:user)
|
||||
user_two = insert(:user)
|
||||
|
||||
{:ok, direct} =
|
||||
CommonAPI.post(user_one, %{
|
||||
"status" => "Hi @#{user_two.nickname}!",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
# Apparently undocumented API endpoint
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> post("/api/v1/conversations/#{res_id}/read")
|
||||
|
||||
assert response = json_response(res_conn, 200)
|
||||
assert length(response["accounts"]) == 2
|
||||
assert response["last_status"]["id"] == direct.id
|
||||
assert response["unread"] == false
|
||||
|
||||
# (vanilla) Mastodon frontend behaviour
|
||||
res_conn =
|
||||
conn
|
||||
|> assign(:user, user_one)
|
||||
|> get("/api/v1/statuses/#{res_last_status["id"]}/context")
|
||||
|> get("/api/v1/statuses/#{direct.id}/context")
|
||||
|
||||
assert %{"ancestors" => [], "descendants" => []} == json_response(res_conn, 200)
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1242,4 +1242,51 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
"descendants" => [%{"id" => ^id4}, %{"id" => ^id5}]
|
||||
} = response
|
||||
end
|
||||
|
||||
test "returns the favorites of a user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _} = CommonAPI.post(other_user, %{"status" => "bla"})
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "traps are happy"})
|
||||
|
||||
{:ok, _, _} = CommonAPI.favorite(activity.id, user)
|
||||
|
||||
first_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/favourites")
|
||||
|
||||
assert [status] = json_response(first_conn, 200)
|
||||
assert status["id"] == to_string(activity.id)
|
||||
|
||||
assert [{"link", _link_header}] =
|
||||
Enum.filter(first_conn.resp_headers, fn element -> match?({"link", _}, element) end)
|
||||
|
||||
# Honours query params
|
||||
{:ok, second_activity} =
|
||||
CommonAPI.post(other_user, %{
|
||||
"status" =>
|
||||
"Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful."
|
||||
})
|
||||
|
||||
{:ok, _, _} = CommonAPI.favorite(second_activity.id, user)
|
||||
|
||||
last_like = status["id"]
|
||||
|
||||
second_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/favourites?since_id=#{last_like}")
|
||||
|
||||
assert [second_status] = json_response(second_conn, 200)
|
||||
assert second_status["id"] == to_string(second_activity.id)
|
||||
|
||||
third_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/favourites?limit=0")
|
||||
|
||||
assert [] = json_response(third_conn, 200)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -7,7 +7,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
alias Pleroma.Notification
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -20,36 +19,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
clear_config([:rich_media, :enabled])
|
||||
|
||||
test "getting a list of mutes", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, user} = User.mute(user, other_user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/mutes")
|
||||
|
||||
other_user_id = to_string(other_user.id)
|
||||
assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "getting a list of blocks", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, user} = User.block(user, other_user)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/blocks")
|
||||
|
||||
other_user_id = to_string(other_user.id)
|
||||
assert [%{"id" => ^other_user_id}] = json_response(conn, 200)
|
||||
end
|
||||
|
||||
test "unimplemented follow_requests, blocks, domain blocks" do
|
||||
user = insert(:user)
|
||||
|
||||
|
|
@ -64,53 +33,6 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
end)
|
||||
end
|
||||
|
||||
test "returns the favorites of a user", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _} = CommonAPI.post(other_user, %{"status" => "bla"})
|
||||
{:ok, activity} = CommonAPI.post(other_user, %{"status" => "traps are happy"})
|
||||
|
||||
{:ok, _, _} = CommonAPI.favorite(activity.id, user)
|
||||
|
||||
first_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/favourites")
|
||||
|
||||
assert [status] = json_response(first_conn, 200)
|
||||
assert status["id"] == to_string(activity.id)
|
||||
|
||||
assert [{"link", _link_header}] =
|
||||
Enum.filter(first_conn.resp_headers, fn element -> match?({"link", _}, element) end)
|
||||
|
||||
# Honours query params
|
||||
{:ok, second_activity} =
|
||||
CommonAPI.post(other_user, %{
|
||||
"status" =>
|
||||
"Trees Are Never Sad Look At Them Every Once In Awhile They're Quite Beautiful."
|
||||
})
|
||||
|
||||
{:ok, _, _} = CommonAPI.favorite(second_activity.id, user)
|
||||
|
||||
last_like = status["id"]
|
||||
|
||||
second_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/favourites?since_id=#{last_like}")
|
||||
|
||||
assert [second_status] = json_response(second_conn, 200)
|
||||
assert second_status["id"] == to_string(second_activity.id)
|
||||
|
||||
third_conn =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/favourites?limit=0")
|
||||
|
||||
assert [] = json_response(third_conn, 200)
|
||||
end
|
||||
|
||||
describe "link headers" do
|
||||
test "preserves parameters in link headers", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -418,6 +418,27 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
following_count: 1
|
||||
} = AccountView.render("show.json", %{user: user, for: user})
|
||||
end
|
||||
|
||||
test "shows unread_conversation_count only to the account owner" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _activity} =
|
||||
CommonAPI.post(user, %{
|
||||
"status" => "Hey @#{other_user.nickname}.",
|
||||
"visibility" => "direct"
|
||||
})
|
||||
|
||||
user = User.get_cached_by_ap_id(user.ap_id)
|
||||
|
||||
assert AccountView.render("show.json", %{user: user, for: other_user})[:pleroma][
|
||||
:unread_conversation_count
|
||||
] == nil
|
||||
|
||||
assert AccountView.render("show.json", %{user: user, for: user})[:pleroma][
|
||||
:unread_conversation_count
|
||||
] == 1
|
||||
end
|
||||
end
|
||||
|
||||
describe "follow requests counter" do
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|
|||
alias Pleroma.Notification
|
||||
alias Pleroma.Object
|
||||
alias Pleroma.Repo
|
||||
alias Pleroma.User
|
||||
alias Pleroma.Web.CommonAPI
|
||||
|
||||
import Pleroma.Factory
|
||||
|
|
@ -133,6 +134,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do
|
|||
|
||||
participation = Repo.preload(participation, :recipients)
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
assert [user] == participation.recipients
|
||||
assert other_user not in participation.recipients
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue