Test refreshing instances does not update self relay actor

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2022-05-02 12:15:17 +02:00
parent a4cc566ee7
commit bf7ebfd989
No known key found for this signature in database
GPG key ID: A061B9DDE0CA0773
2 changed files with 41 additions and 4 deletions

View file

@ -5,7 +5,9 @@ defmodule Mobilizon.Service.Workers.RefreshInstances do
use Oban.Worker, unique: [period: :infinity, keys: [:event_uuid, :action]]
alias Mobilizon.Actors.Actor
alias Mobilizon.Federation.ActivityPub.Actor, as: ActivityPubActor
alias Mobilizon.Federation.ActivityPub.Relay
alias Mobilizon.Instances
alias Mobilizon.Instances.Instance
alias Oban.Job
@ -22,13 +24,20 @@ defmodule Mobilizon.Service.Workers.RefreshInstances do
@spec refresh_instance_actor(Instance.t()) ::
{:ok, Mobilizon.Actors.Actor.t()}
| {:error,
Mobilizon.Federation.ActivityPub.Actor.make_actor_errors()
ActivityPubActor.make_actor_errors()
| Mobilizon.Federation.WebFinger.finger_errors()}
defp refresh_instance_actor(%Instance{domain: nil}) do
def refresh_instance_actor(%Instance{domain: nil}) do
{:error, :not_remote_instance}
end
defp refresh_instance_actor(%Instance{domain: domain}) do
def refresh_instance_actor(%Instance{domain: domain}) do
%Actor{url: url} = Relay.get_actor()
%URI{host: host} = URI.new!(url)
if host == domain do
{:error, :not_remote_instance}
else
ActivityPubActor.find_or_make_actor_from_nickname("relay@#{domain}")
end
end
end

View file

@ -0,0 +1,28 @@
defmodule Mobilizon.Service.Workers.RefreshInstancesTest do
@moduledoc """
Test the refresh instance module
"""
alias Mobilizon.Actors.Actor
alias Mobilizon.Federation.ActivityPub.Relay
alias Mobilizon.Instances.Instance
alias Mobilizon.Service.Workers.RefreshInstances
use Mobilizon.DataCase
describe "Refresh instance actor" do
test "unless if local actor" do
# relay = Mobilizon.Web.Relay.get_actor()
assert {:error, :not_remote_instance} ==
RefreshInstances.refresh_instance_actor(%Instance{domain: nil})
end
test "unless if local relay actor" do
%Actor{url: url} = Relay.get_actor()
%URI{host: domain} = URI.new!(url)
assert {:error, :not_remote_instance} ==
RefreshInstances.refresh_instance_actor(%Instance{domain: domain})
end
end
end