diff options
Diffstat (limited to 'test')
-rw-r--r-- | test/pleroma/group_test.exs | 26 | ||||
-rw-r--r-- | test/pleroma/web/activity_pub/object_validators/group_validation_test.exs | 24 | ||||
-rw-r--r-- | test/pleroma/web/common_api/group_messaging_test.exs | 25 |
3 files changed, 75 insertions, 0 deletions
diff --git a/test/pleroma/group_test.exs b/test/pleroma/group_test.exs index e4c6cfd92..c10dd10f4 100644 --- a/test/pleroma/group_test.exs +++ b/test/pleroma/group_test.exs @@ -10,6 +10,32 @@ defmodule Pleroma.GroupTest do import Pleroma.Factory + test "get_for_object/1 gets a group based on the group object or the create activity" do + user = insert(:user) + + {:ok, group} = Group.create(%{owner_id: user.id, name: "cofe", description: "corndog"}) + group = Repo.preload(group, :user) + + group_object = %{ + "id" => group.user.ap_id, + "type" => "Group" + } + + assert group.id == Group.get_for_object(group_object).id + + # Same works if wrapped in a 'create' + group_create = %{ + "type" => "Create", + "object" => group_object + } + + assert group.id == Group.get_for_object(group_create).id + + # Nil for nonsense + + assert nil == Group.get_for_object(%{"nothing" => "PS4 games"}) + end + test "a user can create a group" do user = insert(:user) {:ok, group} = Group.create(%{owner_id: user.id, name: "cofe", description: "corndog"}) diff --git a/test/pleroma/web/activity_pub/object_validators/group_validation_test.exs b/test/pleroma/web/activity_pub/object_validators/group_validation_test.exs new file mode 100644 index 000000000..3aab7493d --- /dev/null +++ b/test/pleroma/web/activity_pub/object_validators/group_validation_test.exs @@ -0,0 +1,24 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.ObjectValidators.GroupValidationTest do + use Pleroma.DataCase, async: true + + import Pleroma.Factory + + alias Pleroma.Web.ActivityPub.Builder + alias Pleroma.Web.ActivityPub.ObjectValidator + + describe "Group objects" do + test "it validates a group" do + user = insert(:user) + + {:ok, group_data, []} = Builder.group(user, "a group", "a description") + + {:ok, group, _} = ObjectValidator.validate(group_data, []) + + assert group + end + end +end diff --git a/test/pleroma/web/common_api/group_messaging_test.exs b/test/pleroma/web/common_api/group_messaging_test.exs new file mode 100644 index 000000000..2509428ae --- /dev/null +++ b/test/pleroma/web/common_api/group_messaging_test.exs @@ -0,0 +1,25 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.CommonAPI.GroupMessagingTest do + use Pleroma.DataCase + + import Pleroma.Factory + + alias Pleroma.Group + alias Pleroma.Web.CommonAPI + + describe "Group chats" do + test "local chat" do + user = insert(:user) + + {:ok, group_creation_activity} = + CommonAPI.create_group(user, %{name: "cofe", description: "for cofe enthusiasts"}) + + group = Group.get_for_object(group_creation_activity) + + assert group + end + end +end |