2019-09-26 03:53:42 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-02 05:08:45 +00:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-09-26 03:53:42 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|
|
|
use Pleroma.Web.ConnCase
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
import Tesla.Mock
|
|
|
|
|
|
|
|
alias Pleroma.Config
|
|
|
|
alias Pleroma.User
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
|
|
|
setup do
|
|
|
|
mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
2019-10-08 20:05:57 +00:00
|
|
|
describe "home" do
|
2019-12-19 14:23:27 +00:00
|
|
|
setup do: oauth_access(["read:statuses"])
|
|
|
|
|
2020-05-09 15:05:44 +00:00
|
|
|
test "does NOT embed account/pleroma/relationship in statuses", %{
|
2020-04-01 16:49:09 +00:00
|
|
|
user: user,
|
|
|
|
conn: conn
|
|
|
|
} do
|
|
|
|
other_user = insert(:user)
|
|
|
|
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, _} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
|
2020-04-01 16:49:09 +00:00
|
|
|
|
|
|
|
response =
|
|
|
|
conn
|
|
|
|
|> assign(:user, user)
|
|
|
|
|> get("/api/v1/timelines/home")
|
2020-05-11 11:24:59 +00:00
|
|
|
|> json_response_and_validate_schema(200)
|
2020-04-01 16:49:09 +00:00
|
|
|
|
|
|
|
assert Enum.all?(response, fn n ->
|
|
|
|
get_in(n, ["account", "pleroma", "relationship"]) == %{}
|
|
|
|
end)
|
|
|
|
end
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
test "the home timeline when the direct messages are excluded", %{user: user, conn: conn} do
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, public_activity} = CommonAPI.post(user, %{status: ".", visibility: "public"})
|
|
|
|
{:ok, direct_activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, unlisted_activity} = CommonAPI.post(user, %{status: ".", visibility: "unlisted"})
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, private_activity} = CommonAPI.post(user, %{status: ".", visibility: "private"})
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
conn = get(conn, "/api/v1/timelines/home?exclude_visibilities[]=direct")
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert status_ids = json_response_and_validate_schema(conn, :ok) |> Enum.map(& &1["id"])
|
2019-10-08 20:05:57 +00:00
|
|
|
assert public_activity.id in status_ids
|
|
|
|
assert unlisted_activity.id in status_ids
|
|
|
|
assert private_activity.id in status_ids
|
|
|
|
refute direct_activity.id in status_ids
|
|
|
|
end
|
2019-09-26 03:53:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "public" do
|
|
|
|
@tag capture_log: true
|
|
|
|
test "the public timeline", %{conn: conn} do
|
|
|
|
following = insert(:user)
|
|
|
|
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, _activity} = CommonAPI.post(following, %{status: "test"})
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2019-10-17 23:37:21 +00:00
|
|
|
_activity = insert(:note_activity, local: false)
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
conn = get(conn, "/api/v1/timelines/public?local=False")
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert length(json_response_and_validate_schema(conn, :ok)) == 2
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
conn = get(build_conn(), "/api/v1/timelines/public?local=True")
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok)
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
conn = get(build_conn(), "/api/v1/timelines/public?local=1")
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert [%{"content" => "test"}] = json_response_and_validate_schema(conn, :ok)
|
2019-09-26 03:53:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "the public timeline includes only public statuses for an authenticated user" do
|
2019-12-19 14:23:27 +00:00
|
|
|
%{user: user, conn: conn} = oauth_access(["read:statuses"])
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, _activity} = CommonAPI.post(user, %{status: "test"})
|
|
|
|
{:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "private"})
|
|
|
|
{:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "unlisted"})
|
|
|
|
{:ok, _activity} = CommonAPI.post(user, %{status: "test", visibility: "direct"})
|
2019-09-26 03:53:42 +00:00
|
|
|
|
|
|
|
res_conn = get(conn, "/api/v1/timelines/public")
|
2020-05-11 11:24:59 +00:00
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 1
|
2019-09-26 03:53:42 +00:00
|
|
|
end
|
2020-05-20 14:45:06 +00:00
|
|
|
|
|
|
|
test "doesn't return replies if follower is posting with blocked user" do
|
|
|
|
%{conn: conn, user: blocker} = oauth_access(["read:statuses"])
|
|
|
|
[blockee, friend] = insert_list(2, :user)
|
|
|
|
{:ok, blocker} = User.follow(blocker, friend)
|
|
|
|
{:ok, _} = User.block(blocker, blockee)
|
|
|
|
|
|
|
|
conn = assign(conn, :user, blocker)
|
|
|
|
|
|
|
|
{:ok, %{id: activity_id} = activity} = CommonAPI.post(friend, %{status: "hey!"})
|
|
|
|
|
|
|
|
{:ok, reply_from_blockee} =
|
|
|
|
CommonAPI.post(blockee, %{status: "heya", in_reply_to_status_id: activity})
|
|
|
|
|
|
|
|
{:ok, _reply_from_friend} =
|
|
|
|
CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee})
|
|
|
|
|
|
|
|
res_conn = get(conn, "/api/v1/timelines/public")
|
|
|
|
[%{"id" => ^activity_id}] = json_response_and_validate_schema(res_conn, 200)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "doesn't return replies if follow is posting with users from blocked domain" do
|
|
|
|
%{conn: conn, user: blocker} = oauth_access(["read:statuses"])
|
|
|
|
friend = insert(:user)
|
|
|
|
blockee = insert(:user, ap_id: "https://example.com/users/blocked")
|
|
|
|
{:ok, blocker} = User.follow(blocker, friend)
|
|
|
|
{:ok, blocker} = User.block_domain(blocker, "example.com")
|
|
|
|
|
|
|
|
conn = assign(conn, :user, blocker)
|
|
|
|
|
|
|
|
{:ok, %{id: activity_id} = activity} = CommonAPI.post(friend, %{status: "hey!"})
|
|
|
|
|
|
|
|
{:ok, reply_from_blockee} =
|
|
|
|
CommonAPI.post(blockee, %{status: "heya", in_reply_to_status_id: activity})
|
|
|
|
|
|
|
|
{:ok, _reply_from_friend} =
|
|
|
|
CommonAPI.post(friend, %{status: "status", in_reply_to_status_id: reply_from_blockee})
|
|
|
|
|
2020-06-02 05:50:24 +00:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public")
|
2020-05-20 14:45:06 +00:00
|
|
|
|
|
|
|
activities = json_response_and_validate_schema(res_conn, 200)
|
|
|
|
[%{"id" => ^activity_id}] = activities
|
|
|
|
end
|
2019-09-26 03:53:42 +00:00
|
|
|
end
|
|
|
|
|
2020-03-20 10:04:37 +00:00
|
|
|
defp local_and_remote_activities do
|
|
|
|
insert(:note_activity)
|
|
|
|
insert(:note_activity, local: false)
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "public with restrict unauthenticated timeline for local and federated timelines" do
|
|
|
|
setup do: local_and_remote_activities()
|
|
|
|
|
2020-03-20 15:33:00 +00:00
|
|
|
setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
2020-03-20 10:04:37 +00:00
|
|
|
|
2020-03-20 15:33:00 +00:00
|
|
|
setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
2020-03-20 10:04:37 +00:00
|
|
|
|
|
|
|
test "if user is unauthenticated", %{conn: conn} do
|
2020-05-11 11:24:59 +00:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=true")
|
2020-03-20 10:04:37 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
|
2020-03-20 10:04:37 +00:00
|
|
|
"error" => "authorization required for timeline view"
|
|
|
|
}
|
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=false")
|
2020-03-20 10:04:37 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
|
2020-03-20 10:04:37 +00:00
|
|
|
"error" => "authorization required for timeline view"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "if user is authenticated" do
|
|
|
|
%{conn: conn} = oauth_access(["read:statuses"])
|
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=true")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 1
|
2020-03-20 10:04:37 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=false")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
2020-03-20 10:04:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "public with restrict unauthenticated timeline for local" do
|
|
|
|
setup do: local_and_remote_activities()
|
|
|
|
|
2020-03-20 15:33:00 +00:00
|
|
|
setup do: clear_config([:restrict_unauthenticated, :timelines, :local], true)
|
2020-03-20 10:04:37 +00:00
|
|
|
|
|
|
|
test "if user is unauthenticated", %{conn: conn} do
|
2020-05-11 11:24:59 +00:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=true")
|
2020-03-20 10:04:37 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
|
2020-03-20 10:04:37 +00:00
|
|
|
"error" => "authorization required for timeline view"
|
|
|
|
}
|
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=false")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
2020-03-20 10:04:37 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
test "if user is authenticated", %{conn: _conn} do
|
|
|
|
%{conn: conn} = oauth_access(["read:statuses"])
|
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=true")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 1
|
2020-03-20 10:04:37 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=false")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
2020-03-20 10:04:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "public with restrict unauthenticated timeline for remote" do
|
|
|
|
setup do: local_and_remote_activities()
|
|
|
|
|
2020-03-20 15:33:00 +00:00
|
|
|
setup do: clear_config([:restrict_unauthenticated, :timelines, :federated], true)
|
2020-03-20 10:04:37 +00:00
|
|
|
|
|
|
|
test "if user is unauthenticated", %{conn: conn} do
|
2020-05-11 11:24:59 +00:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=true")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 1
|
2020-03-20 10:04:37 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=false")
|
2020-03-20 10:04:37 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert json_response_and_validate_schema(res_conn, :unauthorized) == %{
|
2020-03-20 10:04:37 +00:00
|
|
|
"error" => "authorization required for timeline view"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
test "if user is authenticated", %{conn: _conn} do
|
|
|
|
%{conn: conn} = oauth_access(["read:statuses"])
|
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=true")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 1
|
2020-03-20 10:04:37 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
res_conn = get(conn, "/api/v1/timelines/public?local=false")
|
|
|
|
assert length(json_response_and_validate_schema(res_conn, 200)) == 2
|
2020-03-20 10:04:37 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-09-26 03:53:42 +00:00
|
|
|
describe "direct" do
|
|
|
|
test "direct timeline", %{conn: conn} do
|
|
|
|
user_one = insert(:user)
|
|
|
|
user_two = insert(:user)
|
|
|
|
|
|
|
|
{:ok, user_two} = User.follow(user_two, user_one)
|
|
|
|
|
|
|
|
{:ok, direct} =
|
|
|
|
CommonAPI.post(user_one, %{
|
2020-05-12 19:59:26 +00:00
|
|
|
status: "Hi @#{user_two.nickname}!",
|
|
|
|
visibility: "direct"
|
2019-09-26 03:53:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
{:ok, _follower_only} =
|
|
|
|
CommonAPI.post(user_one, %{
|
2020-05-12 19:59:26 +00:00
|
|
|
status: "Hi @#{user_two.nickname}!",
|
|
|
|
visibility: "private"
|
2019-09-26 03:53:42 +00:00
|
|
|
})
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
conn_user_two =
|
2019-09-26 03:53:42 +00:00
|
|
|
conn
|
|
|
|
|> assign(:user, user_two)
|
2019-12-19 14:23:27 +00:00
|
|
|
|> assign(:token, insert(:oauth_token, user: user_two, scopes: ["read:statuses"]))
|
|
|
|
|
|
|
|
# Only direct should be visible here
|
|
|
|
res_conn = get(conn_user_two, "api/v1/timelines/direct")
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert [status] = json_response_and_validate_schema(res_conn, :ok)
|
2019-09-26 03:53:42 +00:00
|
|
|
|
|
|
|
assert %{"visibility" => "direct"} = status
|
|
|
|
assert status["url"] != direct.data["id"]
|
|
|
|
|
|
|
|
# User should be able to see their own direct message
|
|
|
|
res_conn =
|
|
|
|
build_conn()
|
|
|
|
|> assign(:user, user_one)
|
2019-12-19 14:23:27 +00:00
|
|
|
|> assign(:token, insert(:oauth_token, user: user_one, scopes: ["read:statuses"]))
|
2019-09-26 03:53:42 +00:00
|
|
|
|> get("api/v1/timelines/direct")
|
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
[status] = json_response_and_validate_schema(res_conn, :ok)
|
2019-09-26 03:53:42 +00:00
|
|
|
|
|
|
|
assert %{"visibility" => "direct"} = status
|
|
|
|
|
|
|
|
# Both should be visible here
|
2019-12-19 14:23:27 +00:00
|
|
|
res_conn = get(conn_user_two, "api/v1/timelines/home")
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
[_s1, _s2] = json_response_and_validate_schema(res_conn, :ok)
|
2019-09-26 03:53:42 +00:00
|
|
|
|
|
|
|
# Test pagination
|
|
|
|
Enum.each(1..20, fn _ ->
|
|
|
|
{:ok, _} =
|
|
|
|
CommonAPI.post(user_one, %{
|
2020-05-12 19:59:26 +00:00
|
|
|
status: "Hi @#{user_two.nickname}!",
|
|
|
|
visibility: "direct"
|
2019-09-26 03:53:42 +00:00
|
|
|
})
|
|
|
|
end)
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
res_conn = get(conn_user_two, "api/v1/timelines/direct")
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
statuses = json_response_and_validate_schema(res_conn, :ok)
|
2019-09-26 03:53:42 +00:00
|
|
|
assert length(statuses) == 20
|
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
max_id = List.last(statuses)["id"]
|
|
|
|
|
|
|
|
res_conn = get(conn_user_two, "api/v1/timelines/direct?max_id=#{max_id}")
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert [status] = json_response_and_validate_schema(res_conn, :ok)
|
2019-09-26 03:53:42 +00:00
|
|
|
|
|
|
|
assert status["url"] != direct.data["id"]
|
|
|
|
end
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
test "doesn't include DMs from blocked users" do
|
|
|
|
%{user: blocker, conn: conn} = oauth_access(["read:statuses"])
|
2019-09-26 03:53:42 +00:00
|
|
|
blocked = insert(:user)
|
2019-12-19 14:23:27 +00:00
|
|
|
other_user = insert(:user)
|
2019-11-19 20:22:10 +00:00
|
|
|
{:ok, _user_relationship} = User.block(blocker, blocked)
|
2019-09-26 03:53:42 +00:00
|
|
|
|
|
|
|
{:ok, _blocked_direct} =
|
|
|
|
CommonAPI.post(blocked, %{
|
2020-05-12 19:59:26 +00:00
|
|
|
status: "Hi @#{blocker.nickname}!",
|
|
|
|
visibility: "direct"
|
2019-09-26 03:53:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
{:ok, direct} =
|
2019-12-19 14:23:27 +00:00
|
|
|
CommonAPI.post(other_user, %{
|
2020-05-12 19:59:26 +00:00
|
|
|
status: "Hi @#{blocker.nickname}!",
|
|
|
|
visibility: "direct"
|
2019-09-26 03:53:42 +00:00
|
|
|
})
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
res_conn = get(conn, "api/v1/timelines/direct")
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
[status] = json_response_and_validate_schema(res_conn, :ok)
|
2019-09-26 03:53:42 +00:00
|
|
|
assert status["id"] == direct.id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "list" do
|
2019-12-19 14:23:27 +00:00
|
|
|
setup do: oauth_access(["read:lists"])
|
|
|
|
|
|
|
|
test "list timeline", %{user: user, conn: conn} do
|
2019-09-26 03:53:42 +00:00
|
|
|
other_user = insert(:user)
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, _activity_one} = CommonAPI.post(user, %{status: "Marisa is cute."})
|
|
|
|
{:ok, activity_two} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
|
2019-09-26 03:53:42 +00:00
|
|
|
{:ok, list} = Pleroma.List.create("name", user)
|
|
|
|
{:ok, list} = Pleroma.List.follow(list, other_user)
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
conn = get(conn, "/api/v1/timelines/list/#{list.id}")
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
|
2019-09-26 03:53:42 +00:00
|
|
|
|
|
|
|
assert id == to_string(activity_two.id)
|
|
|
|
end
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
test "list timeline does not leak non-public statuses for unfollowed users", %{
|
|
|
|
user: user,
|
|
|
|
conn: conn
|
|
|
|
} do
|
2019-09-26 03:53:42 +00:00
|
|
|
other_user = insert(:user)
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, activity_one} = CommonAPI.post(other_user, %{status: "Marisa is cute."})
|
2019-09-26 03:53:42 +00:00
|
|
|
|
|
|
|
{:ok, _activity_two} =
|
|
|
|
CommonAPI.post(other_user, %{
|
2020-05-12 19:59:26 +00:00
|
|
|
status: "Marisa is cute.",
|
|
|
|
visibility: "private"
|
2019-09-26 03:53:42 +00:00
|
|
|
})
|
|
|
|
|
|
|
|
{:ok, list} = Pleroma.List.create("name", user)
|
|
|
|
{:ok, list} = Pleroma.List.follow(list, other_user)
|
|
|
|
|
2019-12-19 14:23:27 +00:00
|
|
|
conn = get(conn, "/api/v1/timelines/list/#{list.id}")
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert [%{"id" => id}] = json_response_and_validate_schema(conn, :ok)
|
2019-09-26 03:53:42 +00:00
|
|
|
|
|
|
|
assert id == to_string(activity_one.id)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "hashtag" do
|
2019-12-19 14:23:27 +00:00
|
|
|
setup do: oauth_access(["n/a"])
|
|
|
|
|
2019-09-26 03:53:42 +00:00
|
|
|
@tag capture_log: true
|
|
|
|
test "hashtag timeline", %{conn: conn} do
|
|
|
|
following = insert(:user)
|
|
|
|
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, activity} = CommonAPI.post(following, %{status: "test #2hu"})
|
2019-09-26 03:53:42 +00:00
|
|
|
|
|
|
|
nconn = get(conn, "/api/v1/timelines/tag/2hu")
|
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok)
|
2019-09-26 03:53:42 +00:00
|
|
|
|
|
|
|
assert id == to_string(activity.id)
|
|
|
|
|
|
|
|
# works for different capitalization too
|
|
|
|
nconn = get(conn, "/api/v1/timelines/tag/2HU")
|
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert [%{"id" => id}] = json_response_and_validate_schema(nconn, :ok)
|
2019-09-26 03:53:42 +00:00
|
|
|
|
|
|
|
assert id == to_string(activity.id)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "multi-hashtag timeline", %{conn: conn} do
|
|
|
|
user = insert(:user)
|
|
|
|
|
2020-05-12 19:59:26 +00:00
|
|
|
{:ok, activity_test} = CommonAPI.post(user, %{status: "#test"})
|
|
|
|
{:ok, activity_test1} = CommonAPI.post(user, %{status: "#test #test1"})
|
|
|
|
{:ok, activity_none} = CommonAPI.post(user, %{status: "#test #none"})
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
any_test = get(conn, "/api/v1/timelines/tag/test?any[]=test1")
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
[status_none, status_test1, status_test] = json_response_and_validate_schema(any_test, :ok)
|
2019-09-26 03:53:42 +00:00
|
|
|
|
|
|
|
assert to_string(activity_test.id) == status_test["id"]
|
|
|
|
assert to_string(activity_test1.id) == status_test1["id"]
|
|
|
|
assert to_string(activity_none.id) == status_none["id"]
|
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
restricted_test = get(conn, "/api/v1/timelines/tag/test?all[]=test1&none[]=none")
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert [status_test1] == json_response_and_validate_schema(restricted_test, :ok)
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
all_test = get(conn, "/api/v1/timelines/tag/test?all[]=none")
|
2019-09-26 03:53:42 +00:00
|
|
|
|
2020-05-11 11:24:59 +00:00
|
|
|
assert [status_none] == json_response_and_validate_schema(all_test, :ok)
|
2019-09-26 03:53:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|