mirror of
https://akkoma.dev/AkkomaGang/akkoma.git
synced 2024-11-09 09:52:13 +00:00
Basic ObjectRepresenter.
This commit is contained in:
parent
4a6d48b0fe
commit
42c90855ba
|
@ -0,0 +1,15 @@
|
|||
defmodule Pleroma.Web.TwitterAPI.Representers.ObjectRepresenter do
|
||||
use Pleroma.Web.TwitterAPI.Representers.BaseRepresenter
|
||||
alias Pleroma.Object
|
||||
|
||||
def to_map(%Object{} = object, _opts) do
|
||||
data = object.data
|
||||
url = List.first(data["url"])
|
||||
%{
|
||||
url: url["href"],
|
||||
mimetype: url["mediaType"],
|
||||
id: object.id,
|
||||
oembed: false
|
||||
}
|
||||
end
|
||||
end
|
|
@ -0,0 +1,30 @@
|
|||
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"
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
expected_object = %{
|
||||
id: 5,
|
||||
url: "someurl",
|
||||
mimetype: "sometype",
|
||||
oembed: false
|
||||
}
|
||||
|
||||
assert expected_object == ObjectRepresenter.to_map(object)
|
||||
end
|
||||
end
|
Loading…
Reference in a new issue