improve tests
This commit is contained in:
parent
44a1e69484
commit
6cbe63726d
2 changed files with 35 additions and 58 deletions
|
@ -1,5 +1,5 @@
|
|||
# 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
|
||||
|
||||
defmodule Pleroma.Web.CommonAPI.Test do
|
||||
|
@ -98,30 +98,26 @@ test "favoriting a status twice returns an error" do
|
|||
end
|
||||
|
||||
describe "pinned statuses" do
|
||||
test "pin status" do
|
||||
setup do
|
||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
||||
user = insert(:user)
|
||||
|
||||
user = insert(:user)
|
||||
{: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)
|
||||
end
|
||||
|
||||
test "only self-authored can be pinned" 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)
|
||||
test "only self-authored can be pinned", %{activity: activity} do
|
||||
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!!!"})
|
||||
|
||||
assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user)
|
||||
|
@ -132,11 +128,7 @@ test "max pinned statuses" do
|
|||
CommonAPI.pin(activity_two.id, user)
|
||||
end
|
||||
|
||||
test "unpin status" do
|
||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
||||
test "unpin status", %{user: user, activity: activity} do
|
||||
{:ok, activity} = CommonAPI.pin(activity.id, user)
|
||||
|
||||
assert {:ok, ^activity} = CommonAPI.unpin(activity.id, user)
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
# 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
|
||||
|
||||
defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
||||
|
@ -1473,88 +1473,74 @@ test "put settings", %{conn: conn} do
|
|||
end
|
||||
|
||||
describe "pinned statuses" do
|
||||
test "returns pinned statuses", %{conn: conn} do
|
||||
setup do
|
||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
||||
user = insert(:user)
|
||||
|
||||
user = insert(:user)
|
||||
{: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)
|
||||
|
||||
result =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
|
||||
|> Map.get(:resp_body)
|
||||
|> Jason.decode!()
|
||||
|> json_response(200)
|
||||
|
||||
id_str = Integer.to_string(activity.id)
|
||||
id_str = to_string(activity.id)
|
||||
|
||||
assert [%{"id" => ^id_str, "pinned" => true}] = result
|
||||
end
|
||||
|
||||
test "pin status", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
||||
id_str = Integer.to_string(activity.id)
|
||||
test "pin status", %{conn: conn, user: user, activity: activity} do
|
||||
id_str = to_string(activity.id)
|
||||
|
||||
assert %{"id" => ^id_str, "pinned" => true} =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses/#{activity.id}/pin")
|
||||
|> Map.get(:resp_body)
|
||||
|> Jason.decode!()
|
||||
|> json_response(200)
|
||||
|
||||
assert [%{"id" => ^id_str, "pinned" => true}] =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
|
||||
|> Map.get(:resp_body)
|
||||
|> Jason.decode!()
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "unpin status", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
||||
test "unpin status", %{conn: conn, user: user, activity: activity} do
|
||||
{:ok, _} = CommonAPI.pin(activity.id, user)
|
||||
|
||||
id_str = Integer.to_string(activity.id)
|
||||
id_str = to_string(activity.id)
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %{"id" => ^id_str, "pinned" => false} =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses/#{activity.id}/unpin")
|
||||
|> Map.get(:resp_body)
|
||||
|> Jason.decode!()
|
||||
|> json_response(200)
|
||||
|
||||
assert [] =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> get("/api/v1/accounts/#{user.id}/statuses?pinned=true")
|
||||
|> Map.get(:resp_body)
|
||||
|> Jason.decode!()
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "max pinned statuses", %{conn: conn} do
|
||||
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
|
||||
|
||||
user = insert(:user)
|
||||
|
||||
{:ok, activity_one} = CommonAPI.post(user, %{"status" => "HI!!!"})
|
||||
test "max pinned statuses", %{conn: conn, user: user, activity: activity_one} do
|
||||
{: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} =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses/#{id_str_one}/pin")
|
||||
|> Map.get(:resp_body)
|
||||
|> Jason.decode!()
|
||||
|> json_response(200)
|
||||
|
||||
user = refresh_record(user)
|
||||
|
||||
|
@ -1562,8 +1548,7 @@ test "max pinned statuses", %{conn: conn} do
|
|||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses/#{activity_two.id}/pin")
|
||||
|> Map.get(:resp_body)
|
||||
|> Jason.decode!()
|
||||
|> json_response(400)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue