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"),
|
|
|
|
role: 0,
|
2018-05-30 18:59:13 +02:00
|
|
|
actor: build(:actor)
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2018-05-30 18:59:13 +02:00
|
|
|
def actor_factory do
|
2018-01-14 17:56:50 +01:00
|
|
|
{:ok, {_, pubkey}} = RsaEx.generate_keypair("4096")
|
2018-05-17 11:32:23 +02:00
|
|
|
username = sequence("thomas")
|
2018-05-30 18:59:13 +02:00
|
|
|
%Eventos.Actors.Actor{
|
|
|
|
preferred_username: username,
|
2018-01-13 23:33:03 +01:00
|
|
|
domain: nil,
|
|
|
|
public_key: pubkey,
|
2018-05-17 11:32:23 +02:00
|
|
|
url: EventosWeb.Endpoint.url() <> "/@#{username}"
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
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-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
|
|
|
slug = sequence("my-event")
|
|
|
|
|
2018-01-13 23:33:03 +01:00
|
|
|
%Eventos.Events.Event{
|
|
|
|
title: sequence("MyEvent"),
|
2018-05-17 11:32:23 +02:00
|
|
|
slug: slug,
|
2018-01-13 23:33:03 +01:00
|
|
|
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-05-17 11:32:23 +02:00
|
|
|
address: build(:address),
|
2018-05-30 18:59:13 +02:00
|
|
|
url: EventosWeb.Endpoint.url() <> "/@" <> actor.username <> "/" <> slug
|
2018-01-13 23:33:03 +01:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def session_factory do
|
|
|
|
%Eventos.Events.Session{
|
|
|
|
title: sequence("MySession"),
|
|
|
|
event: build(:event),
|
|
|
|
track: build(:track)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
def track_factory do
|
|
|
|
%Eventos.Events.Track{
|
|
|
|
name: sequence("MyTrack"),
|
|
|
|
event: build(:event)
|
|
|
|
}
|
|
|
|
end
|
2018-01-17 11:39:01 +01:00
|
|
|
|
|
|
|
def group_factory do
|
2018-05-30 18:59:13 +02:00
|
|
|
username = sequence("My Group")
|
|
|
|
%Eventos.Actors.Actor{
|
|
|
|
preferred_username: username,
|
|
|
|
summary: "My group",
|
2018-01-17 11:39:01 +01:00
|
|
|
suspended: false,
|
2018-05-30 18:59:13 +02:00
|
|
|
url: EventosWeb.Endpoint.url() <> "/@#{username}",
|
|
|
|
type: "Group",
|
2018-01-17 11:39:01 +01:00
|
|
|
}
|
|
|
|
end
|
2018-01-14 17:56:50 +01:00
|
|
|
end
|