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