Refactor as per Rin's suggestions, add endpoint tests
This commit is contained in:
parent
cc21fc5f53
commit
c01ef574c1
9 changed files with 136 additions and 105 deletions
|
|
@ -164,4 +164,30 @@ defmodule Pleroma.Web.CommonAPI.Test do
|
|||
assert %User{info: %{pinned_activities: []}} = user
|
||||
end
|
||||
end
|
||||
|
||||
describe "mute tests" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
||||
activity = insert(:note_activity)
|
||||
|
||||
[user: user, activity: activity]
|
||||
end
|
||||
|
||||
test "add mute", %{user: user, activity: activity} do
|
||||
{:ok, _} = CommonAPI.add_mute(user, activity)
|
||||
assert CommonAPI.thread_muted?(user, activity)
|
||||
end
|
||||
|
||||
test "remove mute", %{user: user, activity: activity} do
|
||||
CommonAPI.add_mute(user, activity)
|
||||
{:ok, _} = CommonAPI.remove_mute(user, activity)
|
||||
refute CommonAPI.thread_muted?(user, activity)
|
||||
end
|
||||
|
||||
test "check that mutes can't be duplicate", %{user: user, activity: activity} do
|
||||
CommonAPI.add_mute(user, activity)
|
||||
{:error, _} = CommonAPI.add_mute(user, activity)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1749,4 +1749,37 @@ defmodule Pleroma.Web.MastodonAPI.MastodonAPIControllerTest do
|
|||
|
||||
assert [json_response(response2, 200)] == json_response(bookmarks, 200)
|
||||
end
|
||||
|
||||
describe "conversation muting" do
|
||||
setup do
|
||||
|
||||
user = insert(:user)
|
||||
{:ok, activity} = CommonAPI.post(user, %{"status" => "HIE"})
|
||||
|
||||
[user: user, activity: activity]
|
||||
end
|
||||
|
||||
test "mute conversation", %{conn: conn, user: user, activity: activity} do
|
||||
id_str = to_string(activity.id)
|
||||
|
||||
assert %{"id" => ^id_str, "muted" => true} =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses/#{activity.id}/mute")
|
||||
|> json_response(200)
|
||||
end
|
||||
|
||||
test "unmute conversation", %{conn: conn, user: user, activity: activity} do
|
||||
{:ok, _} = CommonAPI.add_mute(user, activity)
|
||||
|
||||
id_str = to_string(activity.id)
|
||||
user = refresh_record(user)
|
||||
|
||||
assert %{"id" => ^id_str, "muted" => false} =
|
||||
conn
|
||||
|> assign(:user, user)
|
||||
|> post("/api/v1/statuses/#{activity.id}/unmute")
|
||||
|> json_response(200)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,37 +0,0 @@
|
|||
# Pleroma: A lightweight social networking server
|
||||
# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
|
||||
# SPDX-License-Identifier: AGPL-3.0-only
|
||||
|
||||
defmodule Pleroma.Web.ThreadMuteTest do
|
||||
use Pleroma.DataCase
|
||||
import Pleroma.Web.ThreadMute
|
||||
|
||||
import Pleroma.Factory
|
||||
|
||||
describe "mute tests" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
||||
activity = insert(:note_activity)
|
||||
|
||||
[user: user, activity: activity]
|
||||
end
|
||||
|
||||
test "add mute", %{user: user, activity: activity} do
|
||||
{:ok, _activity} = add_mute(user, activity.id)
|
||||
assert muted?(user, activity)
|
||||
end
|
||||
|
||||
test "remove mute", %{user: user, activity: activity} do
|
||||
add_mute(user, activity.id)
|
||||
{:ok, _activity} = remove_mute(user, activity.id)
|
||||
refute muted?(user, activity)
|
||||
end
|
||||
|
||||
test "check that mutes can't be duplicate", %{user: user, activity: activity} do
|
||||
add_mute(user, activity.id)
|
||||
assert muted?(user, activity)
|
||||
{:error, _} = add_mute(user, activity.id)
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Add a link
Reference in a new issue