Use ex_vcr for tests

Which are now offline-only !

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2018-11-13 12:23:37 +01:00
parent 1e86797e07
commit 9c65ad0170
16 changed files with 553 additions and 69 deletions

View File

@@ -4,6 +4,7 @@ defmodule Mobilizon.ActorsTest do
alias Mobilizon.Actors
alias Mobilizon.Actors.{Actor, Member, Follower, User, Bot}
import Mobilizon.Factory
use ExVCR.Mock, adapter: ExVCR.Adapter.Hackney
describe "actors" do
@valid_attrs %{
@@ -88,12 +89,14 @@ defmodule Mobilizon.ActorsTest do
end
test "get_actor_by_name/1 returns a remote actor" do
with {:ok,
%Actor{id: actor_id, preferred_username: preferred_username, domain: domain} = _actor} <-
Actors.get_or_fetch_by_url(@remote_account_url),
%Actor{id: actor_found_id} <-
Actors.get_actor_by_name("#{preferred_username}@#{domain}").id do
assert actor_found_id == actor_id
use_cassette "actors/remote_actor_mastodon_tcit" do
with {:ok,
%Actor{id: actor_id, preferred_username: preferred_username, domain: domain} = _actor} <-
Actors.get_or_fetch_by_url(@remote_account_url),
%Actor{id: actor_found_id} <-
Actors.get_actor_by_name("#{preferred_username}@#{domain}").id do
assert actor_found_id == actor_id
end
end
end
@@ -132,20 +135,22 @@ defmodule Mobilizon.ActorsTest do
end
test "get_actor_by_name_with_everything!/1 returns the remote actor with it's organized events" do
assert {:ok, %Actor{} = actor} = Actors.get_or_fetch_by_url(@remote_account_url)
use_cassette "actors/remote_actor_mastodon_tcit" do
with {:ok, %Actor{} = actor} <- Actors.get_or_fetch_by_url(@remote_account_url) do
assert Actors.get_actor_by_name_with_everything(
"#{actor.preferred_username}@#{actor.domain}"
).organized_events == []
assert Actors.get_actor_by_name_with_everything(
"#{actor.preferred_username}@#{actor.domain}"
).organized_events == []
event = insert(:event, organizer_actor: actor)
event = insert(:event, organizer_actor: actor)
event_found_id =
Actors.get_actor_by_name_with_everything("#{actor.preferred_username}@#{actor.domain}").organized_events
|> hd
|> Map.get(:id)
event_found_id =
Actors.get_actor_by_name_with_everything("#{actor.preferred_username}@#{actor.domain}").organized_events
|> hd
|> Map.get(:id)
assert event_found_id == event.id
assert event_found_id == event.id
end
end
end
test "get_or_fetch_by_url/1 returns the local actor for the url", %{
@@ -158,10 +163,12 @@ defmodule Mobilizon.ActorsTest do
end
test "get_or_fetch_by_url/1 returns the remote actor for the url" do
with {:ok, %Actor{preferred_username: preferred_username, domain: domain}} <-
Actors.get_or_fetch_by_url!(@remote_account_url) do
assert preferred_username == @remote_account_username
assert domain == @remote_account_domain
use_cassette "actors/remote_actor_mastodon_tcit" do
with {:ok, %Actor{preferred_username: preferred_username, domain: domain}} <-
Actors.get_or_fetch_by_url!(@remote_account_url) do
assert preferred_username == @remote_account_username
assert domain == @remote_account_domain
end
end
end
@@ -178,9 +185,12 @@ defmodule Mobilizon.ActorsTest do
test "test find_actors_by_username_or_name/1 returns actors with similar usernames", %{
actor: %Actor{id: actor_id}
} do
{:ok, %Actor{id: actor2_id}} = Actors.get_or_fetch_by_url(@remote_account_url)
actors_ids = Actors.find_actors_by_username_or_name("t") |> Enum.map(& &1.id)
assert MapSet.new(actors_ids) == MapSet.new([actor2_id, actor_id])
use_cassette "actors/remote_actor_mastodon_tcit" do
with {:ok, %Actor{id: actor2_id}} <- Actors.get_or_fetch_by_url(@remote_account_url) do
actors_ids = Actors.find_actors_by_username_or_name("t") |> Enum.map(& &1.id)
assert MapSet.new(actors_ids) == MapSet.new([actor2_id, actor_id])
end
end
end
test "test find_actors_by_username_or_name/1 returns actors with similar names" do
@@ -218,7 +228,9 @@ defmodule Mobilizon.ActorsTest do
20_890_513_599_005_517_665_557_846_902_571_022_168_782_075_040_010_449_365_706_450_877_170_130_373_892_202_874_869_873_999_284_399_697_282_332_064_948_148_602_583_340_776_692_090_472_558_740_998_357_203_838_580_321_412_679_020_304_645_826_371_196_718_081_108_049_114_160_630_664_514_340_729_769_453_281_682_773_898_619_827_376_232_969_899_348_462_205_389_310_883_299_183_817_817_999_273_916_446_620_095_414_233_374_619_948_098_516_821_650_069_821_783_810_210_582_035_456_563_335_930_330_252_551_528_035_801_173_640_288_329_718_719_895_926_309_416_142_129_926_226_047_930_429_802_084_560_488_897_717_417_403_272_782_469_039_131_379_953_278_833_320_195_233_761_955_815_307_522_871_787_339_192_744_439_894_317_730_207_141_881_699_363_391_788_150_650_217_284_777_541_358_381_165_360_697_136_307_663_640_904_621_178_632_289_787,
65537}}
test "test get_public_key_for_url/1 with remote actor" do
assert Actor.get_public_key_for_url(@remote_account_url) == @remote_actor_key
use_cassette "actors/remote_actor_mastodon_tcit" do
assert Actor.get_public_key_for_url(@remote_account_url) == @remote_actor_key
end
end
test "create_actor/1 with valid data creates a actor" do