+ capture_log(fn ->
+ url = "https://shitposter.club/notice/2827873"
+ {:ok, [activity]} = OStatus.fetch_activity_from_url(url)
+
+ assert activity.data["actor"] == "https://shitposter.club/user/1"
+
+ assert activity.data["object"] ==
+ "tag:shitposter.club,2017-05-05:noticeId=2827873:objectType=comment"
+ end)
+ end
+
+ test "it works for atom notes, too" do
+ url = "https://social.sakamoto.gq/objects/0ccc1a2c-66b0-4305-b23a-7f7f2b040056"
+ {:ok, [activity]} = OStatus.fetch_activity_from_url(url)
+ assert activity.data["actor"] == "https://social.sakamoto.gq/users/eal"
+ assert activity.data["object"] == url
+ end
+ end
+
+ test "it doesn't add nil in the to field" do
+ incoming = File.read!("test/fixtures/nil_mention_entry.xml")
+ {:ok, [activity]} = OStatus.handle_incoming(incoming)
+
+ assert activity.data["to"] == [
+ "http://localhost:4001/users/atarifrosch@social.stopwatchingus-heidelberg.de/followers",
+ "https://www.w3.org/ns/activitystreams#Public"
+ ]
+ end
+
+ describe "is_representable?" do
+ test "Note objects are representable" do
+ note_activity = insert(:note_activity)
+
+ assert OStatus.is_representable?(note_activity)
+ end
+
+ test "Article objects are not representable" do
+ note_activity = insert(:note_activity)
+ note_object = Object.normalize(note_activity)
+
+ note_data =
+ note_object.data
+ |> Map.put("type", "Article")
+
+ Cachex.clear(:object_cache)
+
+ cs = Object.change(note_object, %{data: note_data})
+ {:ok, _article_object} = Repo.update(cs)
+
+ # the underlying object is now an Article instead of a note, so this should fail
+ refute OStatus.is_representable?(note_activity)
+ end
+ end
+
+ describe "make_user/2" do
+ test "creates new user" do
+ {:ok, user} = OStatus.make_user("https://social.heldscal.la/user/23211")
+
+ created_user =
+ User
+ |> Repo.get_by(ap_id: "https://social.heldscal.la/user/23211")
+ |> Map.put(:last_digest_emailed_at, nil)