2019-07-30 14:40:59 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
|
|
|
# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
|
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Mix.Tasks.Mobilizon.RelayTest do
|
2019-09-22 14:26:23 +00:00
|
|
|
use Mobilizon.DataCase
|
|
|
|
|
2020-10-30 14:16:01 +00:00
|
|
|
alias Mix.Tasks.Mobilizon.Relay.{Follow, Unfollow}
|
2020-01-22 01:14:42 +00:00
|
|
|
|
|
|
|
alias Mobilizon.Federation.ActivityPub.Relay
|
2021-04-12 10:01:09 +00:00
|
|
|
import Mock
|
2019-07-30 14:40:59 +00:00
|
|
|
|
2021-04-12 10:01:09 +00:00
|
|
|
Mix.shell(Mix.Shell.Process)
|
2019-07-30 14:40:59 +00:00
|
|
|
|
2021-04-12 10:01:09 +00:00
|
|
|
@target_instance "mobilizon1.com"
|
2019-07-30 14:40:59 +00:00
|
|
|
|
2021-04-12 10:01:09 +00:00
|
|
|
@output_1 "Requested to follow #{@target_instance}"
|
|
|
|
@error_1 "Some error"
|
|
|
|
@error_msg_1 "Error while following #{@target_instance}: \"#{@error_1}\""
|
|
|
|
@error_msg_1_unfollow "Error while unfollowing #{@target_instance}: \"#{@error_1}\""
|
|
|
|
@error_msg_2 "mobilizon.relay.follow requires an instance hostname as arguments"
|
|
|
|
@error_msg_2_unfollow "mobilizon.relay.unfollow requires an instance hostname as arguments"
|
2019-07-30 14:40:59 +00:00
|
|
|
|
2021-04-12 10:01:09 +00:00
|
|
|
@output_2 "Unfollowed #{@target_instance}"
|
2019-07-30 14:40:59 +00:00
|
|
|
|
2021-04-12 10:01:09 +00:00
|
|
|
describe "running follow" do
|
|
|
|
test "relay is followed" do
|
|
|
|
with_mock Relay, [:passthrough], follow: fn @target_instance -> {:ok, nil, nil} end do
|
|
|
|
Follow.run([@target_instance])
|
|
|
|
assert_received {:mix_shell, :info, [output_received]}
|
|
|
|
assert output_received == @output_1
|
2019-07-30 14:40:59 +00:00
|
|
|
end
|
|
|
|
end
|
2021-04-12 10:01:09 +00:00
|
|
|
|
|
|
|
test "returns an error" do
|
|
|
|
with_mock Relay, [:passthrough], follow: fn @target_instance -> {:error, @error_1} end do
|
|
|
|
Follow.run([@target_instance])
|
|
|
|
assert_received {:mix_shell, :error, [output_received]}
|
|
|
|
assert output_received == @error_msg_1
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
test "without arguments" do
|
|
|
|
Follow.run([])
|
|
|
|
assert_received {:mix_shell, :error, [output_received]}
|
|
|
|
assert output_received == @error_msg_2
|
|
|
|
end
|
2019-07-30 14:40:59 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "running unfollow" do
|
|
|
|
test "relay is unfollowed" do
|
2021-04-12 10:01:09 +00:00
|
|
|
with_mock Relay, [:passthrough], unfollow: fn @target_instance -> {:ok, nil, nil} end do
|
|
|
|
Unfollow.run([@target_instance])
|
2019-12-03 10:29:51 +00:00
|
|
|
|
2021-04-12 10:01:09 +00:00
|
|
|
assert_received {:mix_shell, :info, [output_received]}
|
|
|
|
assert output_received == @output_2
|
|
|
|
end
|
|
|
|
end
|
2019-07-30 14:40:59 +00:00
|
|
|
|
2021-04-12 10:01:09 +00:00
|
|
|
test "returns an error" do
|
|
|
|
with_mock Relay, [:passthrough], unfollow: fn @target_instance -> {:error, @error_1} end do
|
|
|
|
Unfollow.run([@target_instance])
|
2019-07-30 14:40:59 +00:00
|
|
|
|
2021-04-12 10:01:09 +00:00
|
|
|
assert_received {:mix_shell, :error, [output_received]}
|
|
|
|
assert output_received == @error_msg_1_unfollow
|
2019-07-30 14:40:59 +00:00
|
|
|
end
|
|
|
|
end
|
2021-04-12 10:01:09 +00:00
|
|
|
|
|
|
|
test "without arguments" do
|
|
|
|
Unfollow.run([])
|
|
|
|
assert_received {:mix_shell, :error, [output_received]}
|
|
|
|
assert output_received == @error_msg_2_unfollow
|
|
|
|
end
|
2019-07-30 14:40:59 +00:00
|
|
|
end
|
|
|
|
end
|