logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git

handler_test.exs (2282B)


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