1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.SpcFixesTest do
6 use Pleroma.Web.ConnCase
9 alias Pleroma.Web.CommonAPI
10 alias Pleroma.Web.ActivityPub.ActivityPub
12 alias Pleroma.Activity
16 import Pleroma.Factory
18 test "resets the ap_id and follower_address of old spc users" do
20 %{url: "https://shitposter.club/users/zep"} ->
21 %Tesla.Env{status: 200, body: File.read!("test/fixtures/zep.json")}
30 ap_id: "https://shitposter.club/user/4962",
31 follower_address: User.ap_followers(%User{nickname: "zep@shitposter.club"}),
32 info: %{topic: "ignore"},
33 nickname: "zep@shitposter.club"
36 other_user = insert(:user)
37 {:ok, other_user} = User.follow(other_user, user)
38 {:ok, activity} = CommonAPI.post(user, %{"status" => "blabla"})
39 {:ok, _other_activity} = CommonAPI.post(other_user, %{"status" => "blabla"})
41 assert User.following?(other_user, user)
42 assert [activity] == ActivityPub.fetch_activities(other_user.following)
44 SpcFixes.upgrade_users()
46 user = Pleroma.Repo.get(User, user.id)
47 other_user = Pleroma.Repo.get(User, other_user.id)
49 assert user.ap_id == "https://shitposter.club/users/zep"
50 assert user.follower_address == "https://shitposter.club/users/zep/followers"
53 # Activites and following are correctly stitched.
54 assert User.following?(other_user, user)
55 assert [%{id: ^aid}] = ActivityPub.fetch_activities(other_user.following)
57 third_user = insert(:user)
58 {:ok, third_user} = User.follow(third_user, user)
59 assert [%{id: ^aid}] = ActivityPub.fetch_activities(third_user.following)
61 activity = Repo.get(Activity, aid)
63 assert activity.data["actor"] == user.ap_id
64 assert user.follower_address in activity.recipients
65 assert user.follower_address in activity.data["to"]
67 object = Object.get_by_ap_id(activity.data["object"]["id"])
69 assert object.data["actor"] == user.ap_id
70 assert user.follower_address in object.data["to"]