2018-01-13 23:33:03 +01:00
|
|
|
defmodule Eventos.Factory do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
|
|
|
Factory for fixtures with ExMachina
|
|
|
|
"""
|
2018-01-13 23:33:03 +01:00
|
|
|
# with Ecto
|
|
|
|
use ExMachina.Ecto, repo: Eventos.Repo
|
|
|
|
|
|
|
|
def user_factory do
|
2018-05-30 18:59:13 +02:00
|
|
|
%Eventos.Actors.User{
|
2018-01-13 23:33:03 +01:00
|
|
|
password_hash: "Jane Smith",
|
|
|
|
email: sequence(:email, &"email-#{&1}@example.com"),
|
2018-07-27 10:45:35 +02:00
|
|
|
role: 0
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-05-30 18:59:13 +02:00
|
|
|
def actor_factory do
|
2018-06-14 18:15:27 +02:00
|
|
|
key = :public_key.generate_key({:rsa, 2048, 65_537})
|
2018-06-14 17:25:55 +02:00
|
|
|
entry = :public_key.pem_entry_encode(:RSAPrivateKey, key)
|
2018-06-14 18:15:27 +02:00
|
|
|
pem = [entry] |> :public_key.pem_encode() |> String.trim_trailing()
|
2018-06-14 17:25:55 +02:00
|
|
|
|
|
|
|
preferred_username = sequence("thomas")
|
2018-07-27 10:45:35 +02:00
|
|
|
|
2018-05-30 18:59:13 +02:00
|
|
|
%Eventos.Actors.Actor{
|
2018-06-14 17:25:55 +02:00
|
|
|
preferred_username: preferred_username,
|
2018-01-13 23:33:03 +01:00
|
|
|
domain: nil,
|
2018-06-14 17:25:55 +02:00
|
|
|
keys: pem,
|
2018-08-01 14:45:18 +02:00
|
|
|
type: :Person,
|
2018-07-10 10:00:07 +02:00
|
|
|
url: EventosWeb.Endpoint.url() <> "/@#{preferred_username}",
|
2018-07-27 10:45:35 +02:00
|
|
|
user: nil
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-08-01 14:45:18 +02:00
|
|
|
def group_factory do
|
|
|
|
struct!(
|
|
|
|
actor_factory(),
|
|
|
|
%{
|
|
|
|
type: :Group
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def follower_factory do
|
|
|
|
%Eventos.Actors.Follower{
|
|
|
|
target_actor: build(:actor),
|
|
|
|
actor: build(:actor)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-15 12:04:09 +01:00
|
|
|
def category_factory do
|
|
|
|
%Eventos.Events.Category{
|
|
|
|
title: sequence("MyCategory"),
|
|
|
|
description: "My category desc"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-17 11:39:01 +01:00
|
|
|
def address_factory do
|
|
|
|
%Eventos.Addresses.Address{
|
|
|
|
description: sequence("MyAddress"),
|
|
|
|
geom: %Geo.Point{coordinates: {30, -90}, srid: 4326},
|
|
|
|
floor: "Myfloor",
|
|
|
|
addressCountry: "My Country",
|
|
|
|
addressLocality: "My Locality",
|
|
|
|
addressRegion: "My Region",
|
|
|
|
postalCode: "My Postal Code",
|
|
|
|
streetAddress: "My Street Address"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-06-14 17:25:55 +02:00
|
|
|
def comment_factory do
|
|
|
|
%Eventos.Events.Comment{
|
|
|
|
text: "My Comment",
|
|
|
|
actor: build(:actor),
|
|
|
|
event: build(:event),
|
2018-07-27 10:45:35 +02:00
|
|
|
uuid: Ecto.UUID.generate()
|
2018-06-14 17:25:55 +02:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
def event_factory do
|
2018-05-30 18:59:13 +02:00
|
|
|
actor = build(:actor)
|
2018-05-17 11:32:23 +02:00
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
%Eventos.Events.Event{
|
|
|
|
title: sequence("MyEvent"),
|
|
|
|
description: "My desc",
|
|
|
|
begins_on: nil,
|
|
|
|
ends_on: nil,
|
2018-05-30 18:59:13 +02:00
|
|
|
organizer_actor: actor,
|
2018-01-17 11:39:01 +01:00
|
|
|
category: build(:category),
|
2018-07-04 16:23:52 +02:00
|
|
|
physical_address: build(:address),
|
2018-06-14 17:25:55 +02:00
|
|
|
url: "#{EventosWeb.Endpoint.url()}/@#{actor.url}/#{Ecto.UUID.generate()}"
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def session_factory do
|
|
|
|
%Eventos.Events.Session{
|
2018-07-27 10:45:35 +02:00
|
|
|
title: sequence("MySession"),
|
|
|
|
event: build(:event),
|
|
|
|
track: build(:track)
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def track_factory do
|
|
|
|
%Eventos.Events.Track{
|
|
|
|
name: sequence("MyTrack"),
|
|
|
|
event: build(:event)
|
|
|
|
}
|
|
|
|
end
|
2018-01-17 11:39:01 +01:00
|
|
|
|
2018-06-14 17:25:55 +02:00
|
|
|
def bot_factory do
|
|
|
|
%Eventos.Actors.Bot{
|
|
|
|
source: "https://mysource.tld/feed.ics",
|
|
|
|
type: "ics",
|
|
|
|
user: build(:user),
|
2018-07-27 10:45:35 +02:00
|
|
|
actor: build(:actor)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def member_factory do
|
|
|
|
%Eventos.Actors.Member{
|
|
|
|
parent: build(:actor),
|
|
|
|
actor: build(:actor)
|
2018-01-17 11:39:01 +01:00
|
|
|
}
|
|
|
|
end
|
2018-01-14 17:56:50 +01:00
|
|
|
end
|