Skip to content

Commit

Permalink
https://github.com/bonfire-networks/bonfire-app/issues/924
Browse files Browse the repository at this point in the history
  • Loading branch information
mayel committed Jun 3, 2024
1 parent f7ee35b commit c9a296a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 10 deletions.
7 changes: 6 additions & 1 deletion lib/adapter/adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,13 @@ defmodule Bonfire.Federate.ActivityPub.Adapter do
# "activity_id" => activity.id
# # "activity" => activity
# })

# case
Incoming.receive_activity(activity)
|> debug("receive done")
# |> debug("receive done") do
# nil -> activity
# received -> received
# end
end

defp character_id_from_actor(actor),
Expand Down
5 changes: 5 additions & 0 deletions test/activity_pub_integration/actor_integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ defmodule Bonfire.Federate.ActivityPub.ActorIntegrationTest do
@remote_actor_url @remote_instance <> "/@karen"
@webfinger @remote_instance <>
"/.well-known/webfinger?resource=acct:" <> @actor_name
@webfinger @remote_instance <>
"/.well-known/webfinger?resource=acct%3Akaren%40mocked.local"

# TODO: move this into fixtures
setup_all do
Expand All @@ -24,6 +26,9 @@ defmodule Bonfire.Federate.ActivityPub.ActorIntegrationTest do
%{method: :get, url: @webfinger} ->
json(Simulate.webfingered())

%{method: :get, url: @webfinger2} ->
json(Simulate.webfingered())

%{
method: :get,
url: "http://mocked.local/.well-known/webfinger?resource=acct:[email protected]"
Expand Down
5 changes: 3 additions & 2 deletions test/activity_pub_integration/follow_integration_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ defmodule Bonfire.Federate.ActivityPub.FollowIntegrationTest do

test "incoming follow request works" do
followed = fake_user!(%{}, %{}, request_before_follow: true)
# info(ulid(followed), "followed ID")
# info(ulid(followed), "followed ID")
{:ok, ap_followed} = ActivityPub.Federator.Adapter.get_actor_by_id(followed.id)

{:ok, ap_follower} = ActivityPub.Actor.get_cached_or_fetch(ap_id: @remote_actor)
Expand All @@ -96,7 +96,8 @@ defmodule Bonfire.Federate.ActivityPub.FollowIntegrationTest do
# |> debug
assert {:ok, _} = Bonfire.Federate.ActivityPub.Incoming.receive_activity(follow_activity)

assert Bonfire.Social.Graph.Follows.following?(follower, followed)
assert Bonfire.Social.Graph.Follows.requested?(follower, followed)
refute Bonfire.Social.Graph.Follows.following?(follower, followed)
end

test "incoming follow + accept works" do
Expand Down
11 changes: 6 additions & 5 deletions test/activity_pub_integration/post_web_test.exs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
defmodule Bonfire.Federate.ActivityPub.PostWebTest do
use Bonfire.Federate.ActivityPub.ConnCase
use Bonfire.Federate.ActivityPub.ConnCase, async: false
import Tesla.Mock
import Untangle
alias Bonfire.Posts
Expand All @@ -8,8 +8,8 @@ defmodule Bonfire.Federate.ActivityPub.PostWebTest do
@remote_instance "https://mocked.local"
@remote_actor @remote_instance <> "/users/karen"

setup do
mock(fn
setup_all do
mock_global(fn
%{method: :get, url: @remote_actor} ->
json(Simulate.actor_json(@remote_actor))

Expand All @@ -19,7 +19,7 @@ defmodule Bonfire.Federate.ActivityPub.PostWebTest do
_ ->
raise Tesla.Mock.Error, "Request not mocked"
end)
|> IO.inspect(label: "setup done")
|> debug("setup done")

:ok
end
Expand All @@ -28,7 +28,8 @@ defmodule Bonfire.Federate.ActivityPub.PostWebTest do
test "fetch local post from AP API with Pointer ID, and take into account unindexable setting" do
user =
fake_user!()
|> IO.inspect(label: "a user")

# |> debug("a user")

user =
current_user(
Expand Down
10 changes: 8 additions & 2 deletions test/support/data_helpers.ex
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ defmodule Bonfire.Federate.ActivityPub.DataHelpers do
}
end

def remote_activity_json_with_mentions(actor, tos, extra \\ %{}) do
def remote_activity_json_with_mentions(actor, tos, extra \\ %{})

def remote_activity_json_with_mentions(actor, tos, extra) do
context = "blabla"

object =
Expand Down Expand Up @@ -96,7 +98,11 @@ defmodule Bonfire.Federate.ActivityPub.DataHelpers do
actor: actor,
context: context,
object: object,
to: tos,
to:
Enum.map(List.wrap(tos), fn
%{ap_id: ap_id} -> ap_id
ap_id -> ap_id
end),
local: false,
additional: %{
"id" => @remote_instance <> "/pub/" <> Needle.ULID.autogenerate(),
Expand Down

0 comments on commit c9a296a

Please sign in to comment.