logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma

scheduled_activity_view_test.exs (2102B)


  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.Web.MastodonAPI.ScheduledActivityViewTest do
  5. use Pleroma.DataCase
  6. alias Pleroma.ScheduledActivity
  7. alias Pleroma.Web.ActivityPub.ActivityPub
  8. alias Pleroma.Web.CommonAPI
  9. alias Pleroma.Web.CommonAPI.Utils
  10. alias Pleroma.Web.MastodonAPI.ScheduledActivityView
  11. alias Pleroma.Web.MastodonAPI.StatusView
  12. import Pleroma.Factory
  13. test "A scheduled activity with a media attachment" do
  14. user = insert(:user)
  15. {:ok, activity} = CommonAPI.post(user, %{status: "hi"})
  16. scheduled_at =
  17. NaiveDateTime.utc_now()
  18. |> NaiveDateTime.add(:timer.minutes(10), :millisecond)
  19. |> NaiveDateTime.to_iso8601()
  20. file = %Plug.Upload{
  21. content_type: "image/jpg",
  22. path: Path.absname("test/fixtures/image.jpg"),
  23. filename: "an_image.jpg"
  24. }
  25. {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)
  26. attrs = %{
  27. params: %{
  28. "media_ids" => [upload.id],
  29. "status" => "hi",
  30. "sensitive" => true,
  31. "spoiler_text" => "spoiler",
  32. "visibility" => "unlisted",
  33. "in_reply_to_id" => to_string(activity.id)
  34. },
  35. scheduled_at: scheduled_at
  36. }
  37. {:ok, scheduled_activity} = ScheduledActivity.create(user, attrs)
  38. result = ScheduledActivityView.render("show.json", %{scheduled_activity: scheduled_activity})
  39. expected = %{
  40. id: to_string(scheduled_activity.id),
  41. media_attachments:
  42. %{media_ids: [upload.id]}
  43. |> Utils.attachments_from_ids()
  44. |> Enum.map(&StatusView.render("attachment.json", %{attachment: &1})),
  45. params: %{
  46. in_reply_to_id: to_string(activity.id),
  47. media_ids: [upload.id],
  48. poll: nil,
  49. scheduled_at: nil,
  50. sensitive: true,
  51. spoiler_text: "spoiler",
  52. text: "hi",
  53. visibility: "unlisted"
  54. },
  55. scheduled_at: Utils.to_masto_date(scheduled_activity.scheduled_at)
  56. }
  57. assert expected == result
  58. end
  59. end