summaryrefslogtreecommitdiff
path: root/test/web/twitter_api/representers/object_representer_test.exs
blob: 228b2ac4262cb9654ee08441486bf51c9917f076 (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
defmodule Pleroma.Web.TwitterAPI.Representers.ObjectReprenterTest do
  use Pleroma.DataCase

  alias Pleroma.Object
  alias Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter

  test "represent an image attachment" do
    object = %Object{
      id: 5,
      data: %{
        "type" => "Image",
        "url" => [
          %{
            "mediaType" => "sometype",
            "href" => "someurl"
          }
        ],
        "uuid" => 6
      }
    }

    expected_object = %{
      id: 6,
      url: "someurl",
      mimetype: "sometype",
      oembed: false,
      description: nil
    }

    assert expected_object == ObjectRepresenter.to_map(object)
  end

  test "represents mastodon-style attachments" do
    object = %Object{
      id: nil,
      data: %{
        "mediaType" => "image/png",
        "name" => "blabla",
        "type" => "Document",
        "url" =>
          "http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png"
      }
    }

    expected_object = %{
      url:
        "http://mastodon.example.org/system/media_attachments/files/000/000/001/original/8619f31c6edec470.png",
      mimetype: "image/png",
      oembed: false,
      id: nil,
      description: "blabla"
    }

    assert expected_object == ObjectRepresenter.to_map(object)
  end
end