forked from AkkomaGang/akkoma
AdminAPI Chat tests: Remove factory.
The factory system doesn't work too well with how the chats are done. Instead of tempting people to use it, let's rather use the CommonAPI system for now.
This commit is contained in:
parent
e39ff2616b
commit
5e3c70afa5
2 changed files with 8 additions and 59 deletions
|
@ -441,58 +441,4 @@ def filter_factory do
|
|||
phrase: "cofe"
|
||||
}
|
||||
end
|
||||
|
||||
def chat_factory(attrs \\ %{}) do
|
||||
user = attrs[:user] || insert(:user)
|
||||
recipient = attrs[:recipient] || insert(:user)
|
||||
|
||||
%Pleroma.Chat{
|
||||
user_id: user.id,
|
||||
recipient: recipient.ap_id
|
||||
}
|
||||
end
|
||||
|
||||
def chat_message_factory(attrs \\ %{}) do
|
||||
text = sequence(:text, &"This is :moominmamma: chat message #{&1}")
|
||||
chat = attrs[:chat] || insert(:chat)
|
||||
|
||||
data = %{
|
||||
"type" => "ChatMessage",
|
||||
"content" => text,
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_object_id(),
|
||||
"actor" => User.get_by_id(chat.user_id).ap_id,
|
||||
"to" => [chat.recipient],
|
||||
"published" => DateTime.utc_now() |> DateTime.to_iso8601()
|
||||
}
|
||||
|
||||
%Pleroma.Object{
|
||||
data: merge_attributes(data, Map.get(attrs, :data, %{}))
|
||||
}
|
||||
end
|
||||
|
||||
def chat_message_activity_factory(attrs \\ %{}) do
|
||||
chat = attrs[:chat] || insert(:chat)
|
||||
chat_message = attrs[:chat_message] || insert(:chat_message, chat: chat)
|
||||
|
||||
data_attrs = attrs[:data_attrs] || %{}
|
||||
attrs = Map.drop(attrs, [:chat, :chat_message, :data_attrs])
|
||||
|
||||
data =
|
||||
%{
|
||||
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||
"type" => "Create",
|
||||
"actor" => chat_message.data["actor"],
|
||||
"to" => chat_message.data["to"],
|
||||
"object" => chat_message.data["id"],
|
||||
"published" => DateTime.utc_now() |> DateTime.to_iso8601()
|
||||
}
|
||||
|> Map.merge(data_attrs)
|
||||
|
||||
%Pleroma.Activity{
|
||||
data: data,
|
||||
actor: data["actor"],
|
||||
recipients: data["to"]
|
||||
}
|
||||
|> Map.merge(attrs)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1513,10 +1513,11 @@ test "excludes reblogs by default", %{conn: conn, user: user} do
|
|||
describe "GET /api/pleroma/admin/users/:nickname/chats" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
recipients = insert_list(3, :user)
|
||||
|
||||
insert(:chat, user: user)
|
||||
insert(:chat, user: user)
|
||||
insert(:chat, user: user)
|
||||
Enum.each(recipients, fn recipient ->
|
||||
CommonAPI.post_chat_message(user, recipient, "yo")
|
||||
end)
|
||||
|
||||
%{user: user}
|
||||
end
|
||||
|
@ -1531,7 +1532,8 @@ test "renders user's chats", %{conn: conn, user: user} do
|
|||
describe "GET /api/pleroma/admin/users/:nickname/chats unauthorized" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
insert(:chat, user: user)
|
||||
recipient = insert(:user)
|
||||
CommonAPI.post_chat_message(user, recipient, "yo")
|
||||
%{conn: conn} = oauth_access(["read:chats"])
|
||||
%{conn: conn, user: user}
|
||||
end
|
||||
|
@ -1546,7 +1548,8 @@ test "returns 403", %{conn: conn, user: user} do
|
|||
describe "GET /api/pleroma/admin/users/:nickname/chats unauthenticated" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
insert(:chat, user: user)
|
||||
recipient = insert(:user)
|
||||
CommonAPI.post_chat_message(user, recipient, "yo")
|
||||
%{conn: build_conn(), user: user}
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue