diff options
Diffstat (limited to 'test/web/mastodon_api/views')
6 files changed, 71 insertions, 45 deletions
diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index 375f0103a..69ddbb5d4 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -93,7 +93,14 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do    test "Represent the user account for the account owner" do      user = insert(:user) -    notification_settings = %Pleroma.User.NotificationSetting{} +    notification_settings = %{ +      followers: true, +      follows: true, +      non_followers: true, +      non_follows: true, +      privacy_option: false +    } +      privacy = user.default_scope      assert %{ @@ -452,8 +459,8 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do        {:ok, _activity} =          CommonAPI.post(other_user, %{ -          "status" => "Hey @#{user.nickname}.", -          "visibility" => "direct" +          status: "Hey @#{user.nickname}.", +          visibility: "direct"          })        user = User.get_cached_by_ap_id(user.ap_id) diff --git a/test/web/mastodon_api/views/conversation_view_test.exs b/test/web/mastodon_api/views/conversation_view_test.exs index dbf3c51e2..6f84366f8 100644 --- a/test/web/mastodon_api/views/conversation_view_test.exs +++ b/test/web/mastodon_api/views/conversation_view_test.exs @@ -16,7 +16,7 @@ defmodule Pleroma.Web.MastodonAPI.ConversationViewTest do      other_user = insert(:user)      {:ok, activity} = -      CommonAPI.post(user, %{"status" => "hey @#{other_user.nickname}", "visibility" => "direct"}) +      CommonAPI.post(user, %{status: "hey @#{other_user.nickname}", visibility: "direct"})      [participation] = Participation.for_user_with_last_activity_id(user) diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs index 0806269a2..04a774d17 100644 --- a/test/web/mastodon_api/views/notification_view_test.exs +++ b/test/web/mastodon_api/views/notification_view_test.exs @@ -34,7 +34,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do    test "Mention notification" do      user = insert(:user)      mentioned_user = insert(:user) -    {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{mentioned_user.nickname}"}) +    {:ok, activity} = CommonAPI.post(user, %{status: "hey @#{mentioned_user.nickname}"})      {:ok, [notification]} = Notification.create_notifications(activity)      user = User.get_cached_by_id(user.id) @@ -53,7 +53,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do    test "Favourite notification" do      user = insert(:user)      another_user = insert(:user) -    {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"}) +    {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})      {:ok, favorite_activity} = CommonAPI.favorite(another_user, create_activity.id)      {:ok, [notification]} = Notification.create_notifications(favorite_activity)      create_activity = Activity.get_by_id(create_activity.id) @@ -73,7 +73,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do    test "Reblog notification" do      user = insert(:user)      another_user = insert(:user) -    {:ok, create_activity} = CommonAPI.post(user, %{"status" => "hey"}) +    {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"})      {:ok, reblog_activity, _object} = CommonAPI.repeat(create_activity.id, another_user)      {:ok, [notification]} = Notification.create_notifications(reblog_activity)      reblog_activity = Activity.get_by_id(create_activity.id) @@ -155,7 +155,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do      user = insert(:user)      other_user = insert(:user) -    {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"}) +    {:ok, activity} = CommonAPI.post(user, %{status: "#cofe"})      {:ok, _activity} = CommonAPI.react_with_emoji(activity.id, other_user, "ā")      activity = Repo.get(Activity, activity.id) diff --git a/test/web/mastodon_api/views/poll_view_test.exs b/test/web/mastodon_api/views/poll_view_test.exs index 63b204387..76672f36c 100644 --- a/test/web/mastodon_api/views/poll_view_test.exs +++ b/test/web/mastodon_api/views/poll_view_test.exs @@ -22,10 +22,10 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do      {:ok, activity} =        CommonAPI.post(user, %{ -        "status" => "Is Tenshi eating a corndog cute?", -        "poll" => %{ -          "options" => ["absolutely!", "sure", "yes", "why are you even asking?"], -          "expires_in" => 20 +        status: "Is Tenshi eating a corndog cute?", +        poll: %{ +          options: ["absolutely!", "sure", "yes", "why are you even asking?"], +          expires_in: 20          }        }) @@ -62,11 +62,11 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do      {:ok, activity} =        CommonAPI.post(user, %{ -        "status" => "Which Mastodon developer is your favourite?", -        "poll" => %{ -          "options" => ["Gargron", "Eugen"], -          "expires_in" => 20, -          "multiple" => true +        status: "Which Mastodon developer is your favourite?", +        poll: %{ +          options: ["Gargron", "Eugen"], +          expires_in: 20, +          multiple: true          }        }) @@ -91,10 +91,10 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do      {:ok, activity} =        CommonAPI.post(user, %{ -        "status" => "What's with the smug face?", -        "poll" => %{ -          "options" => [":blank: sip", ":blank::blank: sip", ":blank::blank::blank: sip"], -          "expires_in" => 20 +        status: "What's with the smug face?", +        poll: %{ +          options: [":blank: sip", ":blank::blank: sip", ":blank::blank::blank: sip"], +          expires_in: 20          }        }) @@ -109,11 +109,11 @@ defmodule Pleroma.Web.MastodonAPI.PollViewTest do      {:ok, activity} =        CommonAPI.post(user, %{ -        "status" => "Which input devices do you use?", -        "poll" => %{ -          "options" => ["mouse", "trackball", "trackpoint"], -          "multiple" => true, -          "expires_in" => 20 +        status: "Which input devices do you use?", +        poll: %{ +          options: ["mouse", "trackball", "trackpoint"], +          multiple: true, +          expires_in: 20          }        }) diff --git a/test/web/mastodon_api/views/scheduled_activity_view_test.exs b/test/web/mastodon_api/views/scheduled_activity_view_test.exs index 0c0987593..fbfd873ef 100644 --- a/test/web/mastodon_api/views/scheduled_activity_view_test.exs +++ b/test/web/mastodon_api/views/scheduled_activity_view_test.exs @@ -14,7 +14,7 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do    test "A scheduled activity with a media attachment" do      user = insert(:user) -    {:ok, activity} = CommonAPI.post(user, %{"status" => "hi"}) +    {:ok, activity} = CommonAPI.post(user, %{status: "hi"})      scheduled_at =        NaiveDateTime.utc_now() @@ -47,7 +47,7 @@ defmodule Pleroma.Web.MastodonAPI.ScheduledActivityViewTest do      expected = %{        id: to_string(scheduled_activity.id),        media_attachments: -        %{"media_ids" => [upload.id]} +        %{media_ids: [upload.id]}          |> Utils.attachments_from_ids()          |> Enum.map(&StatusView.render("attachment.json", %{attachment: &1})),        params: %{ diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs index b5e7dc317..ffad65b01 100644 --- a/test/web/mastodon_api/views/status_view_test.exs +++ b/test/web/mastodon_api/views/status_view_test.exs @@ -20,6 +20,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do    import Pleroma.Factory    import Tesla.Mock +  import OpenApiSpex.TestAssertions    setup do      mock(fn env -> apply(HttpRequestMock, :request, [env]) end) @@ -30,7 +31,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      user = insert(:user)      other_user = insert(:user)      third_user = insert(:user) -    {:ok, activity} = CommonAPI.post(user, %{"status" => "dae cofe??"}) +    {:ok, activity} = CommonAPI.post(user, %{status: "dae cofe??"})      {:ok, _} = CommonAPI.react_with_emoji(activity.id, user, "ā")      {:ok, _} = CommonAPI.react_with_emoji(activity.id, third_user, "šµ") @@ -38,6 +39,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      activity = Repo.get(Activity, activity.id)      status = StatusView.render("show.json", activity: activity) +    assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec()) +      assert status[:pleroma][:emoji_reactions] == [               %{name: "ā", count: 2, me: false},               %{name: "šµ", count: 1, me: false} @@ -45,6 +48,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      status = StatusView.render("show.json", activity: activity, for: user) +    assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec()) +      assert status[:pleroma][:emoji_reactions] == [               %{name: "ā", count: 2, me: true},               %{name: "šµ", count: 1, me: false} @@ -54,7 +59,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do    test "loads and returns the direct conversation id when given the `with_direct_conversation_id` option" do      user = insert(:user) -    {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"}) +    {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"})      [participation] = Participation.for_user(user)      status = @@ -68,12 +73,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      status = StatusView.render("show.json", activity: activity, for: user)      assert status[:pleroma][:direct_conversation_id] == nil +    assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())    end    test "returns the direct conversation id when given the `direct_conversation_id` option" do      user = insert(:user) -    {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"}) +    {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"})      [participation] = Participation.for_user(user)      status = @@ -84,12 +90,13 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do        )      assert status[:pleroma][:direct_conversation_id] == participation.id +    assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())    end    test "returns a temporary ap_id based user for activities missing db users" do      user = insert(:user) -    {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"}) +    {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"})      Repo.delete(user)      Cachex.clear(:user_cache) @@ -119,7 +126,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do    test "tries to get a user by nickname if fetching by ap_id doesn't work" do      user = insert(:user) -    {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"}) +    {:ok, activity} = CommonAPI.post(user, %{status: "Hey @shp!", visibility: "direct"})      {:ok, user} =        user @@ -131,6 +138,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      result = StatusView.render("show.json", activity: activity)      assert result[:account][:id] == to_string(user.id) +    assert_schema(result, "Status", Pleroma.Web.ApiSpec.spec())    end    test "a note with null content" do @@ -149,6 +157,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      status = StatusView.render("show.json", %{activity: note})      assert status.content == "" +    assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())    end    test "a note activity" do @@ -222,6 +231,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      }      assert status == expected +    assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())    end    test "tells if the message is muted for some reason" do @@ -230,13 +240,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      {:ok, _user_relationships} = User.mute(user, other_user) -    {:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"}) +    {:ok, activity} = CommonAPI.post(other_user, %{status: "test"})      relationships_opt = UserRelationship.view_relationships_option(user, [other_user])      opts = %{activity: activity}      status = StatusView.render("show.json", opts)      assert status.muted == false +    assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())      status = StatusView.render("show.json", Map.put(opts, :relationships, relationships_opt))      assert status.muted == false @@ -247,6 +258,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      status = StatusView.render("show.json", Map.put(for_opts, :relationships, relationships_opt))      assert status.muted == true +    assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())    end    test "tells if the message is thread muted" do @@ -255,7 +267,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      {:ok, _user_relationships} = User.mute(user, other_user) -    {:ok, activity} = CommonAPI.post(other_user, %{"status" => "test"}) +    {:ok, activity} = CommonAPI.post(other_user, %{status: "test"})      status = StatusView.render("show.json", %{activity: activity, for: user})      assert status.pleroma.thread_muted == false @@ -270,7 +282,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do    test "tells if the status is bookmarked" do      user = insert(:user) -    {:ok, activity} = CommonAPI.post(user, %{"status" => "Cute girls doing cute things"}) +    {:ok, activity} = CommonAPI.post(user, %{status: "Cute girls doing cute things"})      status = StatusView.render("show.json", %{activity: activity})      assert status.bookmarked == false @@ -292,8 +304,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      note = insert(:note_activity)      user = insert(:user) -    {:ok, activity} = -      CommonAPI.post(user, %{"status" => "he", "in_reply_to_status_id" => note.id}) +    {:ok, activity} = CommonAPI.post(user, %{status: "he", in_reply_to_status_id: note.id})      status = StatusView.render("show.json", %{activity: activity}) @@ -308,12 +319,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      user = insert(:user)      mentioned = insert(:user) -    {:ok, activity} = CommonAPI.post(user, %{"status" => "hi @#{mentioned.nickname}"}) +    {:ok, activity} = CommonAPI.post(user, %{status: "hi @#{mentioned.nickname}"})      status = StatusView.render("show.json", %{activity: activity})      assert status.mentions ==               Enum.map([mentioned], fn u -> AccountView.render("mention.json", %{user: u}) end) + +    assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())    end    test "create mentions from the 'to' field" do @@ -405,14 +418,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      api_spec = Pleroma.Web.ApiSpec.spec()      assert expected == StatusView.render("attachment.json", %{attachment: object}) -    OpenApiSpex.TestAssertions.assert_schema(expected, "Attachment", api_spec) +    assert_schema(expected, "Attachment", api_spec)      # If theres a "id", use that instead of the generated one      object = Map.put(object, "id", 2)      result = StatusView.render("attachment.json", %{attachment: object})      assert %{id: "2"} = result -    OpenApiSpex.TestAssertions.assert_schema(result, "Attachment", api_spec) +    assert_schema(result, "Attachment", api_spec)    end    test "put the url advertised in the Activity in to the url attribute" do @@ -436,6 +449,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      assert represented[:id] == to_string(reblog.id)      assert represented[:reblog][:id] == to_string(activity.id)      assert represented[:emojis] == [] +    assert_schema(represented, "Status", Pleroma.Web.ApiSpec.spec())    end    test "a peertube video" do @@ -452,6 +466,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      assert represented[:id] == to_string(activity.id)      assert length(represented[:media_attachments]) == 1 +    assert_schema(represented, "Status", Pleroma.Web.ApiSpec.spec())    end    test "funkwhale audio" do @@ -567,13 +582,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      {:ok, activity} =        CommonAPI.post(user, %{ -        "status" => "drink more water" +        status: "drink more water"        })      result = StatusView.render("show.json", %{activity: activity, for: other_user})      assert result[:account][:pleroma][:relationship] ==               AccountView.render("relationship.json", %{user: other_user, target: user}) + +    assert_schema(result, "Status", Pleroma.Web.ApiSpec.spec())    end    test "embeds a relationship in the account in reposts" do @@ -582,7 +599,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      {:ok, activity} =        CommonAPI.post(user, %{ -        "status" => "ĖĖÉŹns" +        status: "ĖĖÉŹns"        })      {:ok, activity, _object} = CommonAPI.repeat(activity.id, other_user) @@ -594,6 +611,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      assert result[:reblog][:account][:pleroma][:relationship] ==               AccountView.render("relationship.json", %{user: user, target: user}) + +    assert_schema(result, "Status", Pleroma.Web.ApiSpec.spec())    end    test "visibility/list" do @@ -601,8 +620,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      {:ok, list} = Pleroma.List.create("foo", user) -    {:ok, activity} = -      CommonAPI.post(user, %{"status" => "foobar", "visibility" => "list:#{list.id}"}) +    {:ok, activity} = CommonAPI.post(user, %{status: "foobar", visibility: "list:#{list.id}"})      status = StatusView.render("show.json", activity: activity) @@ -616,5 +634,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      assert status.length == listen_activity.data["object"]["length"]      assert status.title == listen_activity.data["object"]["title"] +    assert_schema(status, "Status", Pleroma.Web.ApiSpec.spec())    end  end  | 
