summaryrefslogtreecommitdiff
path: root/test/pleroma/web/mastodon_api/views/scheduled_activity_view_test.exs
blob: c3b7f0f41f9d2e6df3bea1fbeefbcd7aa0abda99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Pleroma: A lightweight social networking server
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do
  use Pleroma.DataCase, async: true
  alias Pleroma.ScheduledActivity
  alias Pleroma.Web.ActivityPub.ActivityPub
  alias Pleroma.Web.CommonAPI
  alias Pleroma.Web.CommonAPI.Utils
  alias Pleroma.Web.MastodonAPI.ScheduledActivityView
  alias Pleroma.Web.MastodonAPI.StatusView
  import Pleroma.Factory

  test "A scheduled activity with a media attachment" do
    user = insert(:user)
    {:ok, activity} = CommonAPI.post(user, %{status: "hi"})

    scheduled_at =
      NaiveDateTime.utc_now()
      |> NaiveDateTime.add(:timer.minutes(10), :millisecond)
      |> NaiveDateTime.to_iso8601()

    file = %Plug.Upload{
      content_type: "image/jpeg",
      path: Path.absname("test/fixtures/image.jpg"),
      filename: "an_image.jpg"
    }

    {:ok, upload} = ActivityPub.upload(file, actor: user.ap_id)

    attrs = %{
      params: %{
        "media_ids" => [upload.id],
        "status" => "hi",
        "sensitive" => true,
        "spoiler_text" => "spoiler",
        "visibility" => "unlisted",
        "in_reply_to_id" => to_string(activity.id)
      },
      scheduled_at: scheduled_at
    }

    {:ok, scheduled_activity} = ScheduledActivity.create(user, attrs)
    result = ScheduledActivityView.render("show.json", %{scheduled_activity: scheduled_activity})

    expected = %{
      id: to_string(scheduled_activity.id),
      media_attachments:
        %{media_ids: [upload.id]}
        |> Utils.attachments_from_ids()
        |> Enum.map(&StatusView.render("attachment.json", %{attachment: &1})),
      params: %{
        in_reply_to_id: to_string(activity.id),
        media_ids: [upload.id],
        poll: nil,
        scheduled_at: nil,
        sensitive: true,
        spoiler_text: "spoiler",
        text: "hi",
        visibility: "unlisted"
      },
      scheduled_at: Utils.to_masto_date(scheduled_activity.scheduled_at)
    }

    assert expected == result
  end
end