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