mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-18 02:49:18 +00:00
Add direct_note[_activity]_factory and a couple tests
This commit is contained in:
parent
4dfb40a546
commit
d0ad13c12e
|
@ -45,6 +45,33 @@ def note_factory do
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def direct_note_factory do
|
||||||
|
user2 = insert(:user)
|
||||||
|
|
||||||
|
%Pleroma.Object{data: data} = note_factory()
|
||||||
|
%Pleroma.Object{data: Map.merge(data, %{"to" => [user2.ap_id]})}
|
||||||
|
end
|
||||||
|
|
||||||
|
def direct_note_activity_factory do
|
||||||
|
dm = insert(:direct_note)
|
||||||
|
|
||||||
|
data = %{
|
||||||
|
"id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(),
|
||||||
|
"type" => "Create",
|
||||||
|
"actor" => dm.data["actor"],
|
||||||
|
"to" => dm.data["to"],
|
||||||
|
"object" => dm.data,
|
||||||
|
"published" => DateTime.utc_now() |> DateTime.to_iso8601(),
|
||||||
|
"context" => dm.data["context"]
|
||||||
|
}
|
||||||
|
|
||||||
|
%Pleroma.Activity{
|
||||||
|
data: data,
|
||||||
|
actor: data["actor"],
|
||||||
|
recipients: data["to"]
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def note_activity_factory do
|
def note_activity_factory do
|
||||||
note = insert(:note)
|
note = insert(:note)
|
||||||
|
|
||||||
|
|
|
@ -132,14 +132,32 @@ test "posting a direct status", %{conn: conn} do
|
||||||
conn =
|
conn =
|
||||||
conn
|
conn
|
||||||
|> assign(:user, user1)
|
|> assign(:user, user1)
|
||||||
|> post("api/v1/statuses", %{"status" => content,
|
|> post("api/v1/statuses", %{"status" => content, "visibility" => "direct"})
|
||||||
"visibility" => "direct"})
|
|
||||||
|
|
||||||
assert %{"content" => content, "id" => id, "visibility" => "direct"} = json_response(conn, 200)
|
assert %{"id" => id, "visibility" => "direct"} = json_response(conn, 200)
|
||||||
assert activity = Repo.get(Activity, id)
|
assert activity = Repo.get(Activity, id)
|
||||||
assert user2.follower_address not in activity.data["to"]
|
assert user2.follower_address not in activity.data["to"]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test "direct timeline", %{conn: conn} do
|
||||||
|
dm = insert(:direct_note_activity)
|
||||||
|
reg_note = insert(:note_activity)
|
||||||
|
|
||||||
|
recipient = User.get_by_ap_id(hd(dm.recipients))
|
||||||
|
|
||||||
|
conn =
|
||||||
|
conn
|
||||||
|
|> assign(:user, recipient)
|
||||||
|
|> get("api/v1/timelines/direct")
|
||||||
|
|
||||||
|
resp = json_response(conn, 200)
|
||||||
|
first_status = hd(resp)
|
||||||
|
|
||||||
|
assert length(resp) == 1
|
||||||
|
assert %{"visibility" => "direct"} = first_status
|
||||||
|
assert first_status["url"] != reg_note.data["id"]
|
||||||
|
end
|
||||||
|
|
||||||
test "replying to a status", %{conn: conn} do
|
test "replying to a status", %{conn: conn} do
|
||||||
user = insert(:user)
|
user = insert(:user)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue