logo

pleroma

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

scheduled_activity_view_test.exs (2110B)


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