2018-10-11 17:37:39 +02:00
|
|
|
defmodule Mobilizon.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
|
2018-10-11 17:37:39 +02:00
|
|
|
use ExMachina.Ecto, repo: Mobilizon.Repo
|
2018-01-13 23:33:03 +01:00
|
|
|
|
|
|
|
def user_factory do
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Actors.User{
|
2018-01-13 23:33:03 +01:00
|
|
|
password_hash: "Jane Smith",
|
|
|
|
email: sequence(:email, &"email-#{&1}@example.com"),
|
2019-01-11 14:07:14 +01:00
|
|
|
role: 0,
|
|
|
|
confirmed_at: DateTime.utc_now(),
|
|
|
|
confirmation_sent_at: nil,
|
|
|
|
confirmation_token: nil
|
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-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.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-11-27 17:54:54 +01:00
|
|
|
followers: [],
|
|
|
|
followings: [],
|
2018-06-14 17:25:55 +02:00
|
|
|
keys: pem,
|
2018-08-01 14:45:18 +02:00
|
|
|
type: :Person,
|
2018-10-11 17:37:39 +02:00
|
|
|
url: MobilizonWeb.Endpoint.url() <> "/@#{preferred_username}",
|
2018-11-27 17:54:54 +01:00
|
|
|
followers_url: MobilizonWeb.Endpoint.url() <> "/@#{preferred_username}/followers",
|
|
|
|
following_url: MobilizonWeb.Endpoint.url() <> "/@#{preferred_username}/following",
|
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
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Actors.Follower{
|
2018-08-01 14:45:18 +02:00
|
|
|
target_actor: build(:actor),
|
|
|
|
actor: build(:actor)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-15 12:04:09 +01:00
|
|
|
def category_factory do
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Events.Category{
|
2018-01-15 12:04:09 +01:00
|
|
|
title: sequence("MyCategory"),
|
|
|
|
description: "My category desc"
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-11-23 15:03:53 +01:00
|
|
|
def tag_factory do
|
|
|
|
%Mobilizon.Events.Tag{
|
|
|
|
title: "MyTag",
|
|
|
|
slug: sequence("MyTag")
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-17 11:39:01 +01:00
|
|
|
def address_factory do
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Addresses.Address{
|
2018-01-17 11:39:01 +01: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 17:25:55 +02:00
|
|
|
def comment_factory do
|
2018-08-24 11:34:00 +02:00
|
|
|
uuid = Ecto.UUID.generate()
|
|
|
|
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Events.Comment{
|
2018-06-14 17:25:55 +02:00
|
|
|
text: "My Comment",
|
|
|
|
actor: build(:actor),
|
|
|
|
event: build(:event),
|
2018-08-24 11:34:00 +02:00
|
|
|
uuid: uuid,
|
2018-11-27 17:54:54 +01:00
|
|
|
in_reply_to_comment: nil,
|
2018-10-11 17:37:39 +02:00
|
|
|
url: "#{MobilizonWeb.Endpoint.url()}/comments/#{uuid}"
|
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-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Events.Event{
|
2018-11-06 10:30:27 +01: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 23:33:03 +01:00
|
|
|
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),
|
2019-01-14 15:56:07 +01:00
|
|
|
visibility: :public,
|
2018-11-06 10:30:27 +01:00
|
|
|
url: "@#{actor.url}/#{Ecto.UUID.generate()}"
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-08-24 11:34:00 +02:00
|
|
|
def participant_factory do
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Events.Participant{
|
2018-08-24 11:34:00 +02:00
|
|
|
event: build(:event),
|
|
|
|
actor: build(:actor)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
def session_factory do
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.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
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Events.Track{
|
2018-01-13 23:33:03 +01:00
|
|
|
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
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Actors.Bot{
|
2018-06-14 17:25:55 +02:00
|
|
|
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
|
2018-10-11 17:37:39 +02:00
|
|
|
%Mobilizon.Actors.Member{
|
2018-07-27 10:45:35 +02:00
|
|
|
parent: build(:actor),
|
|
|
|
actor: build(:actor)
|
2018-01-17 11:39:01 +01:00
|
|
|
}
|
|
|
|
end
|
2018-01-14 17:56:50 +01:00
|
|
|
end
|