[#878] Refactored assumptions on embedded object presence in tests. Adjusted note...
[akkoma] / test / bbs / handler_test.exs
1 defmodule Pleroma.BBS.HandlerTest do
2 use Pleroma.DataCase
3 alias Pleroma.Activity
4 alias Pleroma.BBS.Handler
5 alias Pleroma.Object
6 alias Pleroma.Repo
7 alias Pleroma.User
8 alias Pleroma.Web.CommonAPI
9
10 import ExUnit.CaptureIO
11 import Pleroma.Factory
12 import Ecto.Query
13
14 test "getting the home timeline" do
15 user = insert(:user)
16 followed = insert(:user)
17
18 {:ok, user} = User.follow(user, followed)
19
20 {:ok, _first} = CommonAPI.post(user, %{"status" => "hey"})
21 {:ok, _second} = CommonAPI.post(followed, %{"status" => "hello"})
22
23 output =
24 capture_io(fn ->
25 Handler.handle_command(%{user: user}, "home")
26 end)
27
28 assert output =~ user.nickname
29 assert output =~ followed.nickname
30
31 assert output =~ "hey"
32 assert output =~ "hello"
33 end
34
35 test "posting" do
36 user = insert(:user)
37
38 output =
39 capture_io(fn ->
40 Handler.handle_command(%{user: user}, "p this is a test post")
41 end)
42
43 assert output =~ "Posted"
44
45 activity =
46 Repo.one(
47 from(a in Activity,
48 where: fragment("?->>'type' = ?", a.data, "Create")
49 )
50 )
51
52 assert activity.actor == user.ap_id
53 object = Object.normalize(activity)
54 assert object.data["content"] == "this is a test post"
55 end
56
57 test "replying" do
58 user = insert(:user)
59 another_user = insert(:user)
60
61 {:ok, activity} = CommonAPI.post(another_user, %{"status" => "this is a test post"})
62 activity_object = Object.normalize(activity)
63
64 output =
65 capture_io(fn ->
66 Handler.handle_command(%{user: user}, "r #{activity.id} this is a reply")
67 end)
68
69 assert output =~ "Replied"
70
71 reply =
72 Repo.one(
73 from(a in Activity,
74 where: fragment("?->>'type' = ?", a.data, "Create"),
75 where: a.actor == ^user.ap_id
76 )
77 )
78
79 assert reply.actor == user.ap_id
80
81 reply_object_data = Object.normalize(reply).data
82 assert reply_object_data["content"] == "this is a reply"
83 assert reply_object_data["inReplyTo"] == activity_object.data["id"]
84 end
85 end