improve tests
This commit is contained in:
parent
44a1e69484
commit
6cbe63726d
@ -1,5 +1,5 @@
|
|||||||
# Pleroma: A lightweight social networking server
|
# Pleroma: A lightweight social networking server
|
||||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.CommonAPI.Test do
|
defmodule Pleroma.Web.CommonAPI.Test do
|
||||||
@ -98,30 +98,26 @@ defmodule Pleroma.Web.CommonAPI.Test do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "pinned statuses" do
|
describe "pinned statuses" do
|
||||||
test "pin status" do
|
setup do
|
||||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
||||||
user = insert(:user)
|
|
||||||
|
|
||||||
|
user = insert(:user)
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
||||||
|
|
||||||
|
[user: user, activity: activity]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "pin status", %{user: user, activity: activity} do
|
||||||
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
|
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "only self-authored can be pinned" do
|
test "only self-authored can be pinned", %{activity: activity} do
|
||||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
|
||||||
user_one = insert(:user)
|
|
||||||
user_two = insert(:user)
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(user_one, %{"status" => "HI!!!"})
|
|
||||||
|
|
||||||
assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user_two)
|
|
||||||
end
|
|
||||||
|
|
||||||
test "max pinned statuses" do
|
|
||||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
{:ok, activity_one} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user)
|
||||||
|
end
|
||||||
|
|
||||||
|
test "max pinned statuses", %{user: user, activity: activity_one} do
|
||||||
{:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
{:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
||||||
|
|
||||||
assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user)
|
assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user)
|
||||||
@ -132,11 +128,7 @@ defmodule Pleroma.Web.CommonAPI.Test do
|
|||||||
CommonAPI.pin(activity_two.id, user)
|
CommonAPI.pin(activity_two.id, user)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "unpin status" do
|
test "unpin status", %{user: user, activity: activity} do
|
||||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
|
||||||
user = insert(:user)
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
|
||||||
{:ok, activity} = CommonAPI.pin(activity.id, user)
|
{:ok, activity} = CommonAPI.pin(activity.id, user)
|
||||||
|
|
||||||
assert {:ok, ^activity} = CommonAPI.unpin(activity.id, user)
|
assert {:ok, ^activity} = CommonAPI.unpin(activity.id, user)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
# Pleroma: A lightweight social networking server
|
# Pleroma: A lightweight social networking server
|
||||||
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
||||||
@ -1473,88 +1473,74 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "pinned statuses" do
|
describe "pinned statuses" do
|
||||||
test "returns pinned statuses", %{conn: conn} do
|
setup do
|
||||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
||||||
user = insert(:user)
|
|
||||||
|
|
||||||
|
user = insert(:user)
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
||||||
|
|
||||||
|
[user: user, activity: activity]
|
||||||
|
end
|
||||||
|
|
||||||
|
test "returns pinned statuses", %{conn: conn, user: user, activity: activity} do
|
||||||
{:ok, _} = CommonAPI.pin(activity.id, user)
|
{:ok, _} = CommonAPI.pin(activity.id, user)
|
||||||
|
|
||||||
result =
|
result =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
|
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
|
||||||
|> Map.get(:resp_body)
|
|> json_response(200)
|
||||||
|> Jason.decode!()
|
|
||||||
|
|
||||||
id_str = Integer.to_string(activity.id)
|
id_str = to_string(activity.id)
|
||||||
|
|
||||||
assert [%{"id" => ^id_str, "pinned" => true}] = result
|
assert [%{"id" => ^id_str, "pinned" => true}] = result
|
||||||
end
|
end
|
||||||
|
|
||||||
test "pin status", %{conn: conn} do
|
test "pin status", %{conn: conn, user: user, activity: activity} do
|
||||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
id_str = to_string(activity.id)
|
||||||
user = insert(:user)
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
|
||||||
id_str = Integer.to_string(activity.id)
|
|
||||||
|
|
||||||
assert %{"id" => ^id_str, "pinned" => true} =
|
assert %{"id" => ^id_str, "pinned" => true} =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|> post("/api/v1/statuses/#{activity.id}/pin")
|
|> post("/api/v1/statuses/#{activity.id}/pin")
|
||||||
|> Map.get(:resp_body)
|
|> json_response(200)
|
||||||
|> Jason.decode!()
|
|
||||||
|
|
||||||
assert [%{"id" => ^id_str, "pinned" => true}] =
|
assert [%{"id" => ^id_str, "pinned" => true}] =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
|
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
|
||||||
|> Map.get(:resp_body)
|
|> json_response(200)
|
||||||
|> Jason.decode!()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "unpin status", %{conn: conn} do
|
test "unpin status", %{conn: conn, user: user, activity: activity} do
|
||||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
|
||||||
user = insert(:user)
|
|
||||||
|
|
||||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
|
||||||
{:ok, _} = CommonAPI.pin(activity.id, user)
|
{:ok, _} = CommonAPI.pin(activity.id, user)
|
||||||
|
|
||||||
id_str = Integer.to_string(activity.id)
|
id_str = to_string(activity.id)
|
||||||
user = refresh_record(user)
|
user = refresh_record(user)
|
||||||
|
|
||||||
assert %{"id" => ^id_str, "pinned" => false} =
|
assert %{"id" => ^id_str, "pinned" => false} =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|> post("/api/v1/statuses/#{activity.id}/unpin")
|
|> post("/api/v1/statuses/#{activity.id}/unpin")
|
||||||
|> Map.get(:resp_body)
|
|> json_response(200)
|
||||||
|> Jason.decode!()
|
|
||||||
|
|
||||||
assert [] =
|
assert [] =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
|
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
|
||||||
|> Map.get(:resp_body)
|
|> json_response(200)
|
||||||
|> Jason.decode!()
|
|
||||||
end
|
end
|
||||||
|
|
||||||
test "max pinned statuses", %{conn: conn} do
|
test "max pinned statuses", %{conn: conn, user: user, activity: activity_one} do
|
||||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
|
||||||
|
|
||||||
user = insert(:user)
|
|
||||||
|
|
||||||
{:ok, activity_one} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
|
||||||
{:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
{:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
||||||
|
|
||||||
id_str_one = Integer.to_string(activity_one.id)
|
id_str_one = to_string(activity_one.id)
|
||||||
|
|
||||||
assert %{"id" => ^id_str_one, "pinned" => true} =
|
assert %{"id" => ^id_str_one, "pinned" => true} =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|> post("/api/v1/statuses/#{id_str_one}/pin")
|
|> post("/api/v1/statuses/#{id_str_one}/pin")
|
||||||
|> Map.get(:resp_body)
|
|> json_response(200)
|
||||||
|> Jason.decode!()
|
|
||||||
|
|
||||||
user = refresh_record(user)
|
user = refresh_record(user)
|
||||||
|
|
||||||
@ -1562,8 +1548,7 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||||||
conn
|
conn
|
||||||
|> assign(:user, user)
|
|> assign(:user, user)
|
||||||
|> post("/api/v1/statuses/#{activity_two.id}/pin")
|
|> post("/api/v1/statuses/#{activity_two.id}/pin")
|
||||||
|> Map.get(:resp_body)
|
|> json_response(400)
|
||||||
|> Jason.decode!()
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
Reference in New Issue
Block a user