X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Ftwitter_api%2Fviews%2Factivity_view_test.exs;h=7f2017d3cf6fed72652c23dfc73ca49ede55463f;hb=6ff583e5e10e59fe76cb51ce3d04587307af9eae;hp=eca69cdfe655fec59624eab14df058f02241ccd9;hpb=1f32ba052c52ad974d17d8b65fb2c66b61eceffe;p=akkoma diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs index eca69cdfe..7f2017d3c 100644 --- a/test/web/twitter_api/views/activity_view_test.exs +++ b/test/web/twitter_api/views/activity_view_test.exs @@ -10,7 +10,9 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do alias Pleroma.Activity alias Pleroma.User alias Pleroma.Web.ActivityPub.ActivityPub + import Pleroma.Factory + import Mock test "a create activity with a note" do user = insert(:user) @@ -51,6 +53,37 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do assert result == expected end + test "a list of activities" do + user = insert(:user) + other_user = insert(:user, %{nickname: "shp"}) + {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"}) + + convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"]) + + mocks = [ + { + TwitterAPI, + [], + [context_to_conversation_id: fn _ -> false end] + }, + { + User, + [:passthrough], + [get_cached_by_ap_id: fn _ -> nil end] + } + ] + + with_mocks mocks do + [result] = ActivityView.render("index.json", activities: [activity]) + + assert result["statusnet_conversation_id"] == convo_id + assert result["user"] + refute called(TwitterAPI.context_to_conversation_id(:_)) + refute called(User.get_cached_by_ap_id(user.ap_id)) + refute called(User.get_cached_by_ap_id(other_user.ap_id)) + end + end + test "an activity that is a reply" do user = insert(:user) other_user = insert(:user, %{nickname: "shp"}) @@ -126,7 +159,6 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do user = insert(:user) other_user = insert(:user, %{nickname: "shp"}) - {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"}) {:ok, follower} = User.follow(user, other_user) {:ok, follow} = ActivityPub.follow(follower, other_user) @@ -148,4 +180,30 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do assert result == expected end + + test "a delete activity" do + user = insert(:user) + + {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"}) + {:ok, delete} = CommonAPI.delete(activity.id, user) + + result = ActivityView.render("activity.json", activity: delete) + + expected = %{ + "activity_type" => "delete", + "attentions" => [], + "created_at" => delete.data["published"] |> Utils.date_to_asctime(), + "external_url" => delete.data["id"], + "id" => delete.id, + "in_reply_to_status_id" => nil, + "is_local" => true, + "is_post_verb" => false, + "statusnet_html" => "deleted notice {{tag", + "text" => "deleted notice {{tag", + "uri" => delete.data["object"], + "user" => UserView.render("show.json", user: user) + } + + assert result == expected + end end