2018-10-11 15:37:39 +00:00
|
|
|
defmodule Mobilizon.Factory do
|
2018-01-14 16:56:50 +00:00
|
|
|
@moduledoc """
|
|
|
|
Factory for fixtures with ExMachina
|
|
|
|
"""
|
2018-01-13 22:33:03 +00:00
|
|
|
# with Ecto
|
2018-10-11 15:37:39 +00:00
|
|
|
use ExMachina.Ecto, repo: Mobilizon.Repo
|
2018-01-13 22:33:03 +00:00
|
|
|
|
|
|
|
def user_factory do
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Actors.User{
|
2018-01-13 22:33:03 +00:00
|
|
|
password_hash: "Jane Smith",
|
|
|
|
email: sequence(:email, &"email-#{&1}@example.com"),
|
2018-07-27 08:45:35 +00:00
|
|
|
role: 0
|
2018-01-13 22:33:03 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-05-30 16:59:13 +00:00
|
|
|
def actor_factory do
|
2018-06-14 16:15:27 +00:00
|
|
|
key = :public_key.generate_key({:rsa, 2048, 65_537})
|
2018-06-14 15:25:55 +00:00
|
|
|
entry = :public_key.pem_entry_encode(:RSAPrivateKey, key)
|
2018-06-14 16:15:27 +00:00
|
|
|
pem = [entry] |> :public_key.pem_encode() |> String.trim_trailing()
|
2018-06-14 15:25:55 +00:00
|
|
|
|
|
|
|
preferred_username = sequence("thomas")
|
2018-07-27 08:45:35 +00:00
|
|
|
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Actors.Actor{
|
2018-06-14 15:25:55 +00:00
|
|
|
preferred_username: preferred_username,
|
2018-01-13 22:33:03 +00:00
|
|
|
domain: nil,
|
2018-11-27 16:54:54 +00:00
|
|
|
followers: [],
|
|
|
|
followings: [],
|
2018-06-14 15:25:55 +00:00
|
|
|
keys: pem,
|
2018-08-01 12:45:18 +00:00
|
|
|
type: :Person,
|
2018-10-11 15:37:39 +00:00
|
|
|
url: MobilizonWeb.Endpoint.url() <> "/@#{preferred_username}",
|
2018-11-27 16:54:54 +00:00
|
|
|
followers_url: MobilizonWeb.Endpoint.url() <> "/@#{preferred_username}/followers",
|
|
|
|
following_url: MobilizonWeb.Endpoint.url() <> "/@#{preferred_username}/following",
|
2018-07-27 08:45:35 +00:00
|
|
|
user: nil
|
2018-01-13 22:33:03 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-08-01 12:45:18 +00:00
|
|
|
def group_factory do
|
|
|
|
struct!(
|
|
|
|
actor_factory(),
|
|
|
|
%{
|
|
|
|
type: :Group
|
|
|
|
}
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
def follower_factory do
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Actors.Follower{
|
2018-08-01 12:45:18 +00:00
|
|
|
target_actor: build(:actor),
|
|
|
|
actor: build(:actor)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-15 11:04:09 +00:00
|
|
|
def category_factory do
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Events.Category{
|
2018-01-15 11:04:09 +00:00
|
|
|
title: sequence("MyCategory"),
|
|
|
|
description: "My category desc"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-11-23 14:03:53 +00:00
|
|
|
def tag_factory do
|
|
|
|
%Mobilizon.Events.Tag{
|
|
|
|
title: "MyTag",
|
|
|
|
slug: sequence("MyTag")
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-17 10:39:01 +00:00
|
|
|
def address_factory do
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Addresses.Address{
|
2018-01-17 10:39:01 +00:00
|
|
|
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 15:25:55 +00:00
|
|
|
def comment_factory do
|
2018-08-24 09:34:00 +00:00
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Events.Comment{
|
2018-06-14 15:25:55 +00:00
|
|
|
text: "My Comment",
|
|
|
|
actor: build(:actor),
|
|
|
|
event: build(:event),
|
2018-08-24 09:34:00 +00:00
|
|
|
uuid: uuid,
|
2018-11-27 16:54:54 +00:00
|
|
|
in_reply_to_comment: nil,
|
2018-10-11 15:37:39 +00:00
|
|
|
url: "#{MobilizonWeb.Endpoint.url()}/comments/#{uuid}"
|
2018-06-14 15:25:55 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-13 22:33:03 +00:00
|
|
|
def event_factory do
|
2018-05-30 16:59:13 +00:00
|
|
|
actor = build(:actor)
|
2018-05-17 09:32:23 +00:00
|
|
|
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Events.Event{
|
2018-11-06 09:30:27 +00:00
|
|
|
title: sequence("Ceci est un événement"),
|
|
|
|
description: "Ceci est une description avec une première phrase assez longue,
|
|
|
|
puis sur une seconde ligne",
|
2018-01-13 22:33:03 +00:00
|
|
|
begins_on: nil,
|
|
|
|
ends_on: nil,
|
2018-05-30 16:59:13 +00:00
|
|
|
organizer_actor: actor,
|
2018-01-17 10:39:01 +00:00
|
|
|
category: build(:category),
|
2018-07-04 14:23:52 +00:00
|
|
|
physical_address: build(:address),
|
2018-08-24 09:34:00 +00:00
|
|
|
public: true,
|
2018-11-06 09:30:27 +00:00
|
|
|
url: "@#{actor.url}/#{Ecto.UUID.generate()}"
|
2018-01-13 22:33:03 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-08-24 09:34:00 +00:00
|
|
|
def participant_factory do
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Events.Participant{
|
2018-08-24 09:34:00 +00:00
|
|
|
event: build(:event),
|
|
|
|
actor: build(:actor)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-13 22:33:03 +00:00
|
|
|
def session_factory do
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Events.Session{
|
2018-07-27 08:45:35 +00:00
|
|
|
title: sequence("MySession"),
|
|
|
|
event: build(:event),
|
|
|
|
track: build(:track)
|
2018-01-13 22:33:03 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def track_factory do
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Events.Track{
|
2018-01-13 22:33:03 +00:00
|
|
|
name: sequence("MyTrack"),
|
|
|
|
event: build(:event)
|
|
|
|
}
|
|
|
|
end
|
2018-01-17 10:39:01 +00:00
|
|
|
|
2018-06-14 15:25:55 +00:00
|
|
|
def bot_factory do
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Actors.Bot{
|
2018-06-14 15:25:55 +00:00
|
|
|
source: "https://mysource.tld/feed.ics",
|
|
|
|
type: "ics",
|
|
|
|
user: build(:user),
|
2018-07-27 08:45:35 +00:00
|
|
|
actor: build(:actor)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def member_factory do
|
2018-10-11 15:37:39 +00:00
|
|
|
%Mobilizon.Actors.Member{
|
2018-07-27 08:45:35 +00:00
|
|
|
parent: build(:actor),
|
|
|
|
actor: build(:actor)
|
2018-01-17 10:39:01 +00:00
|
|
|
}
|
|
|
|
end
|
2018-01-14 16:56:50 +00:00
|
|
|
end
|