Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

90 行
2.2KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Pleroma.BBS.HandlerTest do
  5. use Pleroma.DataCase
  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} = 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)
  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)
  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).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