X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fconversation_test.exs;h=dc0027d0440a00fdc5fc79735b1b12f69c2a0731;hb=4427161ca3798aeee0290f0ed7ac5536039509d8;hp=f3300e7d18a535db0deb78df160197369821ab0d;hpb=b6b5b16ba4d65ecd9812b02d79f844548266eb8b;p=akkoma diff --git a/test/conversation_test.exs b/test/conversation_test.exs index f3300e7d1..dc0027d04 100644 --- a/test/conversation_test.exs +++ b/test/conversation_test.exs @@ -1,14 +1,42 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2019 Pleroma Authors +# Copyright © 2017-2020 Pleroma Authors # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.ConversationTest do use Pleroma.DataCase + alias Pleroma.Activity alias Pleroma.Conversation + alias Pleroma.Object alias Pleroma.Web.CommonAPI import Pleroma.Factory + clear_config_all([:instance, :federating]) do + Pleroma.Config.put([:instance, :federating], true) + end + + test "it goes through old direct conversations" do + user = insert(:user) + other_user = insert(:user) + + {:ok, _activity} = + CommonAPI.post(user, %{"visibility" => "direct", "status" => "hey @#{other_user.nickname}"}) + + Pleroma.Tests.ObanHelpers.perform_all() + + Repo.delete_all(Conversation) + Repo.delete_all(Conversation.Participation) + + refute Repo.one(Conversation) + + Conversation.bump_for_all_activities() + + assert Repo.one(Conversation) + [participation, _p2] = Repo.all(Conversation.Participation) + + assert participation.read + end + test "it creates a conversation for given ap_id" do assert {:ok, %Conversation{} = conversation} = Conversation.create_for_ap_id("https://some_ap_id") @@ -134,4 +162,40 @@ defmodule Pleroma.ConversationTest do assert {:error, _} = Conversation.create_or_bump_for(activity) end + + test "create_or_bump_for does not normalize objects before checking the activity type" do + note = insert(:note) + note_id = note.data["id"] + Repo.delete(note) + refute Object.get_by_ap_id(note_id) + + Tesla.Mock.mock(fn env -> + case env.url do + ^note_id -> + # TODO: add attributedTo and tag to the note factory + body = + note.data + |> Map.put("attributedTo", note.data["actor"]) + |> Map.put("tag", []) + |> Jason.encode!() + + %Tesla.Env{status: 200, body: body} + end + end) + + undo = %Activity{ + id: "fake", + data: %{ + "id" => Pleroma.Web.ActivityPub.Utils.generate_activity_id(), + "actor" => note.data["actor"], + "to" => [note.data["actor"]], + "object" => note_id, + "type" => "Undo" + } + } + + Conversation.create_or_bump_for(undo) + + refute Object.get_by_ap_id(note_id) + end end