diff options
Diffstat (limited to 'test/web/pleroma_api/controllers')
| -rw-r--r-- | test/web/pleroma_api/controllers/pleroma_api_controller_test.exs | 150 | ||||
| -rw-r--r-- | test/web/pleroma_api/controllers/subscription_notification_controller_test.exs | 234 | 
2 files changed, 0 insertions, 384 deletions
diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs deleted file mode 100644 index 7eaeda4a0..000000000 --- a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs +++ /dev/null @@ -1,150 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do -  use Pleroma.Web.ConnCase - -  alias Pleroma.Conversation.Participation -  alias Pleroma.Notification -  alias Pleroma.Repo -  alias Pleroma.Web.CommonAPI - -  import Pleroma.Factory - -  test "/api/v1/pleroma/conversations/:id", %{conn: conn} do -    user = insert(:user) -    other_user = insert(:user) - -    {:ok, _activity} = -      CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"}) - -    [participation] = Participation.for_user(other_user) - -    result = -      conn -      |> assign(:user, other_user) -      |> get("/api/v1/pleroma/conversations/#{participation.id}") -      |> json_response(200) - -    assert result["id"] == participation.id |> to_string() -  end - -  test "/api/v1/pleroma/conversations/:id/statuses", %{conn: conn} do -    user = insert(:user) -    other_user = insert(:user) -    third_user = insert(:user) - -    {:ok, _activity} = -      CommonAPI.post(user, %{"status" => "Hi @#{third_user.nickname}!", "visibility" => "direct"}) - -    {:ok, activity} = -      CommonAPI.post(user, %{"status" => "Hi @#{other_user.nickname}!", "visibility" => "direct"}) - -    [participation] = Participation.for_user(other_user) - -    {:ok, activity_two} = -      CommonAPI.post(other_user, %{ -        "status" => "Hi!", -        "in_reply_to_status_id" => activity.id, -        "in_reply_to_conversation_id" => participation.id -      }) - -    result = -      conn -      |> assign(:user, other_user) -      |> get("/api/v1/pleroma/conversations/#{participation.id}/statuses") -      |> json_response(200) - -    assert length(result) == 2 - -    id_one = activity.id -    id_two = activity_two.id -    assert [%{"id" => ^id_one}, %{"id" => ^id_two}] = result -  end - -  test "PATCH /api/v1/pleroma/conversations/:id", %{conn: conn} do -    user = insert(:user) -    other_user = insert(:user) - -    {:ok, _activity} = CommonAPI.post(user, %{"status" => "Hi", "visibility" => "direct"}) - -    [participation] = Participation.for_user(user) - -    participation = Repo.preload(participation, :recipients) - -    assert [user] == participation.recipients -    assert other_user not in participation.recipients - -    result = -      conn -      |> assign(:user, user) -      |> patch("/api/v1/pleroma/conversations/#{participation.id}", %{ -        "recipients" => [user.id, other_user.id] -      }) -      |> json_response(200) - -    assert result["id"] == participation.id |> to_string - -    [participation] = Participation.for_user(user) -    participation = Repo.preload(participation, :recipients) - -    assert user in participation.recipients -    assert other_user in participation.recipients -  end - -  describe "POST /api/v1/pleroma/notifications/read" do -    test "it marks a single notification as read", %{conn: conn} do -      user1 = insert(:user) -      user2 = insert(:user) -      {:ok, activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"}) -      {:ok, activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"}) -      {:ok, [notification1]} = Notification.create_notifications(activity1) -      {:ok, [notification2]} = Notification.create_notifications(activity2) - -      response = -        conn -        |> assign(:user, user1) -        |> post("/api/v1/pleroma/notifications/read", %{"id" => "#{notification1.id}"}) -        |> json_response(:ok) - -      assert %{"pleroma" => %{"is_seen" => true}} = response -      assert Repo.get(Notification, notification1.id).seen -      refute Repo.get(Notification, notification2.id).seen -    end - -    test "it marks multiple notifications as read", %{conn: conn} do -      user1 = insert(:user) -      user2 = insert(:user) -      {:ok, _activity1} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"}) -      {:ok, _activity2} = CommonAPI.post(user2, %{"status" => "hi @#{user1.nickname}"}) -      {:ok, _activity3} = CommonAPI.post(user2, %{"status" => "HIE @#{user1.nickname}"}) - -      [notification3, notification2, notification1] = Notification.for_user(user1, %{limit: 3}) - -      [response1, response2] = -        conn -        |> assign(:user, user1) -        |> post("/api/v1/pleroma/notifications/read", %{"max_id" => "#{notification2.id}"}) -        |> json_response(:ok) - -      assert %{"pleroma" => %{"is_seen" => true}} = response1 -      assert %{"pleroma" => %{"is_seen" => true}} = response2 -      assert Repo.get(Notification, notification1.id).seen -      assert Repo.get(Notification, notification2.id).seen -      refute Repo.get(Notification, notification3.id).seen -    end - -    test "it returns error when notification not found", %{conn: conn} do -      user1 = insert(:user) - -      response = -        conn -        |> assign(:user, user1) -        |> post("/api/v1/pleroma/notifications/read", %{"id" => "22222222222222"}) -        |> json_response(:bad_request) - -      assert response == %{"error" => "Cannot get notification"} -    end -  end -end diff --git a/test/web/pleroma_api/controllers/subscription_notification_controller_test.exs b/test/web/pleroma_api/controllers/subscription_notification_controller_test.exs deleted file mode 100644 index c6a71732d..000000000 --- a/test/web/pleroma_api/controllers/subscription_notification_controller_test.exs +++ /dev/null @@ -1,234 +0,0 @@ -# Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> -# SPDX-License-Identifier: AGPL-3.0-only - -defmodule Pleroma.Web.PleromaAPI.SubscriptionNotificationControllerTest do -  use Pleroma.Web.ConnCase - -  alias Pleroma.Repo -  alias Pleroma.SubscriptionNotification -  alias Pleroma.User -  alias Pleroma.Web.CommonAPI -  import Pleroma.Factory -  import Tesla.Mock - -  setup do -    mock(fn env -> apply(HttpRequestMock, :request, [env]) end) -    :ok -  end - -  clear_config([:instance, :public]) -  clear_config([:rich_media, :enabled]) - -  describe "subscription_notifications" do -    setup do -      user = insert(:user) -      subscriber = insert(:user) - -      User.subscribe(subscriber, user) - -      {:ok, %{user: user, subscriber: subscriber}} -    end - -    test "list of notifications", %{conn: conn, user: user, subscriber: subscriber} do -      status_text = "Hello" -      {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text}) -      path = subscription_notification_path(conn, :index) - -      conn = -        conn -        |> assign(:user, subscriber) -        |> get(path) - -      assert [%{"status" => %{"content" => response}} | _rest] = json_response(conn, 200) -      assert response == status_text -    end - -    test "getting a single notification", %{conn: conn, user: user, subscriber: subscriber} do -      status_text = "Hello" - -      {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text}) -      [notification] = Repo.all(SubscriptionNotification) - -      path = subscription_notification_path(conn, :show, notification) - -      conn = -        conn -        |> assign(:user, subscriber) -        |> get(path) - -      assert %{"status" => %{"content" => response}} = json_response(conn, 200) -      assert response == status_text -    end - -    test "dismissing a single notification also deletes it", %{ -      conn: conn, -      user: user, -      subscriber: subscriber -    } do -      status_text = "Hello" -      {:ok, _activity} = CommonAPI.post(user, %{"status" => status_text}) - -      [notification] = Repo.all(SubscriptionNotification) - -      conn = -        conn -        |> assign(:user, subscriber) -        |> post(subscription_notification_path(conn, :dismiss), %{"id" => notification.id}) - -      assert %{} = json_response(conn, 200) - -      assert Repo.all(SubscriptionNotification) == [] -    end - -    test "clearing all notifications also deletes them", %{ -      conn: conn, -      user: user, -      subscriber: subscriber -    } do -      status_text1 = "Hello" -      status_text2 = "Hello again" -      {:ok, _activity1} = CommonAPI.post(user, %{"status" => status_text1}) -      {:ok, _activity2} = CommonAPI.post(user, %{"status" => status_text2}) - -      conn = -        conn -        |> assign(:user, subscriber) -        |> post(subscription_notification_path(conn, :clear)) - -      assert %{} = json_response(conn, 200) - -      conn = -        build_conn() -        |> assign(:user, subscriber) -        |> get(subscription_notification_path(conn, :index)) - -      assert json_response(conn, 200) == [] - -      assert Repo.all(SubscriptionNotification) == [] -    end - -    test "paginates notifications using min_id, since_id, max_id, and limit", %{ -      conn: conn, -      user: user, -      subscriber: subscriber -    } do -      {:ok, activity1} = CommonAPI.post(user, %{"status" => "Hello 1"}) -      {:ok, activity2} = CommonAPI.post(user, %{"status" => "Hello 2"}) -      {:ok, activity3} = CommonAPI.post(user, %{"status" => "Hello 3"}) -      {:ok, activity4} = CommonAPI.post(user, %{"status" => "Hello 4"}) - -      notification1_id = -        Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string() - -      notification2_id = -        Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string() - -      notification3_id = -        Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string() - -      notification4_id = -        Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string() - -      conn = assign(conn, :user, subscriber) - -      # min_id -      conn_res = -        get( -          conn, -          subscription_notification_path(conn, :index, %{ -            "limit" => 2, -            "min_id" => notification1_id -          }) -        ) - -      result = json_response(conn_res, 200) -      assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result - -      # since_id -      conn_res = -        get( -          conn, -          subscription_notification_path(conn, :index, %{ -            "limit" => 2, -            "since_id" => notification1_id -          }) -        ) - -      result = json_response(conn_res, 200) -      assert [%{"id" => ^notification4_id}, %{"id" => ^notification3_id}] = result - -      # max_id -      conn_res = -        get( -          conn, -          subscription_notification_path(conn, :index, %{ -            "limit" => 2, -            "max_id" => notification4_id -          }) -        ) - -      result = json_response(conn_res, 200) -      assert [%{"id" => ^notification3_id}, %{"id" => ^notification2_id}] = result -    end - -    test "destroy multiple", %{conn: conn, user: user1, subscriber: user2} do -      # mutual subscription -      User.subscribe(user1, user2) - -      {:ok, activity1} = CommonAPI.post(user1, %{"status" => "Hello 1"}) -      {:ok, activity2} = CommonAPI.post(user1, %{"status" => "World 1"}) -      {:ok, activity3} = CommonAPI.post(user2, %{"status" => "Hello 2"}) -      {:ok, activity4} = CommonAPI.post(user2, %{"status" => "World 2"}) - -      notification1_id = -        Repo.get_by(SubscriptionNotification, activity_id: activity1.id).id |> to_string() - -      notification2_id = -        Repo.get_by(SubscriptionNotification, activity_id: activity2.id).id |> to_string() - -      notification3_id = -        Repo.get_by(SubscriptionNotification, activity_id: activity3.id).id |> to_string() - -      notification4_id = -        Repo.get_by(SubscriptionNotification, activity_id: activity4.id).id |> to_string() - -      conn = assign(conn, :user, user1) - -      conn_res = get(conn, subscription_notification_path(conn, :index)) - -      result = json_response(conn_res, 200) - -      Enum.each(result, fn %{"id" => id} -> -        assert id in [notification3_id, notification4_id] -      end) - -      conn2 = assign(conn, :user, user2) - -      conn_res = get(conn2, subscription_notification_path(conn, :index)) - -      result = json_response(conn_res, 200) - -      Enum.each(result, fn %{"id" => id} -> -        assert id in [notification1_id, notification2_id] -      end) - -      conn_destroy = -        delete(conn, subscription_notification_path(conn, :destroy_multiple), %{ -          "ids" => [notification3_id, notification4_id] -        }) - -      assert json_response(conn_destroy, 200) == %{} - -      conn_res = get(conn2, subscription_notification_path(conn, :index)) - -      result = json_response(conn_res, 200) - -      Enum.each(result, fn %{"id" => id} -> -        assert id in [notification1_id, notification2_id] -      end) - -      assert length(Repo.all(SubscriptionNotification)) == 2 -    end -  end -end  | 
