X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fpleroma%2Fobject%2Ffetcher_test.exs;h=e26443a81bdb41f67c6460e10748046bc1fbe018;hb=d427c23e56469aedd4257ff881be55fea151772d;hp=c76a09fd7142e7c3f82961afb2dc315376ea988f;hpb=68894089e845220e06d77401d15e399cb0d3882c;p=akkoma diff --git a/test/pleroma/object/fetcher_test.exs b/test/pleroma/object/fetcher_test.exs index c76a09fd7..e26443a81 100644 --- a/test/pleroma/object/fetcher_test.exs +++ b/test/pleroma/object/fetcher_test.exs @@ -572,4 +572,75 @@ defmodule Pleroma.Object.FetcherTest do } = object.data end end + + describe "get_object/1" do + test "should return ok if the content type is application/activity+json" do + Tesla.Mock.mock(fn + %{ + method: :get, + url: "https://mastodon.social/2" + } -> + %Tesla.Env{ + status: 200, + headers: [{"content-type", "application/activity+json"}], + body: "{}" + } + end) + + assert {:ok, "{}"} = Fetcher.get_object("https://mastodon.social/2") + end + + test "should return ok if the content type is application/ld+json with a profile" do + Tesla.Mock.mock(fn + %{ + method: :get, + url: "https://mastodon.social/2" + } -> + %Tesla.Env{ + status: 200, + headers: [ + {"content-type", + "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\""} + ], + body: "{}" + } + end) + + assert {:ok, "{}"} = Fetcher.get_object("https://mastodon.social/2") + + Tesla.Mock.mock(fn + %{ + method: :get, + url: "https://mastodon.social/2" + } -> + %Tesla.Env{ + status: 200, + headers: [ + {"content-type", + "application/ld+json; profile=\"http://www.w3.org/ns/activitystreams\""} + ], + body: "{}" + } + end) + + assert {:ok, "{}"} = Fetcher.get_object("https://mastodon.social/2") + end + + test "should not return ok with other content types" do + Tesla.Mock.mock(fn + %{ + method: :get, + url: "https://mastodon.social/2" + } -> + %Tesla.Env{ + status: 200, + headers: [{"content-type", "application/json"}], + body: "{}" + } + end) + + assert {:error, {:content_type, "application/json"}} = + Fetcher.get_object("https://mastodon.social/2") + end + end end