From f789fcd2eea62ef693d1f5e124a2a5f688f62432 Mon Sep 17 00:00:00 2001 From: setop Date: Tue, 20 Aug 2024 21:43:41 +0200 Subject: [PATCH] test(backent): fix ActivityPub client mock --- test/federation/activity_pub/transmogrifier/follow_test.exs | 5 ++++- test/federation/activity_pub/transmogrifier/undo_test.exs | 5 ++++- test/federation/activity_pub/transmogrifier/update_test.exs | 6 ++++++ test/graphql/resolvers/member_test.exs | 4 ++++ 4 files changed, 18 insertions(+), 2 deletions(-) diff --git a/test/federation/activity_pub/transmogrifier/follow_test.exs b/test/federation/activity_pub/transmogrifier/follow_test.exs index ed464820d..b07b8d467 100644 --- a/test/federation/activity_pub/transmogrifier/follow_test.exs +++ b/test/federation/activity_pub/transmogrifier/follow_test.exs @@ -50,13 +50,16 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.FollowTest do |> Jason.decode!() Mock - |> expect(:call, fn + |> expect(:call, 2, fn %{method: :get, url: "https://social.tcit.fr/users/tcit"}, _opts -> {:ok, %Tesla.Env{ status: 200, body: Map.put(actor_data, "id", "https://social.tcit.fr/users/tcit") }} + + %{method: :post, url: "https://framapiaf.org/inbox"} = args, _opts -> + {:ok, args} end) data = diff --git a/test/federation/activity_pub/transmogrifier/undo_test.exs b/test/federation/activity_pub/transmogrifier/undo_test.exs index 35632690c..6713fdbdc 100644 --- a/test/federation/activity_pub/transmogrifier/undo_test.exs +++ b/test/federation/activity_pub/transmogrifier/undo_test.exs @@ -62,9 +62,12 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.UndoTest do |> Map.put("id", "https://social.tcit.fr/users/tcit") Mock - |> expect(:call, fn + |> expect(:call, 2, fn %{method: :get, url: "https://social.tcit.fr/users/tcit"}, _opts -> {:ok, %Tesla.Env{status: 200, body: actor_data}} + + %{method: :post, url: "https://framapiaf.org/inbox"} = args, _opts -> + {:ok, args} end) {:ok, %Activity{data: _, local: false}, _} = Transmogrifier.handle_incoming(follow_data) diff --git a/test/federation/activity_pub/transmogrifier/update_test.exs b/test/federation/activity_pub/transmogrifier/update_test.exs index 70ac60f51..e27fe5958 100644 --- a/test/federation/activity_pub/transmogrifier/update_test.exs +++ b/test/federation/activity_pub/transmogrifier/update_test.exs @@ -185,6 +185,12 @@ defmodule Mobilizon.Federation.ActivityPub.Transmogrifier.UpdateTest do |> Map.put("actor", remote_actor_url) |> Map.put("object", object) + Mock + |> expect(:call, 2, fn + %{method: :post, url: "http://mobilizon.test/inbox"}, _opts -> + {:ok, %Tesla.Env{status: 200, body: update_data}} + end) + {:ok, %Activity{data: data, local: false}, _} = Transmogrifier.handle_incoming(update_data) %Post{id: updated_post_id, title: updated_post_title} = diff --git a/test/graphql/resolvers/member_test.exs b/test/graphql/resolvers/member_test.exs index ff5051eb4..1713a3c27 100644 --- a/test/graphql/resolvers/member_test.exs +++ b/test/graphql/resolvers/member_test.exs @@ -194,6 +194,10 @@ defmodule Mobilizon.GraphQL.Resolvers.MemberTest do group = insert(:group) target_actor = insert(:actor, user: user) + Mox.expect(Mobilizon.Service.HTTP.ActivityPub.Mock, :call, fn _req, _opts -> + {:ok, %Tesla.Env{status: 200, body: %{"role" => "INVITED"}}} + end) + {:ok, conn: conn, actor: actor, user: user, group: group, target_actor: target_actor} end