diff options
Diffstat (limited to 'test/web/mastodon_api')
7 files changed, 77 insertions, 48 deletions
| diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs index b9da7e924..256a8b304 100644 --- a/test/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/web/mastodon_api/controllers/account_controller_test.exs @@ -1196,12 +1196,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do    describe "verify_credentials" do      test "verify_credentials" do        %{user: user, conn: conn} = oauth_access(["read:accounts"]) +      [notification | _] = insert_list(7, :notification, user: user) +      Pleroma.Notification.set_read_up_to(user, notification.id)        conn = get(conn, "/api/v1/accounts/verify_credentials")        response = json_response_and_validate_schema(conn, 200)        assert %{"id" => id, "source" => %{"privacy" => "public"}} = response        assert response["pleroma"]["chat_token"] +      assert response["pleroma"]["unread_notifications_count"] == 6        assert id == to_string(user.id)      end diff --git a/test/web/mastodon_api/controllers/marker_controller_test.exs b/test/web/mastodon_api/controllers/marker_controller_test.exs index bce719bea..6dd40fb4a 100644 --- a/test/web/mastodon_api/controllers/marker_controller_test.exs +++ b/test/web/mastodon_api/controllers/marker_controller_test.exs @@ -11,6 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do      test "gets markers with correct scopes", %{conn: conn} do        user = insert(:user)        token = insert(:oauth_token, user: user, scopes: ["read:statuses"]) +      insert_list(7, :notification, user: user)        {:ok, %{"notifications" => marker}} =          Pleroma.Marker.upsert( @@ -29,7 +30,8 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do                 "notifications" => %{                   "last_read_id" => "69420",                   "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at), -                 "version" => 0 +                 "version" => 0, +                 "pleroma" => %{"unread_count" => 7}                 }               }      end @@ -71,7 +73,8 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do                 "notifications" => %{                   "last_read_id" => "69420",                   "updated_at" => _, -                 "version" => 0 +                 "version" => 0, +                 "pleroma" => %{"unread_count" => 0}                 }               } = response      end @@ -101,7 +104,8 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do                 "notifications" => %{                   "last_read_id" => "69888",                   "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at), -                 "version" => 0 +                 "version" => 0, +                 "pleroma" => %{"unread_count" => 0}                 }               }      end diff --git a/test/web/mastodon_api/controllers/search_controller_test.exs b/test/web/mastodon_api/controllers/search_controller_test.exs index 11133ff66..02476acb6 100644 --- a/test/web/mastodon_api/controllers/search_controller_test.exs +++ b/test/web/mastodon_api/controllers/search_controller_test.exs @@ -27,8 +27,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do          capture_log(fn ->            results =              conn -            |> get("/api/v2/search", %{"q" => "2hu"}) -            |> json_response(200) +            |> get("/api/v2/search?q=2hu") +            |> json_response_and_validate_schema(200)            assert results["accounts"] == []            assert results["statuses"] == [] @@ -54,8 +54,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        results =          conn -        |> get("/api/v2/search", %{"q" => "2hu #private"}) -        |> json_response(200) +        |> get("/api/v2/search?#{URI.encode_query(%{q: "2hu #private"})}") +        |> json_response_and_validate_schema(200)        [account | _] = results["accounts"]        assert account["id"] == to_string(user_three.id) @@ -68,8 +68,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        assert status["id"] == to_string(activity.id)        results = -        get(conn, "/api/v2/search", %{"q" => "天子"}) -        |> json_response(200) +        get(conn, "/api/v2/search?q=天子") +        |> json_response_and_validate_schema(200)        [status] = results["statuses"]        assert status["id"] == to_string(activity.id) @@ -89,8 +89,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do          conn          |> assign(:user, user)          |> assign(:token, insert(:oauth_token, user: user, scopes: ["read"])) -        |> get("/api/v2/search", %{"q" => "Agent"}) -        |> json_response(200) +        |> get("/api/v2/search?q=Agent") +        |> json_response_and_validate_schema(200)        status_ids = Enum.map(results["statuses"], fn g -> g["id"] end) @@ -107,8 +107,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        results =          conn -        |> get("/api/v1/accounts/search", %{"q" => "shp"}) -        |> json_response(200) +        |> get("/api/v1/accounts/search?q=shp") +        |> json_response_and_validate_schema(200)        result_ids = for result <- results, do: result["acct"] @@ -117,8 +117,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        results =          conn -        |> get("/api/v1/accounts/search", %{"q" => "2hu"}) -        |> json_response(200) +        |> get("/api/v1/accounts/search?q=2hu") +        |> json_response_and_validate_schema(200)        result_ids = for result <- results, do: result["acct"] @@ -130,8 +130,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        results =          conn -        |> get("/api/v1/accounts/search", %{"q" => "shp@shitposter.club xxx "}) -        |> json_response(200) +        |> get("/api/v1/accounts/search?q=shp@shitposter.club xxx") +        |> json_response_and_validate_schema(200)        assert length(results) == 1      end @@ -146,8 +146,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do          capture_log(fn ->            results =              conn -            |> get("/api/v1/search", %{"q" => "2hu"}) -            |> json_response(200) +            |> get("/api/v1/search?q=2hu") +            |> json_response_and_validate_schema(200)            assert results["accounts"] == []            assert results["statuses"] == [] @@ -173,8 +173,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        results =          conn -        |> get("/api/v1/search", %{"q" => "2hu"}) -        |> json_response(200) +        |> get("/api/v1/search?q=2hu") +        |> json_response_and_validate_schema(200)        [account | _] = results["accounts"]        assert account["id"] == to_string(user_three.id) @@ -194,8 +194,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do          results =            conn -          |> get("/api/v1/search", %{"q" => "https://shitposter.club/notice/2827873"}) -          |> json_response(200) +          |> get("/api/v1/search?q=https://shitposter.club/notice/2827873") +          |> json_response_and_validate_schema(200)          [status, %{"id" => ^activity_id}] = results["statuses"] @@ -212,10 +212,12 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do          })        capture_log(fn -> +        q = Object.normalize(activity).data["id"] +          results =            conn -          |> get("/api/v1/search", %{"q" => Object.normalize(activity).data["id"]}) -          |> json_response(200) +          |> get("/api/v1/search?q=#{q}") +          |> json_response_and_validate_schema(200)          [] = results["statuses"]        end) @@ -228,8 +230,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do          conn          |> assign(:user, user)          |> assign(:token, insert(:oauth_token, user: user, scopes: ["read"])) -        |> get("/api/v1/search", %{"q" => "mike@osada.macgirvin.com", "resolve" => "true"}) -        |> json_response(200) +        |> get("/api/v1/search?q=mike@osada.macgirvin.com&resolve=true") +        |> json_response_and_validate_schema(200)        [account] = results["accounts"]        assert account["acct"] == "mike@osada.macgirvin.com" @@ -238,8 +240,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do      test "search doesn't fetch remote accounts if resolve is false", %{conn: conn} do        results =          conn -        |> get("/api/v1/search", %{"q" => "mike@osada.macgirvin.com", "resolve" => "false"}) -        |> json_response(200) +        |> get("/api/v1/search?q=mike@osada.macgirvin.com&resolve=false") +        |> json_response_and_validate_schema(200)        assert [] == results["accounts"]      end @@ -254,16 +256,16 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        result =          conn -        |> get("/api/v1/search", %{"q" => "2hu", "limit" => 1}) +        |> get("/api/v1/search?q=2hu&limit=1") -      assert results = json_response(result, 200) +      assert results = json_response_and_validate_schema(result, 200)        assert [%{"id" => activity_id1}] = results["statuses"]        assert [_] = results["accounts"]        results =          conn -        |> get("/api/v1/search", %{"q" => "2hu", "limit" => 1, "offset" => 1}) -        |> json_response(200) +        |> get("/api/v1/search?q=2hu&limit=1&offset=1") +        |> json_response_and_validate_schema(200)        assert [%{"id" => activity_id2}] = results["statuses"]        assert [] = results["accounts"] @@ -279,13 +281,13 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        assert %{"statuses" => [_activity], "accounts" => [], "hashtags" => []} =                 conn -               |> get("/api/v1/search", %{"q" => "2hu", "type" => "statuses"}) -               |> json_response(200) +               |> get("/api/v1/search?q=2hu&type=statuses") +               |> json_response_and_validate_schema(200)        assert %{"statuses" => [], "accounts" => [_user_two], "hashtags" => []} =                 conn -               |> get("/api/v1/search", %{"q" => "2hu", "type" => "accounts"}) -               |> json_response(200) +               |> get("/api/v1/search?q=2hu&type=accounts") +               |> json_response_and_validate_schema(200)      end      test "search uses account_id to filter statuses by the author", %{conn: conn} do @@ -297,8 +299,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        results =          conn -        |> get("/api/v1/search", %{"q" => "2hu", "account_id" => user.id}) -        |> json_response(200) +        |> get("/api/v1/search?q=2hu&account_id=#{user.id}") +        |> json_response_and_validate_schema(200)        assert [%{"id" => activity_id1}] = results["statuses"]        assert activity_id1 == activity1.id @@ -306,8 +308,8 @@ defmodule Pleroma.Web.MastodonAPI.SearchControllerTest do        results =          conn -        |> get("/api/v1/search", %{"q" => "2hu", "account_id" => user_two.id}) -        |> json_response(200) +        |> get("/api/v1/search?q=2hu&account_id=#{user_two.id}") +        |> json_response_and_validate_schema(200)        assert [%{"id" => activity_id2}] = results["statuses"]        assert activity_id2 == activity2.id diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index 9ebb13549..df6b995d3 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -469,6 +469,24 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do                 :unread_conversation_count               ] == 1      end + +    test "shows unread_count only to the account owner" do +      user = insert(:user) +      insert_list(7, :notification, user: user) +      other_user = insert(:user) + +      user = User.get_cached_by_ap_id(user.ap_id) + +      assert AccountView.render( +               "show.json", +               %{user: user, for: other_user} +             )[:pleroma][:unread_notifications_count] == nil + +      assert AccountView.render( +               "show.json", +               %{user: user, for: user} +             )[:pleroma][:unread_notifications_count] == 7 +    end    end    describe "follow requests counter" do diff --git a/test/web/mastodon_api/views/marker_view_test.exs b/test/web/mastodon_api/views/marker_view_test.exs index 893cf8857..48a0a6d33 100644 --- a/test/web/mastodon_api/views/marker_view_test.exs +++ b/test/web/mastodon_api/views/marker_view_test.exs @@ -8,19 +8,21 @@ defmodule Pleroma.Web.MastodonAPI.MarkerViewTest do    import Pleroma.Factory    test "returns markers" do -    marker1 = insert(:marker, timeline: "notifications", last_read_id: "17") +    marker1 = insert(:marker, timeline: "notifications", last_read_id: "17", unread_count: 5)      marker2 = insert(:marker, timeline: "home", last_read_id: "42")      assert MarkerView.render("markers.json", %{markers: [marker1, marker2]}) == %{               "home" => %{                 last_read_id: "42",                 updated_at: NaiveDateTime.to_iso8601(marker2.updated_at), -               version: 0 +               version: 0, +               pleroma: %{unread_count: 0}               },               "notifications" => %{                 last_read_id: "17",                 updated_at: NaiveDateTime.to_iso8601(marker1.updated_at), -               version: 0 +               version: 0, +               pleroma: %{unread_count: 5}               }             }    end diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs index a48c298f2..2416772bb 100644 --- a/test/web/mastodon_api/views/notification_view_test.exs +++ b/test/web/mastodon_api/views/notification_view_test.exs @@ -182,7 +182,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do      other_user = insert(:user)      {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"}) -    {:ok, _activity, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕") +    {:ok, _activity} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")      activity = Repo.get(Activity, activity.id) diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs index 451723e60..b5e7dc317 100644 --- a/test/web/mastodon_api/views/status_view_test.exs +++ b/test/web/mastodon_api/views/status_view_test.exs @@ -32,9 +32,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      third_user = insert(:user)      {: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, "🍵") -    {:ok, _, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕") +    {:ok, _} = CommonAPI.react_with_emoji(activity.id, user, "☕") +    {:ok, _} = CommonAPI.react_with_emoji(activity.id, third_user, "🍵") +    {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")      activity = Repo.get(Activity, activity.id)      status = StatusView.render("show.json", activity: activity) | 
